From c13e5249d1dc690d95ae523352be353b5e084c10 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Wed, 15 Jan 2020 19:48:30 +0100 Subject: [PATCH] More error messages --- .../hadder/commands/misc/WakaTimeCommand.java | 31 +++++++++++++++++++ .../Translations/Translations_en.properties | 4 +++ 2 files changed, 35 insertions(+) diff --git a/src/main/java/com/bbn/hadder/commands/misc/WakaTimeCommand.java b/src/main/java/com/bbn/hadder/commands/misc/WakaTimeCommand.java index 9cee11d..c779e7c 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/WakaTimeCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/WakaTimeCommand.java @@ -2,6 +2,14 @@ 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.JSONException; +import org.json.JSONObject; + +import java.io.IOException; /** * @author Skidder / GregTCLTK @@ -11,7 +19,30 @@ public class WakaTimeCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { + if (args.length == 1) { + Request request = new Request.Builder().url("https://wakatime.com/api/v1/users/" + args[0]).build(); + try { + Response response = new OkHttpClient().newCall(request).execute(); + JSONObject json = new JSONObject(response.body().string()); + event.getTextChannel().sendMessage("jisdfids").queue(); + } catch (JSONException e) { + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage( + MessageEditor.MessageType.ERROR, + "commands.misc.wakatime.user.error.title", + "commands.misc.wakatime.user.error.description").build()).queue(); + } catch (IOException | NullPointerException e) { + event.getTextChannel().sendMessage( + event.getMessageEditor().getMessage( + MessageEditor.MessageType.ERROR, + "commands.misc.wakatime.api.error.title", + "commands.misc.wakatime.api.error.description") + .build() + ).queue(); + } + } else { + event.getHelpCommand().sendHelp(this, event); + } } @Override diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index 9167e2d..76505d1 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -73,6 +73,10 @@ commands.misc.screenshare.number.error.description = This isn't a Number. commands.misc.screenshare.channel.existing.error = Hol' up commands.misc.screenshare.channel.existing.description = There is no Voice Channel named like this. \n\nNote\: Make sure the Voice Channel is in this Guild. commands.misc.screenshare.help.description = Shows you the link to share your screen. +commands.misc.wakatime.api.error.title = API error +commands.misc.wakatime.api.error.description = The WakaTime API might be down at the moment\! +commands.misc.wakatime.user.error.title = User doesn't exist +commands.misc.wakatime.user.error.description = I can not find a user named like this\! commands.moderation.ban.success.title = Successfully banned commands.moderation.ban.success.description = I successfully baned %extra%