Optimized and fixed the reaction system

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2021-04-16 19:07:10 +02:00
parent 42dd0e8dca
commit f27b9cb4f6

View File

@ -62,13 +62,15 @@ public final class DiscordManager {
} }
private static void registerReactionEvents() { private static void registerReactionEvents() {
// reactionAnswers[new Random().nextInt(reactionAnswers.length)]
discordClient.getEventDispatcher().on(ReactionAddEvent.class) discordClient.getEventDispatcher().on(ReactionAddEvent.class)
.filter(event -> event.getMessage().block() != null .flatMap(ReactionAddEvent::getMessage)
&& Arrays.stream(reactionAnswers).noneMatch(r -> Objects.requireNonNull(event.getMessage().block()) .filter(message -> message.getAuthor().isPresent()
.getReactors(r).any(user -> user.equals(discordClient.getSelf().block())).block()) && message.getAuthor().get().equals(discordClient.getSelf().block()))
&& Objects.requireNonNull(event.getMessage().block()).getAuthor().isPresent() .filter(message -> message.getReactions().stream()
&& !Objects.requireNonNull(event.getMessage().block()).getAuthor().get().equals(discordClient.getSelf().block())) .noneMatch(r -> message.getReactors(r.getEmoji()).toStream()
.flatMap(event -> event.getMessage().flatMap(message -> message.addReaction(reactionAnswers[new Random().nextInt(reactionAnswers.length)])).then()) .anyMatch(u -> u.equals(discordClient.getSelf().block()))))
.flatMap(message -> message.addReaction(reactionAnswers[new Random().nextInt(reactionAnswers.length)]).then())
.subscribe(); .subscribe();
} }