diff --git a/Libraries/JDA-3.0/JDA-3.0.BETA_75-javadoc.jar b/Libraries/JDA-3.0/JDA-3.0.BETA_75-javadoc.jar deleted file mode 100644 index b00b5fa..0000000 Binary files a/Libraries/JDA-3.0/JDA-3.0.BETA_75-javadoc.jar and /dev/null differ diff --git a/Libraries/JDA-3.0/JDA-3.0.BETA_98-sources.jar b/Libraries/JDA-3.0/JDA-3.0.BETA_98-sources.jar deleted file mode 100644 index caf48d5..0000000 Binary files a/Libraries/JDA-3.0/JDA-3.0.BETA_98-sources.jar and /dev/null differ diff --git a/Libraries/JDA-3.0/JDA-3.0.BETA_98-withDependencies.jar b/Libraries/JDA-3.0/JDA-3.0.BETA_98-withDependencies.jar deleted file mode 100644 index 89d5972..0000000 Binary files a/Libraries/JDA-3.0/JDA-3.0.BETA_98-withDependencies.jar and /dev/null differ diff --git a/Libraries/JDA3.3.0/JDA-3.3.0_260-javadoc.jar b/Libraries/JDA3.3.0/JDA-3.3.0_260-javadoc.jar new file mode 100644 index 0000000..a9adda0 Binary files /dev/null and b/Libraries/JDA3.3.0/JDA-3.3.0_260-javadoc.jar differ diff --git a/Libraries/JDA3.3.0/JDA-3.3.0_260-sources.jar b/Libraries/JDA3.3.0/JDA-3.3.0_260-sources.jar new file mode 100644 index 0000000..80dc6f4 Binary files /dev/null and b/Libraries/JDA3.3.0/JDA-3.3.0_260-sources.jar differ diff --git a/Libraries/JDA3.3.0/JDA-3.3.0_260-withDependencies.jar b/Libraries/JDA3.3.0/JDA-3.3.0_260-withDependencies.jar new file mode 100644 index 0000000..7ba370b Binary files /dev/null and b/Libraries/JDA3.3.0/JDA-3.3.0_260-withDependencies.jar differ diff --git a/src/net/Broken/BotListener.java b/src/net/Broken/BotListener.java index 44dd9aa..b3ceda5 100644 --- a/src/net/Broken/BotListener.java +++ b/src/net/Broken/BotListener.java @@ -6,7 +6,10 @@ import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.events.ReadyEvent; +import net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent; +import net.dv8tion.jda.core.events.guild.voice.GuildVoiceJoinEvent; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; +import net.dv8tion.jda.core.events.message.priv.PrivateMessageReceivedEvent; import net.dv8tion.jda.core.hooks.ListenerAdapter; import net.dv8tion.jda.core.managers.GuildManager; import org.apache.logging.log4j.LogManager; @@ -33,51 +36,54 @@ public class BotListener extends ListenerAdapter { @Override public void onMessageReceived(MessageReceivedEvent event) { // ----------------------Test pour eviter eco de commande------------------------- - try - { +// try +// { - if (event.getMessage().getContent().startsWith("//") && event.getMessage().getAuthor().getId() != event.getJDA().getSelfUser().getId()) { + if (event.getMessage().getContent().startsWith("//") && !event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) { //On a detecter que c'etait une commande //System.out.println(event.getMessage().getContent()); - MainBot.handleCommand(MainBot.parser.parse(event.getMessage().getContent(), event)); + logger.debug("ok"); } - else if (event.getMessage().getAuthor().getId() != event.getJDA().getSelfUser().getId() && !event.getTextChannel().getName().equals("le_dongeon")) + else if (!event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) { - //N'est pas une commande - Guild serveur=event.getGuild(); - GuildManager guildManager = serveur.getManager(); - Member user = event.getMember(); - - if(!event.isFromType(ChannelType.PRIVATE)) + if(!event.getTextChannel().getName().equals("le_dongeon")) { - // appel de la methode d'analyse de message de "Moderateur" - if(!event.getAuthor().getName().equals("Aethex") && event.getMessage().getContent().length()>0) { + Guild serveur=event.getGuild(); + GuildManager guildManager = serveur.getManager(); + Member user = event.getMember(); - if (modo.analyse(user, serveur, guildManager, event) == 1) { - antispam.extermine(user, serveur, guildManager,true, event); + if(!event.isFromType(ChannelType.PRIVATE)) + { + // appel de la methode d'analyse de message de "Moderateur" + if(!event.getAuthor().getName().equals("Aethex") && event.getMessage().getContent().length()>0) { + + if (modo.analyse(user, serveur, guildManager, event) == 1) { + antispam.extermine(user, serveur, guildManager,true, event); + } } + else if(event.getMessage().getContent().length() == 0) + logger.error("Image detected, ignoring it."); } - else if(event.getMessage().getContent().length() == 0) - logger.error("Image detected, ignoring it."); } + } - }catch (Exception e) - { - if (e.getMessage()==null) { - logger.error("NullPointerException"); - } else { - logger.error(e.getMessage()); - } - } +// }catch (Exception e) +// { +// if (e.getMessage()==null) { +// logger.error("NullPointerException"); +// } else { +// logger.error(e.getMessage()); +// } +// } } } diff --git a/src/net/Broken/Commandes/Help.java b/src/net/Broken/Commandes/Help.java index e739fe5..988ba2d 100644 --- a/src/net/Broken/Commandes/Help.java +++ b/src/net/Broken/Commandes/Help.java @@ -2,7 +2,10 @@ package net.Broken.Commandes; import net.Broken.Commande; import net.Broken.MainBot; +import net.Broken.Outils.PrivateMessage; +import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; +import net.dv8tion.jda.core.exceptions.RateLimitedException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -26,14 +29,22 @@ public class Help implements Commande { //System.out.println(argsString); if (MainBot.commandes.containsKey(argsString)) { - logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getMember().getEffectiveName()); - event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n\n"+MainBot.commandes.get(argsString).help(args)).queue(); + logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getAuthor().getName()); + if(!event.isFromType(ChannelType.PRIVATE)) + event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n\n"+MainBot.commandes.get(argsString).help(args)).queue(); + else{ + PrivateMessage.send(event.getAuthor(), MainBot.commandes.get(argsString).help(args),logger); + } } else { - event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:warning: **__Commande Inconue!__** :warning:").queue(); + if(!event.isFromType(ChannelType.PRIVATE)) + event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:warning: **__Commande Inconue!__** :warning:").queue(); + else{ + PrivateMessage.send(event.getAuthor(),":warning: **__Commande Inconue!__** :warning:",logger); + } logger.info("Commande Inconnue!"); } } @@ -44,8 +55,10 @@ public class Help implements Commande { txt=txt+"\n//"+e.getKey(); } - event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right:\t**__commandes envoyées par message privé__**").queue(); - event.getAuthor().getPrivateChannel().sendMessage("Commandes du bot:\n\n```"+txt+"```\n\nUtilise `//help ` pour plus de détails.").queue(); + if(!event.isFromType(ChannelType.PRIVATE)) + event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right:\t**__commandes envoyées par message privé__**").queue(); + PrivateMessage.send(event.getAuthor(),"Commandes du bot:\n\n```"+txt+"```\n\nUtilise `//help ` pour plus de détails.",logger); + diff --git a/src/net/Broken/Commandes/NumberedCommande.java b/src/net/Broken/Commandes/NumberedCommande.java index aac8a71..3e206c1 100644 --- a/src/net/Broken/Commandes/NumberedCommande.java +++ b/src/net/Broken/Commandes/NumberedCommande.java @@ -130,7 +130,7 @@ public abstract class NumberedCommande implements Commande{ @Override public String help(String[] args) { - return"`//"+this.toString().toLowerCase() +"update\n:arrow_right: *Rafraichi la liste des images.*\n`//"+this.toString().toLowerCase()+" get `\n:arrow_right: *Affiche l'image portant le numero donné*"; + return"`//"+this.toString().toLowerCase() +" update`\n:arrow_right: *Rafraichi la liste des images.*\n`//"+this.toString().toLowerCase()+" get `\n:arrow_right: *Affiche l'image portant le numero donné*"; } @Override diff --git a/src/net/Broken/Commandes/Over18/SM.java b/src/net/Broken/Commandes/Over18/SM.java index cee2f55..052d6e0 100644 --- a/src/net/Broken/Commandes/Over18/SM.java +++ b/src/net/Broken/Commandes/Over18/SM.java @@ -24,12 +24,13 @@ public class SM implements Commande { Redirection redirect= new Redirection(); if(event.getTextChannel().getName().equals("nsfw-over18")) { - try { - event.getTextChannel().sendMessage(redirect.get("https://bonjourfetish.tumblr.com/random")).queue(); - } catch (IOException e) { - logger.warn("Erreur de redirection."); - event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur de redirection (5 essais), Réessayez__**:warning: ").queue(); - } + 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 { +// event.getTextChannel().sendMessage(redirect.get("https://bonjourfetish.tumblr.com/random")).queue(); +// } catch (IOException e) { +// logger.warn("Erreur de redirection."); +// event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n:warning: **__Erreur de redirection (5 essais), Réessayez__**:warning: ").queue(); +// } } else { diff --git a/src/net/Broken/Commandes/PingCommande.java b/src/net/Broken/Commandes/PingCommande.java index 2d7f53f..aa3c892 100644 --- a/src/net/Broken/Commandes/PingCommande.java +++ b/src/net/Broken/Commandes/PingCommande.java @@ -28,7 +28,7 @@ public class PingCommande implements Commande { event.getPrivateChannel().sendMessage(":arrow_right: Pong! `"+((Timestamp.from(Instant.now()).getTime()-receivedTime))+"ms`").queue(); else event.getTextChannel().sendMessage(event.getAuthor().getAsMention()+"\n:arrow_right: Pong! `"+((Timestamp.from(Instant.now()).getTime()-receivedTime))+"ms`").queue(); - LogManager.getLogger().info("pong"); + LogManager.getLogger().debug("pong"); } @Override diff --git a/src/net/Broken/MainBot.java b/src/net/Broken/MainBot.java index 1c9f6b5..0005eb6 100644 --- a/src/net/Broken/MainBot.java +++ b/src/net/Broken/MainBot.java @@ -41,14 +41,11 @@ 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"); logger.warn("warn"); logger.error("error"); - Stop stopTh=new Stop(); - stopTh.start(); /**************************** * Initialisation * ****************************/ @@ -66,11 +63,9 @@ public class MainBot { logger.info("Connection au serveur..."); //connection au bot - jda = new JDABuilder(AccountType.BOT).addListener(new BotListener()).setToken(args[0]).setBulkDeleteSplittingEnabled(false).buildBlocking(); + jda = new JDABuilder(AccountType.BOT).addEventListener(new BotListener()).setToken(args[0]).setBulkDeleteSplittingEnabled(false).buildBlocking(); jda.setAutoReconnect(true); jda.addEventListener(); - jda.addEventListener(); - okInit=true; } @@ -154,10 +149,13 @@ public class MainBot { public static void handleCommand(CommandParser.CommandContainer cmd) { //On verifie que la commande existe + if (commandes.containsKey(cmd.commande)) { + logger.debug("ok"); if(cmd.event.isFromType(ChannelType.PRIVATE) && privateUsableCommand.contains(commandes.get(cmd.commande).getClass())) { + commandes.get(cmd.commande).action(cmd.args, cmd.event); commandes.get(cmd.commande).executed(true, cmd.event); } @@ -214,33 +212,4 @@ public class MainBot { } } - - public static class Stop extends Thread - { - - @Override - public void run() { - Scanner scanner = new Scanner(System.in); - String txtEntré = ""; - while(!txtEntré.equals("o")&&!txtEntré.equals("O")) - { - - while (!txtEntré.equals("stop")) - { - txtEntré = scanner.nextLine(); - } - - logger.warn("Etes-vous sur de vouloir arréter le Bot? (o/n)"); - txtEntré = scanner.nextLine(); - - if(txtEntré.equals("n")||txtEntré.equals("N")) - { - logger.info("Arret du Bot annulé."); - } - } - Runtime.getRuntime().exit(0); - - - } - } } diff --git a/src/net/Broken/Outils/CommandParser.java b/src/net/Broken/Outils/CommandParser.java index 287f307..b4e7dfa 100644 --- a/src/net/Broken/Outils/CommandParser.java +++ b/src/net/Broken/Outils/CommandParser.java @@ -31,7 +31,9 @@ public class CommandParser { } - logger.info("Auteur: "+e.getMember().getEffectiveName()+", Commande: "+commande+", args: "+ Arrays.toString(args)); + + logger.info("Auteur: "+e.getAuthor().getName()+", Commande: "+commande+", args: "+ Arrays.toString(args)); + return new CommandContainer(brut, sansTete, splitSansTete, commande, args, e); //On Save toute les info dans le container } diff --git a/src/net/Broken/Outils/PrivateMessage.java b/src/net/Broken/Outils/PrivateMessage.java new file mode 100644 index 0000000..26aa9bb --- /dev/null +++ b/src/net/Broken/Outils/PrivateMessage.java @@ -0,0 +1,22 @@ +package net.Broken.Outils; + +import net.dv8tion.jda.core.entities.PrivateChannel; +import net.dv8tion.jda.core.entities.User; +import net.dv8tion.jda.core.exceptions.RateLimitedException; +import org.apache.logging.log4j.Logger; + +/** + * Created by seb65 on 04/09/2017. + */ +public class PrivateMessage { + public static void send(User user, String message, Logger logger){ + if(!user.hasPrivateChannel()){ + logger.debug("Create Private Chanel"); + + user.openPrivateChannel().complete(); + + } + user.getJDA().getPrivateChannels().get(0).sendMessage(message).queue(); + + } +}