Added strict comparison for commands and presence

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2020-10-26 00:57:02 +01:00
parent a200e1c602
commit e22e4fec02

View File

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