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; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; /** * Created by seb65 on 07/11/2016. */ public class Pipe implements Commande { Logger logger = LogManager.getLogger(); 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) { Redirection redirect= new Redirection(); if(event.getTextChannel().getName().equals("over18")) { try { 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("