Adding Cat commande
This commit is contained in:
parent
1615bea3ae
commit
e4287a2a33
@ -3,11 +3,8 @@ package net.borken;
|
|||||||
import net.borken.Outils.CommandParser;
|
import net.borken.Outils.CommandParser;
|
||||||
import net.borken.Outils.DayListener;
|
import net.borken.Outils.DayListener;
|
||||||
import net.borken.Outils.Redirection;
|
import net.borken.Outils.Redirection;
|
||||||
import net.borken.commandes.Help;
|
import net.borken.commandes.*;
|
||||||
import net.borken.commandes.Move;
|
|
||||||
import net.borken.commandes.Over18.*;
|
import net.borken.commandes.Over18.*;
|
||||||
import net.borken.commandes.PingCommande;
|
|
||||||
import net.borken.commandes.Spam;
|
|
||||||
import net.dv8tion.jda.core.AccountType;
|
import net.dv8tion.jda.core.AccountType;
|
||||||
import net.dv8tion.jda.core.JDA;
|
import net.dv8tion.jda.core.JDA;
|
||||||
import net.dv8tion.jda.core.JDABuilder;
|
import net.dv8tion.jda.core.JDABuilder;
|
||||||
@ -21,7 +18,11 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -99,6 +100,7 @@ public class MainBot {
|
|||||||
commandes.put("pipe",new Pipe());
|
commandes.put("pipe",new Pipe());
|
||||||
commandes.put("sm",new SM());
|
commandes.put("sm",new SM());
|
||||||
commandes.put("madame",new Madame());
|
commandes.put("madame",new Madame());
|
||||||
|
commandes.put("cat",new Cat());
|
||||||
|
|
||||||
//On recupere le l'id serveur
|
//On recupere le l'id serveur
|
||||||
Guild serveur = jda.getGuilds().get(0);
|
Guild serveur = jda.getGuilds().get(0);
|
||||||
|
67
src/net/borken/commandes/Cat.java
Normal file
67
src/net/borken/commandes/Cat.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package net.borken.commandes;
|
||||||
|
|
||||||
|
import net.borken.Commande;
|
||||||
|
import net.borken.Outils.Redirection;
|
||||||
|
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Seb on 06/02/2017.
|
||||||
|
*/
|
||||||
|
public class Cat implements Commande{
|
||||||
|
@Override
|
||||||
|
public boolean called(String[] args, MessageReceivedEvent event) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
|
Redirection redirect= new Redirection();
|
||||||
|
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"));
|
||||||
|
String inputLine;
|
||||||
|
while ((inputLine = in.readLine()) != null)
|
||||||
|
{
|
||||||
|
if(inputLine.contains("id=\"cat\""))
|
||||||
|
catLine = 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();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String help(String[] args) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executed(boolean success, MessageReceivedEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -26,8 +26,8 @@ public class Ass implements Commande{
|
|||||||
Redirection redirect= new Redirection();
|
Redirection redirect= new Redirection();
|
||||||
try {
|
try {
|
||||||
event.getTextChannel().sendMessage(redirect.get("http://les400culs.com/random")).queue();
|
event.getTextChannel().sendMessage(redirect.get("http://les400culs.com/random")).queue();
|
||||||
logger.warn("Erreur de redirection.");
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
logger.warn("Erreur de redirection.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user