Now numberedCommand return .jpg
This commit is contained in:
parent
2010948cc4
commit
dde7d146e9
@ -1,5 +1,6 @@
|
||||
package net.Broken.Commandes;
|
||||
import net.Broken.Commande;
|
||||
import net.Broken.Outils.FindContentOnWebPage;
|
||||
import net.Broken.Outils.LimitChecker;
|
||||
import net.Broken.Outils.Redirection;
|
||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
@ -19,11 +20,15 @@ public abstract class NumberedCommande implements Commande{
|
||||
int minNumber = 1;
|
||||
int maxNumber = -1;
|
||||
String baseURL;
|
||||
String divClass;
|
||||
String htmlType;
|
||||
|
||||
|
||||
public NumberedCommande(Logger logger, String baseURL) {
|
||||
public NumberedCommande(Logger logger, String baseURL, String divClass, String htmlType) {
|
||||
this.logger = logger;
|
||||
this.baseURL = baseURL;
|
||||
this.divClass = divClass;
|
||||
this.htmlType = htmlType;
|
||||
try {
|
||||
logger.info("Checking max...");
|
||||
maxNumber = LimitChecker.doYourJob(baseURL, minNumber);
|
||||
@ -40,80 +45,87 @@ public abstract class NumberedCommande implements Commande{
|
||||
|
||||
@Override
|
||||
public void action(String[] args, MessageReceivedEvent event) {
|
||||
if(args.length == 0)
|
||||
try
|
||||
{
|
||||
if(event.getTextChannel().getName().equals("nsfw-over18")) {
|
||||
Redirection redirect= new Redirection();
|
||||
int randomResult = (int) (minNumber + (Math.random() * (maxNumber - minNumber)));
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n"+baseURL+randomResult+"-2/").queue();
|
||||
if(args.length == 0)
|
||||
{
|
||||
if(event.getTextChannel().getName().equals("nsfw-over18")) {
|
||||
Redirection redirect= new Redirection();
|
||||
int randomResult = (int) (minNumber + (Math.random() * (maxNumber - minNumber)));
|
||||
String result = FindContentOnWebPage.doYourJob(baseURL + randomResult + "-2", divClass, htmlType);
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n"+result).queue();
|
||||
}
|
||||
else
|
||||
{
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:warning: **__Channel règlementé! Go sur over18!__**:warning: ").queue();
|
||||
|
||||
logger.warn("Erreur chanel.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:warning: **__Channel règlementé! Go sur over18!__**:warning: ").queue();
|
||||
|
||||
logger.warn("Erreur chanel.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(args[0].toLowerCase().equals("update"))
|
||||
{
|
||||
logger.info("update commande from "+event.getMessage().getAuthor().getName());
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: Updating...").queue();
|
||||
|
||||
int newNumber = maxNumber;
|
||||
try {
|
||||
newNumber = LimitChecker.doYourJob(baseURL,maxNumber);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(newNumber == maxNumber)
|
||||
{
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: Aucune nouvelle image n'a était trouver :cry:").queue();
|
||||
}
|
||||
else if(newNumber-maxNumber == 1) event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: "+(newNumber-maxNumber)+" nouvelle image a été trouvé :kissing_heart:").queue();
|
||||
else
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: "+(newNumber-maxNumber)+" nouvelles images on été trouvé :kissing_heart:").queue();
|
||||
logger.info((newNumber-maxNumber)+" new image(s) found.");
|
||||
maxNumber = newNumber;
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("get")) {
|
||||
if (args.length >= 2)
|
||||
if(args[0].toLowerCase().equals("update"))
|
||||
{
|
||||
logger.info("update commande from "+event.getMessage().getAuthor().getName());
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: Updating...").queue();
|
||||
|
||||
int number = -1;
|
||||
int newNumber = maxNumber;
|
||||
try {
|
||||
number = Integer.parseInt(args[1]);
|
||||
URL url = new URL(baseURL + number + "-2/");
|
||||
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
|
||||
huc.setRequestMethod("GET");
|
||||
huc.connect();
|
||||
int result = huc.getResponseCode();
|
||||
if (result == 200) {
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n" + baseURL + number + "-2/").queue();
|
||||
} else {
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur__** :warning:\n:arrow_right: Page introuvable (404)").queue();
|
||||
}
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur__** :warning:\n:arrow_right: Erreur d'argument. `//help " + this.toString().toLowerCase() + "` pour plus d'info ").queue();
|
||||
newNumber = LimitChecker.doYourJob(baseURL,maxNumber);
|
||||
} catch (IOException e) {
|
||||
logger.catching(e);
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur__** :warning:\n:arrow_right: Erreur interne...").queue();
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(newNumber == maxNumber)
|
||||
{
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: Aucune nouvelle image n'a était trouver :cry:").queue();
|
||||
}
|
||||
else if(newNumber-maxNumber == 1) event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: "+(newNumber-maxNumber)+" nouvelle image a été trouvé :kissing_heart:").queue();
|
||||
else
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: "+(newNumber-maxNumber)+" nouvelles images on été trouvé :kissing_heart:").queue();
|
||||
logger.info((newNumber-maxNumber)+" new image(s) found.");
|
||||
maxNumber = newNumber;
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("get")) {
|
||||
if (args.length >= 2)
|
||||
{
|
||||
|
||||
int number = -1;
|
||||
try {
|
||||
number = Integer.parseInt(args[1]);
|
||||
URL url = new URL(baseURL + number + "-2/");
|
||||
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
|
||||
huc.setRequestMethod("GET");
|
||||
huc.connect();
|
||||
int result = huc.getResponseCode();
|
||||
if (result == 200) {
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n" + baseURL + number + "-2/").queue();
|
||||
} else {
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur__** :warning:\n:arrow_right: Page introuvable (404)").queue();
|
||||
}
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur__** :warning:\n:arrow_right: Erreur d'argument. `//help " + this.toString().toLowerCase() + "` pour plus d'info ").queue();
|
||||
} catch (IOException e) {
|
||||
logger.catching(e);
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur__** :warning:\n:arrow_right: Erreur interne...").queue();
|
||||
}
|
||||
}
|
||||
else{
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur__** :warning:\n:arrow_right: Erreur d'argument. `//help " + this.toString().toLowerCase() + "` pour plus d'info ").queue();
|
||||
logger.warn("Bad Argument: "+event.getMessage().getContent()+" From "+event.getAuthor().getName());
|
||||
}
|
||||
}
|
||||
else{
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur__** :warning:\n:arrow_right: Erreur d'argument. `//help " + this.toString().toLowerCase() + "` pour plus d'info ").queue();
|
||||
else
|
||||
{
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:warning: **__Erreur__** :warning:\n:arrow_right: Erreur d'argument. `//help "+this.toString().toLowerCase()+"` pour plus d'info ").queue();
|
||||
logger.warn("Bad Argument: "+event.getMessage().getContent()+" From "+event.getAuthor().getName());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:warning: **__Erreur__** :warning:\n:arrow_right: Erreur d'argument. `//help "+this.toString().toLowerCase()+"` pour plus d'info ").queue();
|
||||
logger.warn("Bad Argument: "+event.getMessage().getContent()+" From "+event.getAuthor().getName());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.catching(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,7 +9,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
public class Ass extends NumberedCommande {
|
||||
|
||||
public Ass() {
|
||||
super(LogManager.getLogger(), "http://les400culs.com/");
|
||||
super(LogManager.getLogger(), "http://les400culs.com/","featured-img","img");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,7 +9,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
public class Boobs extends NumberedCommande {
|
||||
|
||||
public Boobs() {
|
||||
super(LogManager.getLogger(), "http://lesaintdesseins.fr/");
|
||||
super(LogManager.getLogger(), "http://lesaintdesseins.fr/","featured-img","img");
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -8,7 +8,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
*/
|
||||
public class Pipe extends NumberedCommande {
|
||||
public Pipe() {
|
||||
super(LogManager.getLogger(), "http://feelation.com/");
|
||||
super(LogManager.getLogger(), "http://feelation.com/","featured-img","img");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3,6 +3,7 @@ package net.Broken;
|
||||
import net.Broken.Commandes.Over18.*;
|
||||
import net.Broken.Outils.CommandParser;
|
||||
import net.Broken.Outils.DayListener;
|
||||
import net.Broken.Outils.FindContentOnWebPage;
|
||||
import net.Broken.Outils.Redirection;
|
||||
import net.Broken.Commandes.*;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
@ -40,6 +41,7 @@ public class MainBot {
|
||||
static Logger logger = LogManager.getLogger();
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// FindContentOnWebPage.doYourJob("http://les400culs.com/2347-2/","featured-img","img");
|
||||
logger.trace("trace");
|
||||
logger.debug("debug");
|
||||
logger.info("info");
|
||||
|
41
src/net/Broken/Outils/FindContentOnWebPage.java
Normal file
41
src/net/Broken/Outils/FindContentOnWebPage.java
Normal file
@ -0,0 +1,41 @@
|
||||
package net.Broken.Outils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
* Created by sebastien on 10/05/17.
|
||||
*/
|
||||
public class FindContentOnWebPage {
|
||||
public static String doYourJob(String url, String divClass, String htmlType) throws IOException {
|
||||
String source = getUrlSource(url);
|
||||
int divIndex = source.indexOf(divClass);
|
||||
String sub = source.substring(divIndex);
|
||||
// System.out.println(sub);
|
||||
sub = sub.replace(divClass,"");
|
||||
sub = sub.substring(sub.indexOf(htmlType));
|
||||
sub = sub.substring(sub.indexOf("src"));
|
||||
sub = sub.replace("src=\"","");
|
||||
String[] split = sub.split("\"");
|
||||
// System.out.println(split[0]);
|
||||
return split[0];
|
||||
}
|
||||
|
||||
private static String getUrlSource(String url) throws IOException {
|
||||
URL urlC = new URL(url);
|
||||
URLConnection yc = urlC.openConnection();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||
yc.getInputStream(), "UTF-8"));
|
||||
String inputLine;
|
||||
StringBuilder a = new StringBuilder();
|
||||
while ((inputLine = in.readLine()) != null)
|
||||
a.append(inputLine);
|
||||
in.close();
|
||||
|
||||
return a.toString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user