ClaptrapBot/src/net/borken/commandes/Over18/Pipe.java

91 lines
2.9 KiB
Java
Raw Normal View History

2016-12-08 20:05:23 +01:00
package net.borken.commandes.Over18;
import net.borken.Commande;
import net.borken.Outils.Redirection;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2016-12-08 20:05:23 +01:00
2017-02-08 23:53:50 +01:00
import java.io.BufferedReader;
2016-12-08 20:05:23 +01:00
import java.io.IOException;
2017-02-08 23:53:50 +01:00
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
2016-12-08 20:05:23 +01:00
/**
* Created by seb65 on 07/11/2016.
*/
public class Pipe implements Commande {
Logger logger = LogManager.getLogger();
2016-12-08 20:05:23 +01:00
public String HELP="T'es sérieux la?";
@Override
public boolean called(String[] args, MessageReceivedEvent event) {
return false;
}
@Override
public void action(String[] args, MessageReceivedEvent event) {
2017-02-08 23:53:50 +01:00
2016-12-08 20:05:23 +01:00
Redirection redirect= new Redirection();
if(event.getTextChannel().getName().equals("over18"))
{
try {
2017-02-08 23:53:50 +01:00
System.out.println("ok");
String pipeLine=null;
URL pipeURL = new URL(redirect.get("http://feelation.com/random"));
URLConnection cc = pipeURL.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(cc.getInputStream(), "UTF-8"));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
if(inputLine.contains("class=\"post photo\""))
{
String[] splited = inputLine.split("<");
for(String aString:splited)
{
if(aString.startsWith("<img src"))
{
pipeLine=aString;
pipeLine=inputLine.replaceAll("<img src=\"","");
pipeLine=pipeLine.substring(0,pipeLine.indexOf("\""));
System.out.println(pipeLine);
break;
}
}
}
}
in.close();
2016-12-08 20:05:23 +01:00
event.getTextChannel().sendMessage(redirect.get("http://feelation.com/random")).queue();
} catch (IOException e) {
logger.warn("Erreur de redirection.");
2017-02-08 23:53:50 +01:00
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur de redirection (5 essais), Réessayez__**:warning: ").queue();
2016-12-08 20:05:23 +01:00
}
}
else
{
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:warning: **__Channel règlementé! Go sur over18!__**:warning: ").queue();
logger.warn("Erreur chanel.");
2016-12-08 20:05:23 +01:00
}
}
@Override
public String help(String[] args) {
return HELP;
}
@Override
public void executed(boolean success, MessageReceivedEvent event) {
}
}