Bypass Tumblr safe mode

This commit is contained in:
Sebastien 2018-05-14 09:28:16 +02:00
parent 535e78ba08
commit 63e1d6c216
4 changed files with 54 additions and 12 deletions

View File

@ -1,28 +1,31 @@
package net.Broken.Commands.Over18; package net.Broken.Commands.Over18;
import net.Broken.Commande; import net.Broken.Commande;
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;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.io.IOException;
/** /**
* TODO Remove this * TODO Remove this
*/ */
public class SM implements Commande { public class SM implements Commande {
Logger logger = LogManager.getLogger(); Logger logger = LogManager.getLogger();
public String HELP="T'es sérieux la?";
@Override @Override
public void action(String[] args, MessageReceivedEvent event) { public void action(String[] args, MessageReceivedEvent event) {
Redirection redirect= new Redirection(); Redirection redirect= new Redirection();
event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: SM n'est plus disponible pour le moment. Pour plus d'info: https://lc.cx/cbSw :warning: ").queue(); try {
// try { String redirectUrl = redirect.get("https://bonjourfetish.tumblr.com/random");
// event.getTextChannel().sendMessage(redirect.get("https://bonjourfetish.tumblr.com/random")).queue(); String img = FindContentOnWebPage.doYourJob(redirectUrl, "article-picture center", "img");
// } catch (IOException e) { event.getTextChannel().sendMessage(img).queue();
// logger.warn("Erreur de redirection."); } catch (IOException e) {
// event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur de redirection (5 essais), Réessayez__**:warning: ").queue(); logger.warn("Erreur de redirection.");
// } event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur de redirection (5 essais), Réessayez__**:warning: ").queue();
}
} }

View File

@ -2,26 +2,61 @@ package net.Broken.Commands.Over18;
import net.Broken.Commande; import net.Broken.Commande;
import net.Broken.Tools.EmbedMessageUtils; 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;
import org.apache.logging.log4j.Logger;
import java.io.IOException; import java.io.IOException;
public class Suicide implements Commande{ public class Suicide implements Commande{
private String redirectUrl = "https://suicidegirlsandhopefuls.tumblr.com/random"; private Logger logger = LogManager.getLogger();
@Override @Override
public void action(String[] args, MessageReceivedEvent event) { public void action(String[] args, MessageReceivedEvent event) {
Redirection redirection = new Redirection(); Redirection redirection = new Redirection();
String base = "http://suicidegirls.tumblr.com";
String redirectUrl = null;
try { try {
event.getTextChannel().sendMessage(redirection.get(redirectUrl)).queue();
Boolean success = false;
int tryCount = 0;
while(!success && tryCount < 10 ){
redirectUrl = redirection.get(base + "/random");
String img;
try{
img = FindContentOnWebPage.doYourJob(redirectUrl, "post photo_nav_caption", "img");
event.getTextChannel().sendMessage(img).queue();
success = true;
}catch (StringIndexOutOfBoundsException | IOException e){
logger.debug("Photo_nav not found try photoset");
try {
String mid = FindContentOnWebPage.doYourJob(redirectUrl, "html_photoset", "iframe");
img = FindContentOnWebPage.doYourJob(base + mid, "photoset_row", "img");
event.getTextChannel().sendMessage(img).queue();
success = true;
} catch (StringIndexOutOfBoundsException | IOException e1) {
logger.debug("Nothing found, assume it's a comment.");
}
}
tryCount ++;
}
} catch (IOException e) { } catch (IOException e) {
LogManager.getLogger().catching(e); logger.catching(e);
event.getTextChannel().sendMessage(EmbedMessageUtils.getInternalError()).queue();
} }
} }
@Override @Override

View File

@ -16,6 +16,7 @@ public class FindContentOnWebPage {
* @throws IOException * @throws IOException
*/ */
public static String doYourJob(String url, String divClass, String htmlType) throws IOException { public static String doYourJob(String url, String divClass, String htmlType) throws IOException {
// System.out.println(url);
String source = getSourceUrl(url); String source = getSourceUrl(url);
int divIndex = source.indexOf(divClass); int divIndex = source.indexOf(divClass);
String sub = source.substring(divIndex); String sub = source.substring(divIndex);
@ -38,6 +39,7 @@ public class FindContentOnWebPage {
public static String getSourceUrl(String url) throws IOException { public static String getSourceUrl(String url) throws IOException {
URL urlC = new URL(url); URL urlC = new URL(url);
URLConnection yc = urlC.openConnection(); URLConnection yc = urlC.openConnection();
yc.setRequestProperty("User-Agent","Googlebot");
BufferedReader in = new BufferedReader(new InputStreamReader( BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream(), "UTF-8")); yc.getInputStream(), "UTF-8"));
String inputLine; String inputLine;

View File

@ -22,7 +22,9 @@ public class Redirection {
* @throws IOException * @throws IOException
*/ */
public String get(String urlString) throws IOException { public String get(String urlString) throws IOException {
System.setProperty("http.agent","Googlebot");
URLConnection con = new URL(urlString).openConnection(); URLConnection con = new URL(urlString).openConnection();
con.setRequestProperty("User-Agent","Googlebot");
//System.out.println( "orignal url: " + con.getURL() ); //System.out.println( "orignal url: " + con.getURL() );
con.connect(); con.connect();
//System.out.println( "connected url: " + con.getURL() ); //System.out.println( "connected url: " + con.getURL() );