Skip to content

Commit e16f7d8

Browse files
committed
QuoteBoardForwarder.java: don't care about reactions in the board itself
Great, we recently made a quotes board, and if a message gets 5 stars, then it's added to the quotes board. What happens if someone reacts from _within_ the quotes board itself? Add an additional condition so that message reaction additions are not counted within this feature if the reaction is in the quotes board itself. Signed-off-by: Chris Sdogkos <work@chris-sdogkos.com>
1 parent a741f6f commit e16f7d8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,28 @@ public void onMessageReactionAdd(MessageReactionAddEvent event) {
8080

8181
final long guildId = event.getGuild().getIdLong();
8282

83-
Optional<TextChannel> boardChannel = findQuoteBoardChannel(event.getJDA(), guildId);
83+
Optional<TextChannel> boardChannelOptional = findQuoteBoardChannel(event.getJDA(), guildId);
8484

85-
if (boardChannel.isEmpty()) {
85+
if (boardChannelOptional.isEmpty()) {
8686
logger.warn(
8787
"Could not find board channel with pattern '{}' in server with ID '{}'. Skipping reaction handling...",
8888
this.config.channel(), guildId);
8989
return;
9090
}
9191

92-
logger.debug("Forwarding message to quote board channel: {}", boardChannel.get().getName());
92+
TextChannel boardChannel = boardChannelOptional.get();
93+
94+
if (boardChannel.getId().equals(event.getChannel().getId())) {
95+
logger.debug("Someone tried to react with the react emoji to the quotes channel.");
96+
return;
97+
}
98+
99+
logger.debug("Forwarding message to quote board channel: {}", boardChannel.getName());
93100

94101
event.retrieveMessage()
95-
.queue(message -> markAsProcessed(message)
96-
.flatMap(v -> message.forwardTo(boardChannel.orElseThrow()))
102+
.queue(message -> markAsProcessed(message).flatMap(v -> message.forwardTo(boardChannel))
97103
.queue(_ -> logger.debug("Message forwarded to quote board channel: {}",
98-
boardChannel.get().getName())),
104+
boardChannel.getName())),
99105

100106
e -> logger.warn(
101107
"Unknown error while attempting to retrieve and forward message for quote-board, message is ignored.",

0 commit comments

Comments
 (0)