From 8b4926aab245ada31d87f21814d814b3667603f2 Mon Sep 17 00:00:00 2001 From: Schlauer-Hax Date: Fri, 13 Mar 2020 22:15:33 +0100 Subject: [PATCH 1/9] Fix --- .../java/com/bbn/hadder/commands/misc/MoveAllCommand.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java index 5d26277..90aa962 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java @@ -8,6 +8,7 @@ import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.core.Perm; import com.bbn.hadder.core.Perms; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; @@ -20,9 +21,14 @@ public class MoveAllCommand implements Command { @Override public void executed(String[] args, CommandEvent e) { if (args.length == 2) { + int count = 0; Objects.requireNonNull(e.getGuild().getVoiceChannelById(args[0])).getMembers().forEach( - member -> e.getGuild().moveVoiceMember(member, e.getGuild().getVoiceChannelById(args[1])).queue() + member -> { + e.getGuild().moveVoiceMember(member, e.getGuild().getVoiceChannelById(args[1])).queue(); + } ); + e.getChannel().sendMessage(new EmbedBuilder().setTitle("Successfully Moved!").setDescription("I moved " + + Objects.requireNonNull(e.getGuild().getVoiceChannelById(args[0])).getMembers().size() + " Members. Have fun!").build()).queue(); } else { e.getHelpCommand().sendHelp(this, e); } -- 2.45.3 From fbbdb9f48813cf627d490f6c69bb37f0b11e367b Mon Sep 17 00:00:00 2001 From: Schlauer-Hax Date: Fri, 13 Mar 2020 22:15:54 +0100 Subject: [PATCH 2/9] a --- src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java index 90aa962..33684f0 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java @@ -21,13 +21,12 @@ public class MoveAllCommand implements Command { @Override public void executed(String[] args, CommandEvent e) { if (args.length == 2) { - int count = 0; Objects.requireNonNull(e.getGuild().getVoiceChannelById(args[0])).getMembers().forEach( member -> { e.getGuild().moveVoiceMember(member, e.getGuild().getVoiceChannelById(args[1])).queue(); } ); - e.getChannel().sendMessage(new EmbedBuilder().setTitle("Successfully Moved!").setDescription("I moved " + + e.getChannel().sendMessage(new EmbedBuilder().setTitle("Successfully Moved!").setDescription("I moved " + Objects.requireNonNull(e.getGuild().getVoiceChannelById(args[0])).getMembers().size() + " Members. Have fun!").build()).queue(); } else { e.getHelpCommand().sendHelp(this, e); -- 2.45.3 From e0df9cc7388d28cadbdd32d4e97d58120a47b5d6 Mon Sep 17 00:00:00 2001 From: Schlauer-Hax Date: Fri, 13 Mar 2020 22:16:33 +0100 Subject: [PATCH 3/9] aa --- src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java index 33684f0..bf8fc95 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java @@ -21,13 +21,14 @@ public class MoveAllCommand implements Command { @Override public void executed(String[] args, CommandEvent e) { if (args.length == 2) { + int count = Objects.requireNonNull(e.getGuild().getVoiceChannelById(args[0])).getMembers().size(); Objects.requireNonNull(e.getGuild().getVoiceChannelById(args[0])).getMembers().forEach( member -> { e.getGuild().moveVoiceMember(member, e.getGuild().getVoiceChannelById(args[1])).queue(); } ); e.getChannel().sendMessage(new EmbedBuilder().setTitle("Successfully Moved!").setDescription("I moved " + - Objects.requireNonNull(e.getGuild().getVoiceChannelById(args[0])).getMembers().size() + " Members. Have fun!").build()).queue(); + count + " Members. Have fun!").build()).queue(); } else { e.getHelpCommand().sendHelp(this, e); } -- 2.45.3 From e031eb1532217a8b406d59988f415fabbddb05a8 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 14 Mar 2020 15:28:16 +0100 Subject: [PATCH 4/9] Fix help stuff --- .../hadder/commands/misc/MoveAllCommand.java | 27 ++++++++++++------- .../Translations/Translations_en.properties | 1 + 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java index bf8fc95..d6e84f7 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java @@ -1,5 +1,17 @@ /* - * @author Hax / Hax6775 / Schlauer_Hax + * Copyright 2019-2020 GregTCLTK and Schlauer-Hax + * + * Licensed under the GNU Affero General Public License, Version 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/agpl-3.0.en.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.bbn.hadder.commands.misc; @@ -9,10 +21,7 @@ import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.core.Perm; import com.bbn.hadder.core.Perms; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Member; -import java.util.ArrayList; import java.util.Objects; public class MoveAllCommand implements Command { @@ -29,24 +38,22 @@ public class MoveAllCommand implements Command { ); e.getChannel().sendMessage(new EmbedBuilder().setTitle("Successfully Moved!").setDescription("I moved " + count + " Members. Have fun!").build()).queue(); - } else { - e.getHelpCommand().sendHelp(this, e); - } + } else e.getHelpCommand().sendHelp(this, e); } @Override public String[] labels() { - return new String[]{"moveall", "move-all"}; + return new String[]{"moveall", "move-all", "ma"}; } @Override public String description() { - return "Moves All users in channel1 to channel2"; + return "commands.misc.moveall.help.description"; } @Override public String usage() { - return "[channel1] [channel2]"; + return "[source-channel] [target-channel]"; } @Override diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index 01d2f6e..0ccc653 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -98,6 +98,7 @@ commands.misc.code.success.description = This message contains some information commands.misc.code.error.title = Code not found commands.misc.code.error.description = I can't find the specified invite code. commands.misc.code.help.description = Shows information about a invite code. +commands.misc.moveall.help.description = Moves all users in the source channel to the target channel. commands.moderation.ban.success.title = Successfully banned commands.moderation.ban.success.description = I successfully baned %extra% -- 2.45.3 From 8de3748f1a8864f2c2c29c977f97a41b3c642d98 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 14 Mar 2020 15:35:27 +0100 Subject: [PATCH 5/9] i18n stuff --- .../hadder/commands/misc/MoveAllCommand.java | 20 +++++++++---------- .../Translations/Translations_en.properties | 2 ++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java index d6e84f7..8746c3c 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java @@ -20,24 +20,22 @@ import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.core.Perm; import com.bbn.hadder.core.Perms; -import net.dv8tion.jda.api.EmbedBuilder; - -import java.util.Objects; +import com.bbn.hadder.utils.MessageEditor; +@Perms(Perm.VOICE_MOVE_OTHERS) public class MoveAllCommand implements Command { - @Perms(Perm.VOICE_MOVE_OTHERS) @Override public void executed(String[] args, CommandEvent e) { if (args.length == 2) { - int count = Objects.requireNonNull(e.getGuild().getVoiceChannelById(args[0])).getMembers().size(); - Objects.requireNonNull(e.getGuild().getVoiceChannelById(args[0])).getMembers().forEach( - member -> { - e.getGuild().moveVoiceMember(member, e.getGuild().getVoiceChannelById(args[1])).queue(); - } + int count = e.getGuild().getVoiceChannelById(args[0]).getMembers().size(); + e.getGuild().getVoiceChannelById(args[0]).getMembers().forEach( + member -> e.getGuild().moveVoiceMember(member, e.getGuild().getVoiceChannelById(args[1])).queue() ); - e.getChannel().sendMessage(new EmbedBuilder().setTitle("Successfully Moved!").setDescription("I moved " + - count + " Members. Have fun!").build()).queue(); + e.getChannel().sendMessage(e.getMessageEditor().getMessage(MessageEditor.MessageType.INFO, + "commands.misc.moveall.success.title", "", + "commands.misc.moveall.success.description", String.valueOf(count)) + .build()).queue(); } else e.getHelpCommand().sendHelp(this, e); } diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index 0ccc653..e818bc3 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -98,6 +98,8 @@ commands.misc.code.success.description = This message contains some information commands.misc.code.error.title = Code not found commands.misc.code.error.description = I can't find the specified invite code. commands.misc.code.help.description = Shows information about a invite code. +commands.misc.moveall.success.title = Successfully moved +commands.misc.moveall.success.description = I successfully moved %extra% members. Have fun! commands.misc.moveall.help.description = Moves all users in the source channel to the target channel. commands.moderation.ban.success.title = Successfully banned -- 2.45.3 From 39cef6b5fdcda09f57ebd6c4ea5e6ab87eff62c8 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 14 Mar 2020 15:51:48 +0100 Subject: [PATCH 6/9] Remove a line lol --- src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java index 8746c3c..519e681 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java @@ -15,7 +15,6 @@ */ package com.bbn.hadder.commands.misc; - import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.core.Perm; -- 2.45.3 From b4a25bfc97c573d7cd2b89e4ae1013a81d0bb7e7 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 14 Mar 2020 15:53:09 +0100 Subject: [PATCH 7/9] covid command --- src/main/java/com/bbn/hadder/Hadder.java | 3 +- .../hadder/commands/misc/CoronaCommand.java | 48 +++++++++++++++++++ .../Translations/Translations_en.properties | 1 + 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java index 0d93dd7..99f9b3d 100644 --- a/src/main/java/com/bbn/hadder/Hadder.java +++ b/src/main/java/com/bbn/hadder/Hadder.java @@ -127,7 +127,8 @@ public class Hadder { new ServerStatsCommand(), new ProfileCommand(), new CodeCommand(), - new MoveAllCommand()), config, helpCommand); + new MoveAllCommand(), + new CoronaCommand()), config, helpCommand); builder.addEventListeners( new MentionListener(rethink), diff --git a/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java b/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java new file mode 100644 index 0000000..3235fa3 --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java @@ -0,0 +1,48 @@ +/* + * Copyright 2019-2020 GregTCLTK and Schlauer-Hax + * + * Licensed under the GNU Affero General Public License, Version 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.gnu.org/licenses/agpl-3.0.en.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.bbn.hadder.commands.misc; + +import com.bbn.hadder.commands.Command; +import com.bbn.hadder.commands.CommandEvent; + +public class CoronaCommand implements Command { + + @Override + public void executed(String[] args, CommandEvent e) { + + } + + @Override + public String[] labels() { + return new String[]{"corona"}; + } + + @Override + public String description() { + return "commands.misc.corona.help.description"; + } + + @Override + public String usage() { + return null; + } + + @Override + public String example() { + return null; + } +} diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index e818bc3..f967f19 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -101,6 +101,7 @@ commands.misc.code.help.description = Shows information about a invite code. commands.misc.moveall.success.title = Successfully moved commands.misc.moveall.success.description = I successfully moved %extra% members. Have fun! commands.misc.moveall.help.description = Moves all users in the source channel to the target channel. +commands.misc.corona.help.description = Show the newest stats about COVID-19 commands.moderation.ban.success.title = Successfully banned commands.moderation.ban.success.description = I successfully baned %extra% -- 2.45.3 From 36994799bd2aa04670bf47bf536385227c308c06 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 14 Mar 2020 16:19:13 +0100 Subject: [PATCH 8/9] Finish it --- .../hadder/commands/misc/CoronaCommand.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java b/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java index 3235fa3..4f47da5 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java @@ -18,12 +18,33 @@ package com.bbn.hadder.commands.misc; import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.CommandEvent; +import com.bbn.hadder.utils.MessageEditor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.json.JSONObject; + +import java.io.IOException; public class CoronaCommand implements Command { @Override public void executed(String[] args, CommandEvent e) { + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder().url("https://api.covid.stream/latest/numbers").build(); + try { + Response response = client.newCall(request).execute(); + JSONObject json = new JSONObject(response.body().string()).getJSONObject("data"); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("`Confirmed cases:` **").append(json.get("totalConfirmedNumber")).append("**\n").append("`Deaths:` **").append(json.get("totalDeathNumbers")).append("** \n").append("`Recovered:`" ).append("** \n"); + e.getTextChannel().sendMessage(e.getMessageEditor().getMessage(MessageEditor.MessageType.INFO).setDescription(stringBuilder).build()).queue(); + } catch (IOException ex) { + e.getTextChannel().sendMessage(e.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR) + .setTitle("API Error") + .setDescription("Try again later!") + .build()).queue(); + } } @Override -- 2.45.3 From b8cf0cfe054442233fbedbfb87c478a0c4dc3e80 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 14 Mar 2020 16:22:06 +0100 Subject: [PATCH 9/9] Fix --- src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java b/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java index 4f47da5..3f24ea5 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java @@ -37,7 +37,7 @@ public class CoronaCommand implements Command { Response response = client.newCall(request).execute(); JSONObject json = new JSONObject(response.body().string()).getJSONObject("data"); StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("`Confirmed cases:` **").append(json.get("totalConfirmedNumber")).append("**\n").append("`Deaths:` **").append(json.get("totalDeathNumbers")).append("** \n").append("`Recovered:`" ).append("** \n"); + stringBuilder.append("`Confirmed cases:` **").append(json.get("totalConfirmedNumbers")).append("**\n").append("`Deaths:` **").append(json.get("totalDeathNumbers")).append("** \n").append("`Recovered:` **").append(json.get("totalRecoveredNumbers")).append("** \n"); e.getTextChannel().sendMessage(e.getMessageEditor().getMessage(MessageEditor.MessageType.INFO).setDescription(stringBuilder).build()).queue(); } catch (IOException ex) { e.getTextChannel().sendMessage(e.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR) -- 2.45.3