|
|
@ -15,6 +15,7 @@ import static de.yannicpunktdee.yoshibot.utils.RestHelper.getFromURL; |
|
|
|
|
|
|
|
/** |
|
|
|
* Schickt einen zufälligen Jokus aus einer zufällig ausgewählten Quelle in den Textchannel. |
|
|
|
* |
|
|
|
* @author Yannic Link |
|
|
|
*/ |
|
|
|
public class JokeCommand extends YoshiCommand { |
|
|
@ -29,31 +30,41 @@ public class JokeCommand extends YoshiCommand { |
|
|
|
/** |
|
|
|
* {@inheritDoc} |
|
|
|
*/ |
|
|
|
@Override public synchronized boolean execute() { |
|
|
|
@Override |
|
|
|
public synchronized boolean execute() { |
|
|
|
String message = "Jokus"; |
|
|
|
|
|
|
|
Random random = YoshiBot.getInstance().getRandom(); |
|
|
|
int number = random.nextInt(3); |
|
|
|
switch(number) { |
|
|
|
case 0: message = jokeApi(); break; |
|
|
|
case 1: message = officialJokeApi(); break; |
|
|
|
case 2: message = chuckNorris(); break; |
|
|
|
default: message = "Jokus"; break; |
|
|
|
switch (number) { |
|
|
|
case 0: |
|
|
|
message = jokeApi(); |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
message = officialJokeApi(); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
message = chuckNorris(); |
|
|
|
break; |
|
|
|
default: |
|
|
|
message = "Jokus"; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if(context.containsArguments(new String[] {"channel"})) { |
|
|
|
if (context.containsArguments(new String[]{"channel"})) { |
|
|
|
String arg = context.getArgument("channel"); |
|
|
|
if(arg == null) { |
|
|
|
if (arg == null) { |
|
|
|
sendMessage("Es wurde kein channel angegeben."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
List<TextChannel> channels = YoshiBot.getInstance().jda.getTextChannelsByName(context.getArgument("channel"), true); |
|
|
|
if(channels.isEmpty()) { |
|
|
|
List<TextChannel> channels = YoshiBot.getInstance().jda |
|
|
|
.getTextChannelsByName(context.getArgument("channel"), true); |
|
|
|
if (channels.isEmpty()) { |
|
|
|
sendMessage("Der Kanalname konnte nicht gefunden werden."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
channels.get(0).sendMessage(message).queue(); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
sendMessage(message); |
|
|
|
} |
|
|
|
return true; |
|
|
@ -68,7 +79,7 @@ public class JokeCommand extends YoshiCommand { |
|
|
|
String raw = getFromURL(url); |
|
|
|
json = new JSONObject(raw); |
|
|
|
return json.getJSONObject("value").getString("joke"); |
|
|
|
}catch(JSONException | IOException e) { |
|
|
|
} catch (JSONException e) { |
|
|
|
return "Konnte keinen Jokus von \"" + url + "\" laden."; |
|
|
|
} |
|
|
|
} |
|
|
@ -85,7 +96,7 @@ public class JokeCommand extends YoshiCommand { |
|
|
|
result += " - "; |
|
|
|
result += json.getString("punchline"); |
|
|
|
return result; |
|
|
|
}catch(JSONException | IOException e) { |
|
|
|
} catch (JSONException e) { |
|
|
|
return "Konnte keinen Jokus von \"" + url + "\" laden."; |
|
|
|
} |
|
|
|
} |
|
|
@ -102,9 +113,9 @@ public class JokeCommand extends YoshiCommand { |
|
|
|
result += " - "; |
|
|
|
result += json.getString("delivery"); |
|
|
|
return result; |
|
|
|
}catch(JSONException | IOException e) { |
|
|
|
} catch (JSONException e) { |
|
|
|
return "Konnte keinen Jokus von \"" + url + "\" laden."; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |