Add NoDev to reduce loading time on dev mode

This commit is contained in:
Sebastien 2018-09-10 13:02:27 +03:00
parent 5106dd5098
commit fe13b286dc
10 changed files with 75 additions and 19 deletions

View File

@ -1,11 +1,14 @@
package net.Broken.Commands.Over18;
import net.Broken.Tools.Command.NoDev;
import net.Broken.Tools.Command.NumberedCommande;
import org.apache.logging.log4j.LogManager;
/**
* Ass command, return random picture from les400culs.com
*/
@NoDev()
public class Ass extends NumberedCommande {
public Ass() {

View File

@ -1,11 +1,13 @@
package net.Broken.Commands.Over18;
import net.Broken.Tools.Command.NoDev;
import net.Broken.Tools.Command.NumberedCommande;
import org.apache.logging.log4j.LogManager;
/**
* Boobs command, return random picture from lesaintdesseins.fr
*/
@NoDev()
public class Boobs extends NumberedCommande {
public Boobs() {

View File

@ -1,11 +1,13 @@
package net.Broken.Commands.Over18;
import net.Broken.Tools.Command.NoDev;
import net.Broken.Tools.Command.NumberedCommande;
import org.apache.logging.log4j.LogManager;
/**
* Ass command, return random picture from feelation.com
*/
@NoDev()
public class Pipe extends NumberedCommande {
public Pipe() {
super(LogManager.getLogger(), "http://feelation.com/","featured-img","img");

View File

@ -7,7 +7,9 @@ import net.Broken.Tools.MessageTimeOut;
import net.Broken.Tools.PrivateMessage;
import net.Broken.Tools.UserSpamUtils;
import net.Broken.audio.Youtube.YoutubeTools;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Member;
@ -40,6 +42,7 @@ public class MainBot {
public static HashMap<Member, UserSpamUtils> spamUtils = new HashMap<>();
public static JDA jda;
public static boolean ready = false;
public static boolean dev = false;
@ -56,7 +59,7 @@ public class MainBot {
logger.info("--------------Starting Bot-------------");
logger.info("=======================================");
boolean dev = false;
String token = null;
int i = 0;
for(String aArg: args){
@ -70,8 +73,10 @@ public class MainBot {
i++;
}
token = System.getenv("TOKEN");
jda = Init.initJda(token, dev);
ConfigurableApplicationContext ctx = SpringApplication.run(MainBot.class, args);
if(jda == null) {
System.exit(SpringApplication.exit(ctx, (ExitCodeGenerator) () -> {
@ -89,6 +94,8 @@ public class MainBot {
}
/**

View File

@ -35,13 +35,22 @@ public class CommandLoader {
String reference = command.getName();
String[] splited = reference.split("\\.");
String name = splited[splited.length - 1].toLowerCase();
if (!command.isAnnotationPresent(Ignore.class)) {
logger.info("..." + name);
if (!command.isAnnotationPresent(NoDev.class) && MainBot.dev) {
try {
MainBot.commandes.put(name, command.newInstance());
} catch (InstantiationException | IllegalAccessException e) {
logger.error("Failed to load " + name + "!");
}
}else{
logger.warn("Command disable in dev mode");
}
} else {
logger.trace("Ignored command: " + name);
}
}
}

View File

@ -0,0 +1,14 @@
package net.Broken.Tools.Command;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Used to disable command on dev mode
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Ignore {
}

View File

@ -0,0 +1,14 @@
package net.Broken.Tools.Command;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Used to disable command on dev mode
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface NoDev {
}

View File

@ -13,6 +13,7 @@ import java.net.URL;
/**
* Abstact class used for all command that need to find the max number of page on a web site.
*/
@Ignore
public abstract class NumberedCommande implements Commande{
private Logger logger = LogManager.getLogger();
private int minNumber = 1;
@ -35,9 +36,9 @@ public abstract class NumberedCommande implements Commande{
this.divClass = divClass;
this.htmlType = htmlType;
try {
logger.info("Checking max...");
logger.debug("Checking max...");
maxNumber = LimitChecker.doYourJob(baseURL, minNumber);
logger.info("New limit is "+maxNumber);
logger.info("Limit is "+maxNumber);
} catch (IOException e) {
logger.catching(e);
}

View File

@ -34,13 +34,13 @@ public class LimitChecker {
huc.setRequestMethod ("GET");
huc.connect ();
result = huc.getResponseCode();
logger.debug("URL: "+u.toString()+" Result: "+result);
logger.trace("URL: "+u.toString()+" Result: "+result);
if(result!=404)
number += 500;
}
number-=400;
result = -1;
logger.debug("First pass: "+number);
logger.trace("First pass: "+number);
while(result != 404 )
{
u = new URL( baseURL+number+"-2/");
@ -48,13 +48,13 @@ public class LimitChecker {
huc.setRequestMethod ("GET");
huc.connect ();
result = huc.getResponseCode();
logger.debug("URL: "+u.toString()+" Result: "+result);
logger.trace("URL: "+u.toString()+" Result: "+result);
if(result!=404)
number += 100;
}
number-=90;
result = -1;
logger.debug("Second pass: "+number);
logger.trace("Second pass: "+number);
while(result != 404 )
{
u = new URL( baseURL+number+"-2/");
@ -62,13 +62,13 @@ public class LimitChecker {
huc.setRequestMethod ("GET");
huc.connect ();
result = huc.getResponseCode();
logger.debug("URL: "+u.toString()+" Result: "+result);
logger.trace("URL: "+u.toString()+" Result: "+result);
if(result!=404)
number += 10;
}
number-=9;
result = -1;
logger.debug("Third pass: "+number);
logger.trace("Third pass: "+number);
while(result != 404 )
{
u = new URL( baseURL+number+"-2/");
@ -76,12 +76,12 @@ public class LimitChecker {
huc.setRequestMethod ("GET");
huc.connect ();
result = huc.getResponseCode();
logger.debug("URL: "+u.toString()+" Result: "+result);
logger.trace("URL: "+u.toString()+" Result: "+result);
if(result!=404)
number += 1;
}
number-=1;
logger.debug("Final pass: "+number);
logger.trace("Final pass: "+number);
return number;

View File

@ -0,0 +1,4 @@
package net.Broken.Tools.UserManager;
public class Oauth {
}