From e0b5199e72f16fbb76ea0aed73e4f9101756ed45 Mon Sep 17 00:00:00 2001 From: BrokenFire Date: Fri, 23 Feb 2018 19:17:23 +0100 Subject: [PATCH] Change help storage methods #10 --- src/main/java/net/Broken/Commande.java | 2 +- src/main/java/net/Broken/Commands/Cat.java | 10 +- .../java/net/Broken/Commands/DayTrigger.java | 30 +---- src/main/java/net/Broken/Commands/Flush.java | 10 +- src/main/java/net/Broken/Commands/Help.java | 33 +++-- src/main/java/net/Broken/Commands/Move.java | 100 ++++++-------- src/main/java/net/Broken/Commands/Music.java | 11 +- .../java/net/Broken/Commands/Over18/Ass.java | 5 + .../net/Broken/Commands/Over18/Boobs.java | 5 + .../net/Broken/Commands/Over18/Madame.java | 10 +- .../java/net/Broken/Commands/Over18/Pipe.java | 5 + .../java/net/Broken/Commands/Over18/SM.java | 10 +- src/main/java/net/Broken/Commands/Ping.java | 14 +- src/main/java/net/Broken/Commands/Spam.java | 127 ++++++------------ .../java/net/Broken/Commands/SpamInfo.java | 11 +- src/main/java/net/Broken/MainBot.java | 42 ++++-- .../Tools/Command/NumberedCommande.java | 5 - .../net/Broken/Tools/EmbedMessageUtils.java | 51 +++++-- .../java/net/Broken/Tools/MessageTimeOut.java | 2 +- .../java/net/Broken/Tools/ResourceLoader.java | 5 +- .../Tools/UserManager/UserRegister.java | 8 +- src/main/resources/Help/Cat/fr/main.md | 4 + src/main/resources/Help/Default/fr/main.md | 2 + src/main/resources/Help/Flush/fr/main.md | 3 + src/main/resources/Help/Move/fr/main.md | 2 + src/main/resources/Help/Music/fr/main.md | 26 ++++ src/main/resources/Help/Ping/fr/main.md | 2 + src/main/resources/Help/Spam/fr/main.md | 8 ++ src/main/resources/Help/SpamInfo/fr/main.md | 2 + 29 files changed, 293 insertions(+), 252 deletions(-) create mode 100644 src/main/resources/Help/Cat/fr/main.md create mode 100644 src/main/resources/Help/Default/fr/main.md create mode 100644 src/main/resources/Help/Flush/fr/main.md create mode 100644 src/main/resources/Help/Move/fr/main.md create mode 100644 src/main/resources/Help/Music/fr/main.md create mode 100644 src/main/resources/Help/Ping/fr/main.md create mode 100644 src/main/resources/Help/Spam/fr/main.md create mode 100644 src/main/resources/Help/SpamInfo/fr/main.md diff --git a/src/main/java/net/Broken/Commande.java b/src/main/java/net/Broken/Commande.java index 4c3c48d..f77c709 100644 --- a/src/main/java/net/Broken/Commande.java +++ b/src/main/java/net/Broken/Commande.java @@ -9,9 +9,9 @@ import net.dv8tion.jda.core.events.message.MessageReceivedEvent; public interface Commande { boolean called(String[] args, MessageReceivedEvent event); void action(String[] args, MessageReceivedEvent event); - String help(String[] args); void executed(boolean success, MessageReceivedEvent event); boolean isPrivateUsable(); + boolean isAdminCmd(); } diff --git a/src/main/java/net/Broken/Commands/Cat.java b/src/main/java/net/Broken/Commands/Cat.java index d8c4b57..f49037e 100644 --- a/src/main/java/net/Broken/Commands/Cat.java +++ b/src/main/java/net/Broken/Commands/Cat.java @@ -63,11 +63,6 @@ public class Cat implements Commande { } - @Override - public String help(String[] args) { - return ""; - } - @Override public void executed(boolean success, MessageReceivedEvent event) { @@ -77,4 +72,9 @@ public class Cat implements Commande { public boolean isPrivateUsable() { return false; } + + @Override + public boolean isAdminCmd() { + return false; + } } diff --git a/src/main/java/net/Broken/Commands/DayTrigger.java b/src/main/java/net/Broken/Commands/DayTrigger.java index b2cdd3b..9133892 100644 --- a/src/main/java/net/Broken/Commands/DayTrigger.java +++ b/src/main/java/net/Broken/Commands/DayTrigger.java @@ -26,33 +26,8 @@ public class DayTrigger implements Commande{ @Override public void action(String[] args, MessageReceivedEvent event) { - if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){ - DayListener.getInstance().trigger(); event.getMessage().delete().queue(); - } - else{ - logger.warn("Not admin! DENY!"); - if(!event.isFromType(ChannelType.PRIVATE)){ - Message message = event.getTextChannel().sendMessage(EmbedMessageUtils.getError("Vous n'avez pas l'autorisation de faire ça!")).complete(); - List messages = new ArrayList(){{ - add(message); - add(event.getMessage()); - }}; - new MessageTimeOut(messages, MainBot.messageTimeOut).start(); - } - else{ - PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getError("Vous n'avez pas l'autorisation de faire ça!"),logger); - } - - - } - - } - - @Override - public String help(String[] args) { - return null; } @Override @@ -64,4 +39,9 @@ public class DayTrigger implements Commande{ public boolean isPrivateUsable() { return true; } + + @Override + public boolean isAdminCmd() { + return true; + } } diff --git a/src/main/java/net/Broken/Commands/Flush.java b/src/main/java/net/Broken/Commands/Flush.java index 9336deb..5a0d8f0 100644 --- a/src/main/java/net/Broken/Commands/Flush.java +++ b/src/main/java/net/Broken/Commands/Flush.java @@ -54,11 +54,6 @@ public class Flush implements Commande{ } } - @Override - public String help(String[] args) { - return "`//flush `\n:arrow_right:\t*Efface les n derniers messages (Max = 100)*"; - } - @Override public void executed(boolean success, MessageReceivedEvent event) { @@ -68,4 +63,9 @@ public class Flush implements Commande{ public boolean isPrivateUsable() { return false; } + + @Override + public boolean isAdminCmd() { + return false; + } } diff --git a/src/main/java/net/Broken/Commands/Help.java b/src/main/java/net/Broken/Commands/Help.java index 6890891..63defce 100644 --- a/src/main/java/net/Broken/Commands/Help.java +++ b/src/main/java/net/Broken/Commands/Help.java @@ -8,11 +8,13 @@ import net.Broken.Tools.PrivateMessage; import net.dv8tion.jda.core.EmbedBuilder; import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.entities.Message; +import net.dv8tion.jda.core.entities.MessageEmbed; import net.dv8tion.jda.core.events.message.MessageReceivedEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.awt.*; +import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -36,26 +38,39 @@ public class Help implements Commande { if (MainBot.commandes.containsKey(argsString)) { logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getAuthor().getName()); + MessageEmbed messageEmbed; + try { + messageEmbed = EmbedMessageUtils.getHelp(argsString); + } catch (FileNotFoundException e) { + try { + messageEmbed = EmbedMessageUtils.getHelp("Default"); + } catch (FileNotFoundException e1) { + messageEmbed = EmbedMessageUtils.getInternalError(); + logger.catching(e1); + } + } if(!event.isFromType(ChannelType.PRIVATE)) { - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getHelp(argsString, MainBot.commandes.get(argsString).help(args))).complete(); + Message rest = event.getTextChannel().sendMessage(messageEmbed).complete(); if(args.length<=1) { + Message finalRest = rest; List messages = new ArrayList(){{ - add(rest); + add(finalRest); add(event.getMessage()); }}; new MessageTimeOut(messages,MainBot.messageTimeOut).start(); } else if(!args[1].toLowerCase().equals("true")){ + Message finalRest1 = rest; List messages = new ArrayList(){{ - add(rest); + add(finalRest1); add(event.getMessage()); }}; new MessageTimeOut(messages,MainBot.messageTimeOut).start(); } } else{ - PrivateMessage.send(event.getAuthor(), EmbedMessageUtils.getHelp(argsString, MainBot.commandes.get(argsString).help(args)),logger); + PrivateMessage.send(event.getAuthor(), messageEmbed,logger); } @@ -102,11 +117,6 @@ public class Help implements Commande { } - @Override - public String help(String[] args) { - return null; - } - @Override public void executed(boolean success, MessageReceivedEvent event) { @@ -116,4 +126,9 @@ public class Help implements Commande { public boolean isPrivateUsable() { return true; } + + @Override + public boolean isAdminCmd() { + return false; + } } diff --git a/src/main/java/net/Broken/Commands/Move.java b/src/main/java/net/Broken/Commands/Move.java index 7852569..78d2e2a 100644 --- a/src/main/java/net/Broken/Commands/Move.java +++ b/src/main/java/net/Broken/Commands/Move.java @@ -113,70 +113,57 @@ public class Move implements Commande { user = serveur.getMember(userL.get(0)); serveur=event.getGuild(); logger.info("Tentative de déplacement de "+user.getEffectiveName()+" vers "+roleL+" par l'utilisateur "+event.getAuthor().getName()); - if(event.getMember().hasPermission(Permission.ADMINISTRATOR)) - { - logger.info("Autorisation suffisante, deplacement autorisé"); - logger.debug("Utilisateur trouvée"); - try { - boolean erreur=this.exc(user,roleL,true,serveur,serveur.getManager()); - if(erreur) - { - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Verifier le rôle cible. ")).complete(); - List messages = new ArrayList(){{ - add(rest); - add(event.getMessage()); - }}; - new MessageTimeOut(messages,MainBot.messageTimeOut).start(); - } - else - { - StringBuilder roleStr = new StringBuilder(""); - boolean first = true; - for( Role role : roleL) - { - if (!first) { - roleStr.append(", "); - - } - else - first = false; - roleStr.append("__"); - roleStr.append(role.getName()); - roleStr.append("__"); - } - - - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveOk("Déplacement de "+user.getEffectiveName()+" vers "+roleStr.toString()+" reussi.")).complete(); - List messages = new ArrayList(){{ - add(rest); - add(event.getMessage()); - }}; - new MessageTimeOut(messages,MainBot.messageTimeOut).start(); - } - }catch (HierarchyException e){ - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).complete(); + logger.info("Autorisation suffisante, deplacement autorisé"); + logger.debug("Utilisateur trouvée"); + try { + boolean erreur=this.exc(user,roleL,true,serveur,serveur.getManager()); + if(erreur) + { + Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Verifier le rôle cible. ")).complete(); List messages = new ArrayList(){{ add(rest); add(event.getMessage()); }}; new MessageTimeOut(messages,MainBot.messageTimeOut).start(); - logger.error("Hierarchy error, please move bot's role on top!"); } + else + { + StringBuilder roleStr = new StringBuilder(""); + boolean first = true; + for( Role role : roleL) + { + if (!first) { + roleStr.append(", "); + + } + else + first = false; + roleStr.append("__"); + roleStr.append(role.getName()); + roleStr.append("__"); + } - } - else - { - logger.warn("Autorisation insuffisante, deplacement refusé"); - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Vous n'avez pas l'autorisation de faicre ça!")).complete(); + Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveOk("Déplacement de "+user.getEffectiveName()+" vers "+roleStr.toString()+" reussi.")).complete(); + List messages = new ArrayList(){{ + add(rest); + add(event.getMessage()); + }}; + new MessageTimeOut(messages,MainBot.messageTimeOut).start(); + } + }catch (HierarchyException e){ + Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Impossible de déplacer un "+user.getRoles().get(0).getAsMention())).complete(); List messages = new ArrayList(){{ add(rest); add(event.getMessage()); }}; new MessageTimeOut(messages,MainBot.messageTimeOut).start(); - + logger.error("Hierarchy error, please move bot's role on top!"); } + + + } } @@ -201,16 +188,6 @@ public class Move implements Commande { - } - - /** - * - * @param args - * @return - */ - @Override - public String help(String[] args) { - return HELP; } /** @@ -227,4 +204,9 @@ public class Move implements Commande { public boolean isPrivateUsable() { return false; } + + @Override + public boolean isAdminCmd() { + return true; + } } diff --git a/src/main/java/net/Broken/Commands/Music.java b/src/main/java/net/Broken/Commands/Music.java index 2debb67..e9d2307 100644 --- a/src/main/java/net/Broken/Commands/Music.java +++ b/src/main/java/net/Broken/Commands/Music.java @@ -157,12 +157,6 @@ public class Music implements Commande { } } - @Override - public String help(String[] args) { - return "`//music play `\n:arrow_right:\t*Let's dance! Deffinit le chat vocal à utiliser.*\n\n`//music pause`\n:arrow_right:\t*Mise en pause de la piste en cours.*\n\n`//music resume`\n:arrow_right:\t*Reprise de la lecture de la piste en cours.*\n\n`//music next`\n:arrow_right:\t*Change le piste en cours.*\n\n`//music stop`\n:arrow_right:\t*Arrête la piste en cours.*\n\n`//music info`\n:arrow_right:\t*Affiche les infos de la piste en cours.*\n\n`//music flush`\n:arrow_right:\t*Supprime la playlist en cours.*\n\n`//music list`\n:arrow_right:\t*Affiche la playlist en cours.*\n\n`//music add(Next) `\n:arrow_right:\t*Ajoute l'url à la playlist en cour.*"; - - } - @Override public void executed(boolean success, MessageReceivedEvent event) { @@ -173,6 +167,11 @@ public class Music implements Commande { return false; } + @Override + public boolean isAdminCmd() { + return false; + } + public AudioM getAudioManager(){ return audio; } diff --git a/src/main/java/net/Broken/Commands/Over18/Ass.java b/src/main/java/net/Broken/Commands/Over18/Ass.java index a3ede7a..c866a5d 100644 --- a/src/main/java/net/Broken/Commands/Over18/Ass.java +++ b/src/main/java/net/Broken/Commands/Over18/Ass.java @@ -21,4 +21,9 @@ public class Ass extends NumberedCommande { public boolean isPrivateUsable() { return false; } + + @Override + public boolean isAdminCmd() { + return false; + } } diff --git a/src/main/java/net/Broken/Commands/Over18/Boobs.java b/src/main/java/net/Broken/Commands/Over18/Boobs.java index d2bafd1..3f69bce 100644 --- a/src/main/java/net/Broken/Commands/Over18/Boobs.java +++ b/src/main/java/net/Broken/Commands/Over18/Boobs.java @@ -20,4 +20,9 @@ public class Boobs extends NumberedCommande { public boolean isPrivateUsable() { return false; } + + @Override + public boolean isAdminCmd() { + return false; + } } diff --git a/src/main/java/net/Broken/Commands/Over18/Madame.java b/src/main/java/net/Broken/Commands/Over18/Madame.java index 4fd08a2..5442a5a 100644 --- a/src/main/java/net/Broken/Commands/Over18/Madame.java +++ b/src/main/java/net/Broken/Commands/Over18/Madame.java @@ -56,11 +56,6 @@ public class Madame implements Commande{ } } - @Override - public String help(String[] args) { - return HELP; - } - @Override public void executed(boolean success, MessageReceivedEvent event) { @@ -70,4 +65,9 @@ public class Madame implements Commande{ public boolean isPrivateUsable() { return false; } + + @Override + public boolean isAdminCmd() { + return false; + } } diff --git a/src/main/java/net/Broken/Commands/Over18/Pipe.java b/src/main/java/net/Broken/Commands/Over18/Pipe.java index 009d826..3cd69ee 100644 --- a/src/main/java/net/Broken/Commands/Over18/Pipe.java +++ b/src/main/java/net/Broken/Commands/Over18/Pipe.java @@ -54,4 +54,9 @@ public class Pipe extends NumberedCommande { public boolean isPrivateUsable() { return false; } + + @Override + public boolean isAdminCmd() { + return false; + } } diff --git a/src/main/java/net/Broken/Commands/Over18/SM.java b/src/main/java/net/Broken/Commands/Over18/SM.java index 98982b6..73a6429 100644 --- a/src/main/java/net/Broken/Commands/Over18/SM.java +++ b/src/main/java/net/Broken/Commands/Over18/SM.java @@ -40,11 +40,6 @@ public class SM implements Commande { } - @Override - public String help(String[] args) { - return HELP; - } - @Override public void executed(boolean success, MessageReceivedEvent event) { @@ -54,4 +49,9 @@ public class SM implements Commande { public boolean isPrivateUsable() { return false; } + + @Override + public boolean isAdminCmd() { + return false; + } } diff --git a/src/main/java/net/Broken/Commands/Ping.java b/src/main/java/net/Broken/Commands/Ping.java index cab02e5..710a1c3 100644 --- a/src/main/java/net/Broken/Commands/Ping.java +++ b/src/main/java/net/Broken/Commands/Ping.java @@ -16,9 +16,6 @@ import java.util.List; * Created by seb65 on 19/10/2016. */ public class Ping implements Commande { - - - private String HELP = "`//ping` \n :arrow_right:\t*Renvoi le ping du bot*"; @Override public boolean called(String[] args, MessageReceivedEvent event) { return true; @@ -41,12 +38,6 @@ public class Ping implements Commande { LogManager.getLogger().debug("pong"); } - @Override - public String help(String[] args) { - - return HELP; - } - @Override public void executed(boolean success, MessageReceivedEvent event) { @@ -58,4 +49,9 @@ public class Ping implements Commande { public boolean isPrivateUsable() { return true; } + + @Override + public boolean isAdminCmd() { + return false; + } } diff --git a/src/main/java/net/Broken/Commands/Spam.java b/src/main/java/net/Broken/Commands/Spam.java index 4d4fa6a..c4f198d 100644 --- a/src/main/java/net/Broken/Commands/Spam.java +++ b/src/main/java/net/Broken/Commands/Spam.java @@ -76,14 +76,6 @@ public class Spam implements Commande { } - - - @Override - public String help(String[] args) - { - return "`//spam extermine <@utilisateur> `\n:arrow_right:\t*Punir un spammeur.*\n\n`//spam pardon <@utilisateur>`\n:arrow_right:\t*Annuler la punition d'un utilisateur.*\n\n`//spam reset <@utilisateur>`\n:arrow_right:\t*RAZ du multiplicateur d'un utilisateur.*"; - } - @Override public void executed(boolean success, MessageReceivedEvent event) { @@ -95,6 +87,11 @@ public class Spam implements Commande { return false; } + @Override + public boolean isAdminCmd() { + return true; + } + public void pardon(MessageReceivedEvent event, String[] args){ Guild serveur = event.getGuild(); @@ -125,30 +122,12 @@ public class Spam implements Commande { else { Member user = serveur.getMember(userL.get(0)); logger.info("Tentative de pardon de " + user.getEffectiveName() + " par l'utilisateur " + event.getMember().getEffectiveName()); - /**************************** - * c'est un big dady * + /**************************** + * virif si en spammer * ****************************/ - - if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){ - logger.info("Autorisation suffisante, pardon autorisé"); - - /**************************** - * virif si en spammer * - ****************************/ - if (MainBot.spamUtils.containsKey(user.getUser())) { - if (MainBot.spamUtils.get(user.getUser()).isOnSpam()) { - MainBot.spamUtils.get(user.getUser()).setOnSpam(false); - } else { - logger.warn("Utilisateur pas en spam."); - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError(":arrow_right: Utilisateur non spammeur.","pardon")).complete(); - List messages = new ArrayList(){{ - add(rest); - add(event.getMessage()); - }}; - new MessageTimeOut(messages,MainBot.messageTimeOut).start(); - } - - + if (MainBot.spamUtils.containsKey(user.getUser())) { + if (MainBot.spamUtils.get(user.getUser()).isOnSpam()) { + MainBot.spamUtils.get(user.getUser()).setOnSpam(false); } else { logger.warn("Utilisateur pas en spam."); Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError(":arrow_right: Utilisateur non spammeur.","pardon")).complete(); @@ -159,9 +138,10 @@ public class Spam implements Commande { new MessageTimeOut(messages,MainBot.messageTimeOut).start(); } + } else { - logger.warn("Autorisation insuffisante, pardon refusé"); - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Vous n'avez pas l'autorisation de faire ça!")).complete(); + logger.warn("Utilisateur pas en spam."); + Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError(":arrow_right: Utilisateur non spammeur.","pardon")).complete(); List messages = new ArrayList(){{ add(rest); add(event.getMessage()); @@ -210,48 +190,36 @@ public class Spam implements Commande { Guild serveur = event.getGuild(); Member user = serveur.getMember(userL.get(0)); logger.info("Tentative d'extermination de "+user.getEffectiveName()+" par l'utilisateur "+event.getAuthor().getName()); + + + String multiStr =args[2]; + + /**************************** - * c'est un big dady * + * virif pas deja en spammer * ****************************/ - - if(event.getMember().hasPermission(Permission.ADMINISTRATOR)) + if(MainBot.spamUtils.containsKey(user.getUser())) { - logger.info("Autorisation suffisante, extermination autorisé"); - String multiStr =args[2]; - - - /**************************** - * virif pas deja en spammer * - ****************************/ - if(MainBot.spamUtils.containsKey(user.getUser())) - { - if(!MainBot.spamUtils.get(user.getUser()).isOnSpam()) - { - this.goSpam(user,multiStr,serveur,event); - } - else - { - logger.warn("Utilisateur deja en spam."); - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Utilisateur déjà spammeur.","extermine")).complete(); - } - - - } - else + if(!MainBot.spamUtils.get(user.getUser()).isOnSpam()) { this.goSpam(user,multiStr,serveur,event); } + else + { + logger.warn("Utilisateur deja en spam."); + Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Utilisateur déjà spammeur.","extermine")).complete(); + List messages = new ArrayList(){{ + add(rest); + add(event.getMessage()); + }}; + new MessageTimeOut(messages,MainBot.messageTimeOut).start(); + } + } else { - logger.warn("Autorisation insuffisante, extermination refusé"); - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Vous n'avez pas l'autorisation de faire ça!")).complete(); - List messages = new ArrayList(){{ - add(rest); - add(event.getMessage()); - }}; - new MessageTimeOut(messages,MainBot.messageTimeOut).start(); + this.goSpam(user,multiStr,serveur,event); } } @@ -300,36 +268,23 @@ public class Spam implements Commande { else { Member user = serveur.getMember(userL.get(0)); logger.info("Tentative de reset de " + user.getEffectiveName() + " par l'utilisateur " + event.getMember().getEffectiveName()); + + /**************************** - * c'est un big dady * + * verif utilisteur trouver * ****************************/ - - if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){ - logger.info("Autorisation suffisante, pardon autorisé"); - /**************************** - * verif utilisteur trouver * - ****************************/ - if (MainBot.spamUtils.containsKey(user.getUser())) { - logger.info("Reset du multiplicateur de " + user.getEffectiveName() + " réussi"); - Message rest = event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n *Le multiplcicateur de " + user.getEffectiveName() + " a été remit a zéro.*").complete(); - List messages = new ArrayList(){{ - add(rest); - add(event.getMessage()); - }}; - new MessageTimeOut(messages,MainBot.messageTimeOut).start(); - MainBot.spamUtils.remove(user.getUser()); - - } - } else { - logger.warn("Autorisation insuffisante, reset refusé"); - Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Vous n'avez pas l'autorisation de faire ça!")).complete(); + if (MainBot.spamUtils.containsKey(user.getUser())) { + logger.info("Reset du multiplicateur de " + user.getEffectiveName() + " réussi"); + Message rest = event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n *Le multiplcicateur de " + user.getEffectiveName() + " a été remit a zéro.*").complete(); List messages = new ArrayList(){{ add(rest); add(event.getMessage()); }}; new MessageTimeOut(messages,MainBot.messageTimeOut).start(); + MainBot.spamUtils.remove(user.getUser()); } + } } else diff --git a/src/main/java/net/Broken/Commands/SpamInfo.java b/src/main/java/net/Broken/Commands/SpamInfo.java index 9755702..d43f954 100644 --- a/src/main/java/net/Broken/Commands/SpamInfo.java +++ b/src/main/java/net/Broken/Commands/SpamInfo.java @@ -27,7 +27,6 @@ public class SpamInfo implements Commande{ private HashMap threadHashMap = new HashMap<>(); Logger logger = LogManager.getLogger(); - private String HELP="`//spaminfo <@utilisateur> `\n:arrow_right:\t*Affiche les infos relatives aux punitions contre le spam de l'utilisateur mentionnée (de l'auteur si pas de mention)*"; @Override public boolean called(String[] args, MessageReceivedEvent event) { return false; @@ -93,11 +92,6 @@ public class SpamInfo implements Commande{ - } - - @Override - public String help(String[] args) { - return HELP; } @Override @@ -110,6 +104,11 @@ public class SpamInfo implements Commande{ return true; } + @Override + public boolean isAdminCmd() { + return false; + } + public String formatSecond(int second){ long days = TimeUnit.SECONDS.toDays(second); second -= TimeUnit.DAYS.toSeconds(days); diff --git a/src/main/java/net/Broken/MainBot.java b/src/main/java/net/Broken/MainBot.java index c39e068..e44286b 100644 --- a/src/main/java/net/Broken/MainBot.java +++ b/src/main/java/net/Broken/MainBot.java @@ -3,9 +3,12 @@ package net.Broken; import net.Broken.RestApi.ApiCommandLoader; import net.Broken.Tools.Command.CommandParser; import net.Broken.Tools.EmbedMessageUtils; +import net.Broken.Tools.MessageTimeOut; +import net.Broken.Tools.PrivateMessage; import net.Broken.Tools.UserManager.UserRegister; import net.Broken.Tools.UserSpamUtils; import net.dv8tion.jda.core.JDA; +import net.dv8tion.jda.core.Permission; import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.entities.Message; import net.dv8tion.jda.core.entities.User; @@ -20,6 +23,7 @@ import org.springframework.stereotype.Controller; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; /** * Created by seb65 on 19/10/2016. @@ -95,19 +99,37 @@ public class MainBot { if (commandes.containsKey(cmd.commande)) { - if(cmd.event.isFromType(ChannelType.PRIVATE) && commandes.get(cmd.commande).isPrivateUsable()) - { + Commande cmdObj = commandes.get(cmd.commande); + if(!cmdObj.isAdminCmd() || cmd.event.getMember().hasPermission(Permission.ADMINISTRATOR)){ + if(cmd.event.isFromType(ChannelType.PRIVATE) && commandes.get(cmd.commande).isPrivateUsable()) + { - commandes.get(cmd.commande).action(cmd.args, cmd.event); - commandes.get(cmd.commande).executed(true, cmd.event); + commandes.get(cmd.commande).action(cmd.args, cmd.event); + commandes.get(cmd.commande).executed(true, cmd.event); + } + else if (!cmd.event.isFromType(ChannelType.PRIVATE)) + { + commandes.get(cmd.commande).action(cmd.args, cmd.event); + commandes.get(cmd.commande).executed(true, cmd.event); + } + else + cmd.event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate()).queue(); } - else if (!cmd.event.isFromType(ChannelType.PRIVATE)) - { - commandes.get(cmd.commande).action(cmd.args, cmd.event); - commandes.get(cmd.commande).executed(true, cmd.event); + else{ + if(cmd.event.isFromType(ChannelType.PRIVATE)){ + PrivateMessage.send(cmd.event.getAuthor(),EmbedMessageUtils.getUnautorized(), logger); + } + else{ + Message msg = cmd.event.getTextChannel().sendMessage(EmbedMessageUtils.getUnautorized()).complete(); + List messages = new ArrayList(){{ + add(msg); + add(cmd.event.getMessage()); + }}; + new MessageTimeOut(messages, messageTimeOut).start(); + } } - else - cmd.event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate()).queue(); + + } diff --git a/src/main/java/net/Broken/Tools/Command/NumberedCommande.java b/src/main/java/net/Broken/Tools/Command/NumberedCommande.java index cd65172..c932bfd 100644 --- a/src/main/java/net/Broken/Tools/Command/NumberedCommande.java +++ b/src/main/java/net/Broken/Tools/Command/NumberedCommande.java @@ -128,11 +128,6 @@ 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é*"; - } - @Override public void executed(boolean success, MessageReceivedEvent event) { diff --git a/src/main/java/net/Broken/Tools/EmbedMessageUtils.java b/src/main/java/net/Broken/Tools/EmbedMessageUtils.java index 15ceaf7..b2e9a97 100644 --- a/src/main/java/net/Broken/Tools/EmbedMessageUtils.java +++ b/src/main/java/net/Broken/Tools/EmbedMessageUtils.java @@ -6,29 +6,35 @@ import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.MessageEmbed; import java.awt.*; +import java.io.FileNotFoundException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; public class EmbedMessageUtils { public static MessageEmbed getUnknowCommand() { - return new EmbedBuilder().setTitle(":warning: Commande inconnue! :warning:").setDescription(":arrow_right: Utilisez `//help` pour voirs les commandes disponible.").setColor(Color.orange).build(); + return new EmbedBuilder().setTitle(":warning: Commande inconnue! :warning:").setDescription(":arrow_right: Utilisez `//help` pour voirs les commandes disponible.").setColor(Color.orange).setFooter("bot.seb6596.ovh", MainBot.jda.getSelfUser().getAvatarUrl()).build(); } public static MessageEmbed getError(String message) { - return new EmbedBuilder().setTitle(":warning: Error! :warning:").setColor(Color.red).setDescription(message).build(); + EmbedBuilder temp = new EmbedBuilder().setTitle(":warning: Error! :warning:").setColor(Color.red).setDescription(message); + return buildStandar(temp); + } public static MessageEmbed getNoPrivate(){ - return new EmbedBuilder().setTitle(":warning: Commande non disponible en privé! :warning:").setDescription(":arrow_right: Utilisez `//help` pour voirs les commandes disponible.").setColor(Color.red).build(); - + EmbedBuilder temp = new EmbedBuilder().setTitle(":warning: Commande non disponible en privé! :warning:").setDescription(":arrow_right: Utilisez `//help` pour voirs les commandes disponible.").setColor(Color.red); + return buildStandar(temp); } public static MessageEmbed getMusicError(String message){ - return new EmbedBuilder().setTitle(":warning: Musique Error :warning:").setDescription(":arrow_right: "+message).setFooter("'//help music' pour plus d'info",null).setColor(Color.red).build(); + return new EmbedBuilder().setTitle(":warning: Musique Error :warning:").setDescription(":arrow_right: "+message).setFooter("'//help music' pour plus d'info",null).setColor(Color.red).setFooter("bot.seb6596.ovh", MainBot.jda.getSelfUser().getAvatarUrl()).build(); } public static MessageEmbed getMusicOk(String message) { - return new EmbedBuilder().setTitle(":loud_sound: Music :loud_sound:").setDescription(message).setColor(Color.green).setFooter("'//help music' pour plus d'info ", null).build(); + EmbedBuilder temp = new EmbedBuilder().setTitle(":loud_sound: Music :loud_sound:").setDescription(message).setColor(Color.green); + return buildStandar(temp); } public static MessageEmbed getSpamExtermine(Member autor, int multi) { @@ -39,20 +45,25 @@ public class EmbedMessageUtils { return new EmbedBuilder().setTitle(":mute: Spam Hunter :mute:").setDescription(autor.getAsMention() + " est de retour, fais gaffe!\nJe te surveille!").setImage("https://media.giphy.com/media/3o7TKwBctlv08kY08M/giphy.gif").setFooter("Spam info disponible via '//spaminfo' en privé", null).setColor(Color.orange).build(); } - public static MessageEmbed getHelp(String name, String helpMessage) { - return new EmbedBuilder().setTitle(":question: " + name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase() + " :question: ").setDescription("\n" + helpMessage).setColor(Color.green).build(); + + public static MessageEmbed getHelp(String command) throws FileNotFoundException { + String name = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase(); + String message = new ResourceLoader().getFile("Help/"+name+"/fr/main.md"); + EmbedBuilder temp = new EmbedBuilder().setTitle(":question: " + command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase() + " :question: ").setDescription(message).setColor(Color.green); + return buildStandar(temp); } public static MessageEmbed getMoveError(String message) { - return new EmbedBuilder().setTitle(":warning: Move Error :warning: ").setDescription(message).setColor(Color.red).setFooter("'//help move' pour plus d'info ", null).build(); + return new EmbedBuilder().setTitle(":warning: Move Error :warning: ").setDescription(message).setColor(Color.red).setFooter("'//help move' pour plus d'info ", MainBot.jda.getSelfUser().getAvatarUrl()).build(); } public static MessageEmbed getMoveOk(String message) { - return new EmbedBuilder().setTitle(":arrow_left: Move :arrow_right: ").setDescription(message).setColor(Color.green).setFooter("'//help move' pour plus d'info ", null).build(); + EmbedBuilder temp = new EmbedBuilder().setTitle(":arrow_left: Move :arrow_right: ").setDescription(message).setColor(Color.green); + return buildStandar(temp); } public static MessageEmbed getSpamError(String message) { - return new EmbedBuilder().setTitle(":warning: Spam Error :warning: ").setDescription(message).setColor(Color.red).setFooter("'//help spam' pour plus d'info ", null).build(); + return new EmbedBuilder().setTitle(":warning: Spam Error :warning: ").setDescription(message).setColor(Color.red).setFooter("'//help spam' pour plus d'info ", MainBot.jda.getSelfUser().getAvatarUrl()).build(); } public static MessageEmbed getSpamError(String message, String sub) { @@ -60,11 +71,12 @@ public class EmbedMessageUtils { } public static MessageEmbed getSpamInfo(String message) { - return new EmbedBuilder().setTitle(":hourglass: Spam Info :hourglass:").setDescription(message).setColor(Color.green).setFooter("'//help spaminfo' pour plus d'info ", null).build(); + EmbedBuilder temp = new EmbedBuilder().setTitle(":hourglass: Spam Info :hourglass:").setDescription(message).setColor(Color.green); + return buildStandar(temp); } public static MessageEmbed getFlushError(String message) { - return new EmbedBuilder().setTitle(":warning: Flush Error :warning: ").setDescription(message).setColor(Color.red).setFooter("'//help flush' pour plus d'info ", null).build(); + return new EmbedBuilder().setTitle(":warning: Flush Error :warning: ").setDescription(message).setColor(Color.red).setFooter("'//help flush' pour plus d'info ", MainBot.jda.getSelfUser().getAvatarUrl()).build(); } @@ -72,6 +84,19 @@ public class EmbedMessageUtils { return new EmbedBuilder().setTitle(":pencil: Web Registration :pencil:").setDescription(message).setColor(Color.green).setFooter("bot.seb6596.ovh", MainBot.jda.getSelfUser().getAvatarUrl()).build(); } + public static MessageEmbed getInternalError(){ + return getError("Je... Je... je ne me sent pas bien... :thermometer_face: \nContactez vite mon developeur!"); + } + + public static MessageEmbed buildStandar(EmbedBuilder embedBuilder){ + String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM")); + String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm")); + return embedBuilder.setFooter("bot.seb6596.ovh | "+date+" at "+time, MainBot.jda.getSelfUser().getAvatarUrl()).setThumbnail(MainBot.jda.getSelfUser().getAvatarUrl()).build(); + } + + public static MessageEmbed getUnautorized(){ + return getError("Vous n'avez pas l'autorisation de faire ça!"); + } } \ No newline at end of file diff --git a/src/main/java/net/Broken/Tools/MessageTimeOut.java b/src/main/java/net/Broken/Tools/MessageTimeOut.java index aa100eb..3286df0 100644 --- a/src/main/java/net/Broken/Tools/MessageTimeOut.java +++ b/src/main/java/net/Broken/Tools/MessageTimeOut.java @@ -26,10 +26,10 @@ public class MessageTimeOut extends Thread{ e.printStackTrace(); } } + logger.debug("Timiout! Deleting message!"); for(Message aMessage: messages) { try { - logger.debug(aMessage.getContent()); aMessage.delete().queue(); }catch (ErrorResponseException e){ logger.warn("Unknown Message"); diff --git a/src/main/java/net/Broken/Tools/ResourceLoader.java b/src/main/java/net/Broken/Tools/ResourceLoader.java index 02eea97..bb6e59e 100644 --- a/src/main/java/net/Broken/Tools/ResourceLoader.java +++ b/src/main/java/net/Broken/Tools/ResourceLoader.java @@ -4,6 +4,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Scanner; @@ -14,13 +15,15 @@ public class ResourceLoader { private Logger logger = LogManager.getLogger(); - public String getFile(String fileName) { + public String getFile(String fileName) throws FileNotFoundException { StringBuilder result = new StringBuilder(""); //Get file from resources folder ClassLoader classLoader = getClass().getClassLoader(); InputStream file = classLoader.getResourceAsStream(fileName); + if(file == null) + throw new FileNotFoundException(); try (Scanner scanner = new Scanner(file, "UTF-8")) { diff --git a/src/main/java/net/Broken/Tools/UserManager/UserRegister.java b/src/main/java/net/Broken/Tools/UserManager/UserRegister.java index d91265e..f3f583a 100644 --- a/src/main/java/net/Broken/Tools/UserManager/UserRegister.java +++ b/src/main/java/net/Broken/Tools/UserManager/UserRegister.java @@ -18,6 +18,7 @@ import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceS import org.springframework.context.annotation.Bean; import org.springframework.security.crypto.password.PasswordEncoder; +import java.io.FileNotFoundException; import java.security.SecureRandom; import java.util.List; import java.util.UUID; @@ -86,7 +87,12 @@ public class UserRegister { pendingUserEntity = pendingUserRepository.save(pendingUserEntity); } - String message = new ResourceLoader().getFile("MessagesTemplates/RegisterMessage.md"); + String message = null; + try { + message = new ResourceLoader().getFile("MessagesTemplates/RegisterMessage.md"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } message = message.replace("%code",token); diff --git a/src/main/resources/Help/Cat/fr/main.md b/src/main/resources/Help/Cat/fr/main.md new file mode 100644 index 0000000..b502b18 --- /dev/null +++ b/src/main/resources/Help/Cat/fr/main.md @@ -0,0 +1,4 @@ + +Ho! Regarde! Un chat! +Mais il est different à chaque fois en plus! +C'est trop cute! :cat: \ No newline at end of file diff --git a/src/main/resources/Help/Default/fr/main.md b/src/main/resources/Help/Default/fr/main.md new file mode 100644 index 0000000..8488ca7 --- /dev/null +++ b/src/main/resources/Help/Default/fr/main.md @@ -0,0 +1,2 @@ +L'aide pour cette commande n'est pas encore disponible ! +Pour contribué: https://github.com/BrokenFire/BrokenDiscordBot \ No newline at end of file diff --git a/src/main/resources/Help/Flush/fr/main.md b/src/main/resources/Help/Flush/fr/main.md new file mode 100644 index 0000000..cf12dbc --- /dev/null +++ b/src/main/resources/Help/Flush/fr/main.md @@ -0,0 +1,3 @@ + +`//flush ` +:arrow_right: *Efface les n derniers messages (Max = 100)* \ No newline at end of file diff --git a/src/main/resources/Help/Move/fr/main.md b/src/main/resources/Help/Move/fr/main.md new file mode 100644 index 0000000..2018738 --- /dev/null +++ b/src/main/resources/Help/Move/fr/main.md @@ -0,0 +1,2 @@ +`//move <@utilisateur> <@rôleCible>` +:arrow_right: *Deplacement d'un utilisateur vers un rôle cible, attention à bien faire des montions.* \ No newline at end of file diff --git a/src/main/resources/Help/Music/fr/main.md b/src/main/resources/Help/Music/fr/main.md new file mode 100644 index 0000000..11382e9 --- /dev/null +++ b/src/main/resources/Help/Music/fr/main.md @@ -0,0 +1,26 @@ +`//music play ` +:arrow_right: *Let's dance! Deffinit le chat vocal à utiliser.* + +`//music pause` +:arrow_right: *Mise en pause de la piste en cours.* + +`//music resume` +:arrow_right: *Reprise de la lecture de la piste en cours.* + +`//music next` +:arrow_right: *Change le piste en cours.* + +`//music stop` +:arrow_right: *Arrête la piste en cours.* + +`//music info` +:arrow_right: *Affiche les infos de la piste en cours.* + +`//music flush` +:arrow_right: *Supprime la playlist en cours.* + +`//music list` +:arrow_right: *Affiche la playlist en cours.* + +`//music add(Next) ` +:arrow_right: *Ajoute l'url à la playlist en cour.* \ No newline at end of file diff --git a/src/main/resources/Help/Ping/fr/main.md b/src/main/resources/Help/Ping/fr/main.md new file mode 100644 index 0000000..9735eea --- /dev/null +++ b/src/main/resources/Help/Ping/fr/main.md @@ -0,0 +1,2 @@ +`//ping` + :arrow_right: *Renvoi le ping du bot* \ No newline at end of file diff --git a/src/main/resources/Help/Spam/fr/main.md b/src/main/resources/Help/Spam/fr/main.md new file mode 100644 index 0000000..9a72ad0 --- /dev/null +++ b/src/main/resources/Help/Spam/fr/main.md @@ -0,0 +1,8 @@ +`//spam extermine <@utilisateur> ` +:arrow_right: *Punir un spammeur.* + +`//spam pardon <@utilisateur>` +:arrow_right: *Annuler la punition d'un utilisateur.* + +`//spam reset <@utilisateur>` +:arrow_right: *RAZ du multiplicateur d'un utilisateur.* diff --git a/src/main/resources/Help/SpamInfo/fr/main.md b/src/main/resources/Help/SpamInfo/fr/main.md new file mode 100644 index 0000000..3ce369b --- /dev/null +++ b/src/main/resources/Help/SpamInfo/fr/main.md @@ -0,0 +1,2 @@ +`//spaminfo <@utilisateur> ` +:arrow_right: *Affiche les infos relatives aux punitions contre le spam de l'utilisateur mentionnée (de l'auteur si pas de mention)* \ No newline at end of file