Optimized and fixed the reaction system
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
42dd0e8dca
commit
f27b9cb4f6
@ -62,13 +62,15 @@ public final class DiscordManager {
|
||||
}
|
||||
|
||||
private static void registerReactionEvents() {
|
||||
// reactionAnswers[new Random().nextInt(reactionAnswers.length)]
|
||||
discordClient.getEventDispatcher().on(ReactionAddEvent.class)
|
||||
.filter(event -> event.getMessage().block() != null
|
||||
&& Arrays.stream(reactionAnswers).noneMatch(r -> Objects.requireNonNull(event.getMessage().block())
|
||||
.getReactors(r).any(user -> user.equals(discordClient.getSelf().block())).block())
|
||||
&& Objects.requireNonNull(event.getMessage().block()).getAuthor().isPresent()
|
||||
&& !Objects.requireNonNull(event.getMessage().block()).getAuthor().get().equals(discordClient.getSelf().block()))
|
||||
.flatMap(event -> event.getMessage().flatMap(message -> message.addReaction(reactionAnswers[new Random().nextInt(reactionAnswers.length)])).then())
|
||||
.flatMap(ReactionAddEvent::getMessage)
|
||||
.filter(message -> message.getAuthor().isPresent()
|
||||
&& message.getAuthor().get().equals(discordClient.getSelf().block()))
|
||||
.filter(message -> message.getReactions().stream()
|
||||
.noneMatch(r -> message.getReactors(r.getEmoji()).toStream()
|
||||
.anyMatch(u -> u.equals(discordClient.getSelf().block()))))
|
||||
.flatMap(message -> message.addReaction(reactionAnswers[new Random().nextInt(reactionAnswers.length)]).then())
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user