Fix Cat command
This commit is contained in:
parent
af09b0677f
commit
196e61d6bb
@ -5,6 +5,7 @@ import net.Broken.Commande;
|
|||||||
import net.Broken.Tools.Redirection;
|
import net.Broken.Tools.Redirection;
|
||||||
import net.dv8tion.jda.core.entities.ChannelType;
|
import net.dv8tion.jda.core.entities.ChannelType;
|
||||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -19,36 +20,23 @@ public class Cat implements Commande {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
Redirection redirect= new Redirection();
|
|
||||||
if(!event.isFromType(ChannelType.PRIVATE))
|
if(!event.isFromType(ChannelType.PRIVATE))
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
String catLine=null;
|
URL urlC = new URL("http://aws.random.cat/meow");
|
||||||
|
URLConnection yc = urlC.openConnection();
|
||||||
redirect.get("http://random.cat");
|
BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||||
URL cat = new URL(redirect.get("http://random.cat"));
|
yc.getInputStream(), "UTF-8"));
|
||||||
URLConnection cc = cat.openConnection();
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(cc.getInputStream(), "UTF-8"));
|
|
||||||
String inputLine;
|
String inputLine;
|
||||||
|
StringBuilder a = new StringBuilder();
|
||||||
while ((inputLine = in.readLine()) != null)
|
while ((inputLine = in.readLine()) != null)
|
||||||
{
|
a.append(inputLine);
|
||||||
if(inputLine.contains("id=\"cat\""))
|
|
||||||
catLine = inputLine;
|
|
||||||
}
|
|
||||||
in.close();
|
in.close();
|
||||||
String[] splited = catLine.split(" ");
|
|
||||||
String finalLineCat=null;
|
JSONObject json = new JSONObject(a.toString());
|
||||||
for(String aString:splited)
|
|
||||||
{
|
event.getTextChannel().sendMessage(json.getString("file")).queue();
|
||||||
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();
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user