From e22e4fec02b3e2eb5958155f27818c60b94a6133 Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Mon, 26 Oct 2020 00:57:02 +0100 Subject: [PATCH] Added strict comparison for commands and presence Signed-off-by: Louis Vallat --- src/main/java/xyz/vallat/louis/MovieQuoteBot.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/vallat/louis/MovieQuoteBot.java b/src/main/java/xyz/vallat/louis/MovieQuoteBot.java index 9f6c205..bb20542 100644 --- a/src/main/java/xyz/vallat/louis/MovieQuoteBot.java +++ b/src/main/java/xyz/vallat/louis/MovieQuoteBot.java @@ -5,6 +5,9 @@ import discord4j.core.GatewayDiscordClient; import discord4j.core.event.domain.lifecycle.ReadyEvent; import discord4j.core.event.domain.message.MessageCreateEvent; import discord4j.core.object.entity.User; +import discord4j.core.object.presence.Activity; +import discord4j.core.object.presence.Presence; +import discord4j.discordjson.json.gateway.StatusUpdate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Flux; @@ -44,6 +47,7 @@ public class MovieQuoteBot { ).build().login().block(); assert client != null; + client.updatePresence(Presence.online(Activity.watching("some more films"))).subscribe(); client.getEventDispatcher().on(ReadyEvent.class) .subscribe(event -> { User self = event.getSelf(); @@ -53,12 +57,15 @@ public class MovieQuoteBot { client.getEventDispatcher().on(MessageCreateEvent.class) .flatMap(event -> Mono.just(event.getMessage().getContent()) .flatMap(content -> Flux.fromIterable(commands.entrySet()) - .filter(entry -> content.startsWith(PREFIX + entry.getKey())) + .filter(entry -> content.split(" ")[0].equals(PREFIX + entry.getKey())) .flatMap(entry -> entry.getValue().execute(event)) .next())) .subscribe(); - Runtime.getRuntime().addShutdownHook(new Thread(() -> logger.info("Received shut down signal. Bye!"))); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + logger.info("Received shut down signal. Bye!"); + client.logout(); + })); client.onDisconnect().block(); }