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() {
// 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();
}