From d9c2c8e6ea4b694671ff773b0e581ee2b4265a81 Mon Sep 17 00:00:00 2001 From: dust-19 <75648013+dust-19@users.noreply.github.com> Date: Thu, 15 Apr 2021 20:23:24 -0400 Subject: [PATCH] Added JoinsCommand (#38) * add JoinsCommand * Update to include JoinsCommand * updated per owen's request * fixed * ok done --- .../helpbot/bot/HelpBotInstance.java | 5 +- .../bot/command/impl/stats/JoinsCommand.java | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinsCommand.java diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index 7728b0bb..79584d35 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -113,7 +113,8 @@ public static void initialize() throws LoginException { new DiscussionMuteCommand(), new NbsCommand(), new DailySessionsCommand(), - new EightBallCommand() + new EightBallCommand(), + new JoinsCommand() ); JDABuilder builder = JDABuilder.createDefault(config.getToken()) @@ -144,4 +145,4 @@ public static Config getConfig() { public static TaskRegistry getScheduler() { return loop; } -} \ No newline at end of file +} diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinsCommand.java new file mode 100644 index 00000000..983c5b53 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinsCommand.java @@ -0,0 +1,48 @@ +package com.diamondfire.helpbot.bot.command.impl.stats; + +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.help.*; +import com.diamondfire.helpbot.bot.command.impl.Command; +import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; +import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; +import com.diamondfire.helpbot.util.FormatUtil; +import net.dv8tion.jda.api.EmbedBuilder; + +public class JoinsCommand extends Command { + + @Override + public String getName() { return "joins"; } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .description("Shows the total amount of unique players that have joined DiamondFire before.") + .category(CommandCategory.GENERAL_STATS); + } + + @Override + public ArgumentSet compileArguments() { return new ArgumentSet(); } + + @Override + public Permission getPermission() { return Permission.USER; } + + @Override + public void run(CommandEvent event) { + EmbedBuilder builder = new EmbedBuilder(); + + builder.setTitle("Total Joins"); + + // gets the total amount of players that have joined before + new DatabaseQuery() + .query(new BasicQuery("SELECT COUNT(*) AS count FROM players")) + .compile() + .run((result) -> { + String count = FormatUtil.formatNumber(result.getResult().getInt("count")); + builder.setDescription(String.format("A total of %s players have joined DiamondFire before!", count)); + }); + + event.getChannel().sendMessage(builder.build()).queue(); + } +}