Skip to content

Commit 35abd02

Browse files
committed
use REST action chaining
1 parent e883452 commit 35abd02

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

application/src/main/java/org/togetherjava/tjbot/features/basic/CoolMessagesBoardManager.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
1010
import net.dv8tion.jda.api.entities.emoji.Emoji;
1111
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
12+
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
1213
import org.slf4j.Logger;
1314
import org.slf4j.LoggerFactory;
1415

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

6566
final int newReactionsCount = originalReactionsCount + 1;
6667
if (isCoolEmoji && newReactionsCount >= config.minimumReactions()) {
67-
event.retrieveMessage().queue(message -> {
68-
message.addReaction(coolEmoji).queue();
69-
70-
insertCoolMessage(boardChannel.get(), message);
71-
}, e -> logger.warn("Tried to retrieve cool message but got: {}", e.getMessage()));
68+
event.retrieveMessage()
69+
.queue(message -> message.addReaction(coolEmoji)
70+
.flatMap(v -> insertCoolMessage(boardChannel.get(), message))
71+
.queue(),
72+
e -> logger.warn("Tried to retrieve cool message but got: {}",
73+
e.getMessage()));
7274
}
7375
}
7476

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

9092
/**
9193
* Inserts a message to the specified text channel
94+
*
95+
* @return a {@link MessageCreateAction} of the call to make
9296
*/
93-
private static void insertCoolMessage(TextChannel boardChannel, Message message) {
94-
boardChannel.sendMessageEmbeds(Collections.singleton(createQuoteEmbed(message))).queue();
97+
private static MessageCreateAction insertCoolMessage(TextChannel boardChannel,
98+
Message message) {
99+
return boardChannel.sendMessageEmbeds(Collections.singleton(createQuoteEmbed(message)));
95100
}
96101

97102
/**

0 commit comments

Comments
 (0)