Skip to content

Commit

Permalink
use REST action chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
christolis committed May 17, 2024
1 parent af00884 commit 59dc245
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -64,11 +65,12 @@ public void onMessageReactionAdd(MessageReactionAddEvent event) {

final int newReactionsCount = originalReactionsCount + 1;
if (isCoolEmoji && newReactionsCount >= config.minimumReactions()) {
event.retrieveMessage().queue(message -> {
message.addReaction(coolEmoji).queue();

insertCoolMessage(boardChannel.get(), message);
}, e -> logger.warn("Tried to retrieve cool message but got: {}", e.getMessage()));
event.retrieveMessage()
.queue(message -> message.addReaction(coolEmoji)
.flatMap(v -> insertCoolMessage(boardChannel.get(), message))
.queue(),
e -> logger.warn("Tried to retrieve cool message but got: {}",
e.getMessage()));
}
}

Expand All @@ -89,9 +91,12 @@ private Optional<TextChannel> getBoardChannel(JDA jda, long guildId) {

/**
* Inserts a message to the specified text channel
*
* @return a {@link MessageCreateAction} of the call to make
*/
private static void insertCoolMessage(TextChannel boardChannel, Message message) {
boardChannel.sendMessageEmbeds(Collections.singleton(createQuoteEmbed(message))).queue();
private static MessageCreateAction insertCoolMessage(TextChannel boardChannel,
Message message) {
return boardChannel.sendMessageEmbeds(Collections.singleton(createQuoteEmbed(message)));
}

/**
Expand Down

0 comments on commit 59dc245

Please sign in to comment.