Fix Cat command

This commit is contained in:
Sebastien 2018-12-04 18:04:46 +02:00
parent af09b0677f
commit 196e61d6bb

View File

@ -5,6 +5,7 @@ import net.Broken.Commande;
import net.Broken.Tools.Redirection;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
@ -19,36 +20,23 @@ public class Cat implements Commande {
@Override
public void action(String[] args, MessageReceivedEvent event) {
Redirection redirect= new Redirection();
if(!event.isFromType(ChannelType.PRIVATE))
{
try {
String catLine=null;
redirect.get("http://random.cat");
URL cat = new URL(redirect.get("http://random.cat"));
URLConnection cc = cat.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(cc.getInputStream(), "UTF-8"));
URL urlC = new URL("http://aws.random.cat/meow");
URLConnection yc = urlC.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream(), "UTF-8"));
String inputLine;
StringBuilder a = new StringBuilder();
while ((inputLine = in.readLine()) != null)
{
if(inputLine.contains("id=\"cat\""))
catLine = inputLine;
}
a.append(inputLine);
in.close();
String[] splited = catLine.split(" ");
String finalLineCat=null;
for(String aString:splited)
{
if(aString.startsWith("src"))
{
finalLineCat=aString;
}
}
System.out.println(finalLineCat);
finalLineCat=finalLineCat.replaceAll("src=\"","");
finalLineCat=finalLineCat.replaceAll("\"","");
event.getTextChannel().sendMessage("http://random.cat/"+finalLineCat).queue();
JSONObject json = new JSONObject(a.toString());
event.getTextChannel().sendMessage(json.getString("file")).queue();
} catch (IOException e) {
e.printStackTrace();