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..3f24ea5 --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/misc/CoronaCommand.java @@ -0,0 +1,69 @@ +/* + * 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; +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("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) + .setTitle("API Error") + .setDescription("Try again later!") + .build()).queue(); + } + } + + @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/java/com/bbn/hadder/commands/misc/MoveAllCommand.java b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java index 5d26277..519e681 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/MoveAllCommand.java @@ -1,46 +1,56 @@ /* - * @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; - 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.Permission; -import net.dv8tion.jda.api.entities.Member; - -import java.util.ArrayList; -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) { - Objects.requireNonNull(e.getGuild().getVoiceChannelById(args[0])).getMembers().forEach( + 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() ); - } else { - e.getHelpCommand().sendHelp(this, e); - } + 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); } @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..f967f19 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -98,6 +98,10 @@ 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.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%