Added strict comparison for commands and presence
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
a200e1c602
commit
e22e4fec02
@ -5,6 +5,9 @@ import discord4j.core.GatewayDiscordClient;
|
|||||||
import discord4j.core.event.domain.lifecycle.ReadyEvent;
|
import discord4j.core.event.domain.lifecycle.ReadyEvent;
|
||||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||||
import discord4j.core.object.entity.User;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
@ -44,6 +47,7 @@ public class MovieQuoteBot {
|
|||||||
).build().login().block();
|
).build().login().block();
|
||||||
|
|
||||||
assert client != null;
|
assert client != null;
|
||||||
|
client.updatePresence(Presence.online(Activity.watching("some more films"))).subscribe();
|
||||||
client.getEventDispatcher().on(ReadyEvent.class)
|
client.getEventDispatcher().on(ReadyEvent.class)
|
||||||
.subscribe(event -> {
|
.subscribe(event -> {
|
||||||
User self = event.getSelf();
|
User self = event.getSelf();
|
||||||
@ -53,12 +57,15 @@ public class MovieQuoteBot {
|
|||||||
client.getEventDispatcher().on(MessageCreateEvent.class)
|
client.getEventDispatcher().on(MessageCreateEvent.class)
|
||||||
.flatMap(event -> Mono.just(event.getMessage().getContent())
|
.flatMap(event -> Mono.just(event.getMessage().getContent())
|
||||||
.flatMap(content -> Flux.fromIterable(commands.entrySet())
|
.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))
|
.flatMap(entry -> entry.getValue().execute(event))
|
||||||
.next()))
|
.next()))
|
||||||
.subscribe();
|
.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();
|
client.onDisconnect().block();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user