2017-12-12 01:06:58 +01:00
|
|
|
package net.Broken;
|
|
|
|
|
2018-02-15 02:02:35 +01:00
|
|
|
import net.Broken.Tools.Command.CommandLoader;
|
2018-02-16 15:02:53 +01:00
|
|
|
import net.Broken.Tools.DayListener.DayListener;
|
2018-02-16 15:37:10 +01:00
|
|
|
import net.Broken.Tools.DayListener.Listeners.DailyMadame;
|
2018-02-16 15:02:53 +01:00
|
|
|
import net.Broken.Tools.DayListener.Listeners.ResetSpam;
|
2017-12-12 01:06:58 +01:00
|
|
|
import net.dv8tion.jda.core.AccountType;
|
|
|
|
import net.dv8tion.jda.core.JDA;
|
|
|
|
import net.dv8tion.jda.core.JDABuilder;
|
|
|
|
import net.dv8tion.jda.core.OnlineStatus;
|
|
|
|
import net.dv8tion.jda.core.entities.Game;
|
|
|
|
import net.dv8tion.jda.core.entities.Guild;
|
|
|
|
import net.dv8tion.jda.core.entities.Member;
|
|
|
|
import net.dv8tion.jda.core.exceptions.RateLimitedException;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
|
|
|
import javax.security.auth.login.LoginException;
|
|
|
|
import java.util.List;
|
|
|
|
|
2018-02-28 17:59:09 +01:00
|
|
|
|
2017-12-12 01:06:58 +01:00
|
|
|
public class Init {
|
|
|
|
static private Logger logger = LogManager.getLogger();
|
|
|
|
|
2018-02-28 17:59:09 +01:00
|
|
|
/**
|
|
|
|
* Initialize all bot functionality
|
|
|
|
* @param token bot user token
|
|
|
|
* @param dev dev Mode or not
|
|
|
|
* @return JDA object
|
|
|
|
*/
|
2017-12-12 01:06:58 +01:00
|
|
|
static JDA initBot(String token, boolean dev){
|
|
|
|
boolean okInit;
|
|
|
|
JDA jda = null;
|
2017-12-22 19:20:26 +01:00
|
|
|
logger.debug("-------------------INITIALISATION-------------------");
|
2017-12-12 01:06:58 +01:00
|
|
|
|
|
|
|
//Bot démarrer sans token
|
|
|
|
if (token == null) {
|
|
|
|
logger.fatal("Veuilliez indiquer le token du bot en argument...");
|
|
|
|
okInit=false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Token présent
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
logger.info("Connection au serveur...");
|
|
|
|
//connection au bot
|
|
|
|
jda = new JDABuilder(AccountType.BOT).addEventListener(new BotListener()).setToken(token).setBulkDeleteSplittingEnabled(false).buildBlocking();
|
2018-01-12 12:50:12 +01:00
|
|
|
MainBot.jda = jda;
|
2017-12-12 01:06:58 +01:00
|
|
|
jda.setAutoReconnect(true);
|
|
|
|
jda.addEventListener();
|
|
|
|
|
|
|
|
/*************************************
|
|
|
|
* Definition des commande *
|
|
|
|
*************************************/
|
|
|
|
jda.getPresence().setGame(Game.of("Statut: Loading..."));
|
|
|
|
jda.getTextChannels().forEach(textChannel -> textChannel.sendTyping().queue());
|
2018-01-12 12:50:12 +01:00
|
|
|
CommandLoader.load();
|
2017-12-12 01:06:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
//On recupere le l'id serveur
|
|
|
|
Guild serveur = jda.getGuilds().get(0);
|
|
|
|
|
|
|
|
//on recupere les utilisateur
|
|
|
|
List<Member> utilisateurCo = serveur.getMembers();
|
|
|
|
|
2017-12-22 19:20:26 +01:00
|
|
|
logger.info("Utilisatieur connecté: "+utilisateurCo.size());
|
2017-12-12 01:06:58 +01:00
|
|
|
for (Member anUtilisateurCo : utilisateurCo)
|
|
|
|
{
|
|
|
|
if (anUtilisateurCo.getOnlineStatus().equals(OnlineStatus.ONLINE))
|
2017-12-22 19:20:26 +01:00
|
|
|
logger.debug("\t*" + anUtilisateurCo.getEffectiveName());
|
2017-12-12 01:06:58 +01:00
|
|
|
}
|
|
|
|
|
2017-12-22 19:20:26 +01:00
|
|
|
logger.debug("Utilisatieur absent: ");
|
2017-12-12 01:06:58 +01:00
|
|
|
for (Member anUtilisateurCo : utilisateurCo)
|
|
|
|
{
|
|
|
|
if (anUtilisateurCo.getOnlineStatus().equals(OnlineStatus.DO_NOT_DISTURB))
|
2017-12-22 19:20:26 +01:00
|
|
|
logger.debug("\t*" + anUtilisateurCo.getEffectiveName());
|
2017-12-12 01:06:58 +01:00
|
|
|
}
|
|
|
|
|
2017-12-22 19:20:26 +01:00
|
|
|
logger.debug("Utilisatieur hors ligne: ");
|
2017-12-12 01:06:58 +01:00
|
|
|
for (Member anUtilisateurCo : utilisateurCo)
|
|
|
|
{
|
|
|
|
if (anUtilisateurCo.getOnlineStatus().equals(OnlineStatus.OFFLINE))
|
2017-12-22 19:20:26 +01:00
|
|
|
logger.debug("\t*" + anUtilisateurCo.getEffectiveName());
|
2017-12-12 01:06:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MainBot.ModoTimer modotimer = new MainBot.ModoTimer();
|
|
|
|
modotimer.start();
|
2018-02-16 15:02:53 +01:00
|
|
|
|
|
|
|
DayListener dayListener = DayListener.getInstance();
|
|
|
|
dayListener.addListener(new ResetSpam());
|
2018-02-16 15:37:10 +01:00
|
|
|
dayListener.addListener(new DailyMadame());
|
2017-12-12 01:06:58 +01:00
|
|
|
dayListener.start();
|
2018-02-16 15:02:53 +01:00
|
|
|
|
2017-12-22 19:20:26 +01:00
|
|
|
logger.debug("-----------------FIN INITIALISATION-----------------");
|
2017-12-12 01:06:58 +01:00
|
|
|
|
|
|
|
jda.getPresence().setGame(Game.of("Statut: Ok!"));
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (LoginException | InterruptedException | RateLimitedException e)
|
|
|
|
{
|
|
|
|
logger.catching(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return jda;
|
|
|
|
}
|
|
|
|
}
|