From 3d2b5f0caf16b2f9c4a9a6d15eb9145d1ed7ce0d Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Mon, 26 Oct 2020 00:16:08 +0100 Subject: [PATCH] Added a version command Signed-off-by: Louis Vallat --- .../java/xyz/vallat/louis/MovieQuoteBot.java | 10 +++++++- .../xyz/vallat/louis/commands/Version.java | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/java/xyz/vallat/louis/commands/Version.java diff --git a/src/main/java/xyz/vallat/louis/MovieQuoteBot.java b/src/main/java/xyz/vallat/louis/MovieQuoteBot.java index 4aacf7e..9f6c205 100644 --- a/src/main/java/xyz/vallat/louis/MovieQuoteBot.java +++ b/src/main/java/xyz/vallat/louis/MovieQuoteBot.java @@ -11,6 +11,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import xyz.vallat.louis.commands.Command; import xyz.vallat.louis.commands.Ping; +import xyz.vallat.louis.commands.Version; import java.util.HashMap; import java.util.Map; @@ -19,13 +20,17 @@ public class MovieQuoteBot { public static final String DISCORD_TOKEN_ENVIRONMENT = "DISCORD_TOKEN"; public static final String PREFIX = "!"; + public static final String NAME = "Movies Quote Bot"; + public static final String DESCRIPTION = "I may know some quotes from some movies."; public static final String VERSION = "0.1-SNAPSHOT"; private static final Logger logger = LoggerFactory.getLogger(MovieQuoteBot.class.getCanonicalName()); private static final Map commands = new HashMap<>(); + private static GatewayDiscordClient client; static { commands.put("ping", new Ping()); + commands.put("version", new Version()); } public static void main(String[] args) { @@ -34,7 +39,7 @@ public class MovieQuoteBot { System.exit(1); } - GatewayDiscordClient client = DiscordClientBuilder.create( + client = DiscordClientBuilder.create( System.getenv(DISCORD_TOKEN_ENVIRONMENT) == null ? args[0] : System.getenv(DISCORD_TOKEN_ENVIRONMENT) ).build().login().block(); @@ -58,4 +63,7 @@ public class MovieQuoteBot { client.onDisconnect().block(); } + public static Mono getGuilds() { + return client.getGuilds().count(); + } } diff --git a/src/main/java/xyz/vallat/louis/commands/Version.java b/src/main/java/xyz/vallat/louis/commands/Version.java new file mode 100644 index 0000000..5a52558 --- /dev/null +++ b/src/main/java/xyz/vallat/louis/commands/Version.java @@ -0,0 +1,25 @@ +package xyz.vallat.louis.commands; + +import discord4j.core.event.domain.message.MessageCreateEvent; +import discord4j.rest.util.Color; +import reactor.core.publisher.Mono; +import xyz.vallat.louis.MovieQuoteBot; + +public class Version implements Command { + + @Override + public Mono execute(MessageCreateEvent event) { + return event.getMessage().getChannel() + .flatMap(channel -> channel + .createEmbed(embedCreateSpec -> embedCreateSpec + .setColor(Color.RED) + .setTitle(MovieQuoteBot.NAME) + .setDescription(MovieQuoteBot.DESCRIPTION) + .addField("Version", MovieQuoteBot.VERSION, true) + .addField("Guilds", String.valueOf(MovieQuoteBot.getGuilds().block()), true) + ) + ) + .then(); + } + +}