Change Advertisement dection method #16
This commit is contained in:
parent
8b9c9e9ed7
commit
aa392d8cf2
@ -1,6 +1,8 @@
|
|||||||
package net.Broken.Commands.Over18;
|
package net.Broken.Commands.Over18;
|
||||||
|
|
||||||
import net.Broken.Commande;
|
import net.Broken.Commande;
|
||||||
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
|
import net.Broken.Tools.FindContentOnWebPage;
|
||||||
import net.Broken.Tools.Redirection;
|
import net.Broken.Tools.Redirection;
|
||||||
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -14,6 +16,7 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class Madame implements Commande{
|
public class Madame implements Commande{
|
||||||
Logger logger = LogManager.getLogger();
|
Logger logger = LogManager.getLogger();
|
||||||
|
MessageReceivedEvent event;
|
||||||
public String HELP="T'es sérieux la?";
|
public String HELP="T'es sérieux la?";
|
||||||
@Override
|
@Override
|
||||||
public boolean called(String[] args, MessageReceivedEvent event) {
|
public boolean called(String[] args, MessageReceivedEvent event) {
|
||||||
@ -22,6 +25,7 @@ public class Madame implements Commande{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action(String[] args, MessageReceivedEvent event) {
|
public void action(String[] args, MessageReceivedEvent event) {
|
||||||
|
this.event = event;
|
||||||
|
|
||||||
if(event.getTextChannel().isNSFW()) {
|
if(event.getTextChannel().isNSFW()) {
|
||||||
Redirection redirect = new Redirection();
|
Redirection redirect = new Redirection();
|
||||||
@ -33,11 +37,12 @@ public class Madame implements Commande{
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
String url = redirect.get("http://dites.bonjourmadame.fr/random");
|
String url = redirect.get("http://dites.bonjourmadame.fr/random");
|
||||||
if((url.contains("club") && (url.contains("rejoindre") || url.contains("rejoignez"))) || (url.contains("samedi") && url.contains("dimanche"))){
|
logger.debug("URL: "+url);
|
||||||
|
if(scanPageForTipeee(url)){
|
||||||
logger.debug("Advertisement detected! Retry! ("+url+")");
|
logger.debug("Advertisement detected! Retry! ("+url+")");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
event.getTextChannel().sendMessage(redirect.get("http://dites.bonjourmadame.fr/random")).queue();
|
event.getTextChannel().sendMessage(url).queue();
|
||||||
success=true;
|
success=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +57,9 @@ public class Madame implements Commande{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}catch (StringIndexOutOfBoundsException e){
|
||||||
|
logger.catching(e);
|
||||||
|
event.getTextChannel().sendMessage(EmbedMessageUtils.getInternalError()).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,4 +86,37 @@ public class Madame implements Commande{
|
|||||||
public boolean isAdminCmd() {
|
public boolean isAdminCmd() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isAdvertisementUrl(String url){
|
||||||
|
//Scan url
|
||||||
|
if(url.toLowerCase().contains("club") && (url.toLowerCase().contains("rejoindre") || url.toLowerCase().contains("rejoignez"))){
|
||||||
|
logger.debug("Advertisement detected with \"club\" and \"rejoidre\" or \"rejoignez\"");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if(url.contains("samedi") && url.contains("dimanche")){
|
||||||
|
logger.debug("Advertisement detected with \"samedi\" and \"dimanche\"");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean scanPageForTipeee(String url) throws StringIndexOutOfBoundsException, IOException{
|
||||||
|
String content = FindContentOnWebPage.getUrlSource(url);
|
||||||
|
String imgClickLink = content.substring(content.indexOf("photo post"));
|
||||||
|
imgClickLink = imgClickLink.substring(imgClickLink.indexOf("<a"));
|
||||||
|
imgClickLink = imgClickLink.substring(imgClickLink.indexOf("\""));
|
||||||
|
imgClickLink = imgClickLink.substring(0, imgClickLink.indexOf("\">"));
|
||||||
|
imgClickLink = imgClickLink.substring(1);
|
||||||
|
logger.debug("Image link: " + imgClickLink);
|
||||||
|
if(imgClickLink.contains("tipeee")){
|
||||||
|
logger.debug("Detect tipeee link! ");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public class FindContentOnWebPage {
|
|||||||
return split[0];
|
return split[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getUrlSource(String url) throws IOException {
|
public static String getUrlSource(String url) throws IOException {
|
||||||
URL urlC = new URL(url);
|
URL urlC = new URL(url);
|
||||||
URLConnection yc = urlC.openConnection();
|
URLConnection yc = urlC.openConnection();
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(
|
BufferedReader in = new BufferedReader(new InputStreamReader(
|
||||||
|
Loading…
Reference in New Issue
Block a user