Added a version command

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2020-10-26 00:16:08 +01:00
parent e1617e3280
commit 3d2b5f0caf
2 changed files with 34 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import xyz.vallat.louis.commands.Command; import xyz.vallat.louis.commands.Command;
import xyz.vallat.louis.commands.Ping; import xyz.vallat.louis.commands.Ping;
import xyz.vallat.louis.commands.Version;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -19,13 +20,17 @@ public class MovieQuoteBot {
public static final String DISCORD_TOKEN_ENVIRONMENT = "DISCORD_TOKEN"; public static final String DISCORD_TOKEN_ENVIRONMENT = "DISCORD_TOKEN";
public static final String PREFIX = "!"; 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"; public static final String VERSION = "0.1-SNAPSHOT";
private static final Logger logger = LoggerFactory.getLogger(MovieQuoteBot.class.getCanonicalName()); private static final Logger logger = LoggerFactory.getLogger(MovieQuoteBot.class.getCanonicalName());
private static final Map<String, Command> commands = new HashMap<>(); private static final Map<String, Command> commands = new HashMap<>();
private static GatewayDiscordClient client;
static { static {
commands.put("ping", new Ping()); commands.put("ping", new Ping());
commands.put("version", new Version());
} }
public static void main(String[] args) { public static void main(String[] args) {
@ -34,7 +39,7 @@ public class MovieQuoteBot {
System.exit(1); System.exit(1);
} }
GatewayDiscordClient client = DiscordClientBuilder.create( client = DiscordClientBuilder.create(
System.getenv(DISCORD_TOKEN_ENVIRONMENT) == null ? args[0] : System.getenv(DISCORD_TOKEN_ENVIRONMENT) System.getenv(DISCORD_TOKEN_ENVIRONMENT) == null ? args[0] : System.getenv(DISCORD_TOKEN_ENVIRONMENT)
).build().login().block(); ).build().login().block();
@ -58,4 +63,7 @@ public class MovieQuoteBot {
client.onDisconnect().block(); client.onDisconnect().block();
} }
public static Mono<Long> getGuilds() {
return client.getGuilds().count();
}
} }

View File

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