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;
|
2017-02-04 19:31:09 +01:00
|
|
|
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 {
|
2017-02-04 19:31:09 +01:00
|
|
|
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) {
|
2017-02-04 19:31:09 +01:00
|
|
|
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();
|
|
|
|
|
2017-02-04 19:31:09 +01:00
|
|
|
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) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|