From 8357a33ec0a36b7062626f91bfd290bfa0764eff Mon Sep 17 00:00:00 2001 From: dust-19 <75648013+dust-19@users.noreply.github.com> Date: Thu, 15 Apr 2021 19:58:48 -0400 Subject: [PATCH 1/5] add JoinsCommand --- .../bot/command/impl/stats/JoinsCommand.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) 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/command/impl/stats/JoinsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinsCommand.java new file mode 100644 index 00000000..19a06a39 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/JoinsCommand.java @@ -0,0 +1,54 @@ +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 players.name, COUNT(*) as count")) + .compile() + .run((result) -> { + String count; + if(result.isEmpty()) { + count = "None (:rotating_light: this should not be happening :rotating_light:)"; + } else { + 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(); + } +} \ No newline at end of file From 0f63ef48eef12a780d61ace6cca0de74d27ba85b Mon Sep 17 00:00:00 2001 From: dust-19 <75648013+dust-19@users.noreply.github.com> Date: Thu, 15 Apr 2021 19:59:25 -0400 Subject: [PATCH 2/5] Update to include JoinsCommand --- .../java/com/diamondfire/helpbot/bot/HelpBotInstance.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 +} From 4d5c1fe1f4029306b50d35f1cde974bc2e49b534 Mon Sep 17 00:00:00 2001 From: dust-19 <75648013+dust-19@users.noreply.github.com> Date: Thu, 15 Apr 2021 20:12:45 -0400 Subject: [PATCH 3/5] updated per owen's request --- .../helpbot/bot/command/impl/stats/JoinsCommand.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) 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 index 19a06a39..c4d8afd3 100644 --- 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 @@ -40,15 +40,10 @@ public void run(CommandEvent event) { .compile() .run((result) -> { String count; - if(result.isEmpty()) { - count = "None (:rotating_light: this should not be happening :rotating_light:)"; - } else { - count = FormatUtil.formatNumber(result.getResult().getInt("count")); - } - + 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(); } -} \ No newline at end of file +} From a4f5159f33125d464916752ed5b0f347c970ec3e Mon Sep 17 00:00:00 2001 From: dust-19 <75648013+dust-19@users.noreply.github.com> Date: Thu, 15 Apr 2021 20:15:17 -0400 Subject: [PATCH 4/5] fixed --- .../helpbot/bot/command/impl/stats/JoinsCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index c4d8afd3..9e644fd6 100644 --- 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 @@ -36,7 +36,7 @@ public void run(CommandEvent event) { // gets the total amount of players that have joined before new DatabaseQuery() - .query(new BasicQuery("SELECT players.name, COUNT(*) as count")) + .query(new BasicQuery("SELECT COUNT(*) AS count FROM players")) .compile() .run((result) -> { String count; From f45ab5b151e5dd5edb14831d7ab52ae4ac82dae1 Mon Sep 17 00:00:00 2001 From: dust-19 <75648013+dust-19@users.noreply.github.com> Date: Thu, 15 Apr 2021 20:20:20 -0400 Subject: [PATCH 5/5] ok done --- .../helpbot/bot/command/impl/stats/JoinsCommand.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 index 9e644fd6..983c5b53 100644 --- 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 @@ -39,8 +39,7 @@ public void run(CommandEvent event) { .query(new BasicQuery("SELECT COUNT(*) AS count FROM players")) .compile() .run((result) -> { - String count; - count = FormatUtil.formatNumber(result.getResult().getInt("count")); + String count = FormatUtil.formatNumber(result.getResult().getInt("count")); builder.setDescription(String.format("A total of %s players have joined DiamondFire before!", count)); });