|
|
@ -1,27 +1,22 @@ |
|
|
|
package de.yannicpunktdee.yoshibot.command.commands; |
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
import java.net.HttpURLConnection; |
|
|
|
import java.net.URL; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Random; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringEscapeUtils; |
|
|
|
import org.json.JSONException; |
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommand; |
|
|
|
import de.yannicpunktdee.yoshibot.command.YoshiCommandContext; |
|
|
|
import de.yannicpunktdee.yoshibot.main.YoshiBot; |
|
|
|
import net.dv8tion.jda.api.entities.TextChannel; |
|
|
|
import org.json.JSONException; |
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Random; |
|
|
|
|
|
|
|
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 |
|
|
|
*/ |
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
public class JokeCommand extends YoshiCommand { |
|
|
|
|
|
|
|
/** |
|
|
@ -64,31 +59,6 @@ public class JokeCommand extends YoshiCommand { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private String getFromURL(String url) throws IOException { |
|
|
|
StringBuilder response = new StringBuilder(""); |
|
|
|
|
|
|
|
HttpURLConnection con = null; |
|
|
|
|
|
|
|
try{ |
|
|
|
con = (HttpURLConnection)(new URL(url)).openConnection(); |
|
|
|
con.setRequestMethod("GET"); |
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream())); |
|
|
|
|
|
|
|
String line; |
|
|
|
while((line = br.readLine()) != null) { |
|
|
|
response.append(StringEscapeUtils.unescapeHtml4(line)); |
|
|
|
} |
|
|
|
|
|
|
|
br.close(); |
|
|
|
}catch(IOException e) { |
|
|
|
return null; |
|
|
|
}finally { |
|
|
|
if(con != null) con.disconnect(); |
|
|
|
} |
|
|
|
|
|
|
|
return response.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
private String chuckNorris() { |
|
|
|
String url = "http://api.icndb.com/jokes/random"; |
|
|
|
|
|
|
|