From f27b9cb4f639b2b570d3e6358ae8643ccd742b6e Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Fri, 16 Apr 2021 19:07:10 +0200 Subject: [PATCH] Optimized and fixed the reaction system Signed-off-by: Louis Vallat --- .../louis/managers/discord/DiscordManager.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/xyz/vallat/louis/managers/discord/DiscordManager.java b/app/src/main/java/xyz/vallat/louis/managers/discord/DiscordManager.java index dc282ec..1cc6867 100644 --- a/app/src/main/java/xyz/vallat/louis/managers/discord/DiscordManager.java +++ b/app/src/main/java/xyz/vallat/louis/managers/discord/DiscordManager.java @@ -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(); }