Change help storage methods #10

This commit is contained in:
BrokenFire 2018-02-23 19:17:23 +01:00
parent 68116ebfca
commit e0b5199e72
29 changed files with 293 additions and 252 deletions

View File

@ -9,9 +9,9 @@ import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
public interface Commande { public interface Commande {
boolean called(String[] args, MessageReceivedEvent event); boolean called(String[] args, MessageReceivedEvent event);
void action(String[] args, MessageReceivedEvent event); void action(String[] args, MessageReceivedEvent event);
String help(String[] args);
void executed(boolean success, MessageReceivedEvent event); void executed(boolean success, MessageReceivedEvent event);
boolean isPrivateUsable(); boolean isPrivateUsable();
boolean isAdminCmd();
} }

View File

@ -63,11 +63,6 @@ public class Cat implements Commande {
} }
@Override
public String help(String[] args) {
return "";
}
@Override @Override
public void executed(boolean success, MessageReceivedEvent event) { public void executed(boolean success, MessageReceivedEvent event) {
@ -77,4 +72,9 @@ public class Cat implements Commande {
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return false; return false;
} }
@Override
public boolean isAdminCmd() {
return false;
}
} }

View File

@ -26,33 +26,8 @@ public class DayTrigger implements Commande{
@Override @Override
public void action(String[] args, MessageReceivedEvent event) { public void action(String[] args, MessageReceivedEvent event) {
if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){
DayListener.getInstance().trigger();
event.getMessage().delete().queue(); 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<Message> messages = new ArrayList<Message>(){{
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 @Override
@ -64,4 +39,9 @@ public class DayTrigger implements Commande{
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return true; return true;
} }
@Override
public boolean isAdminCmd() {
return true;
}
} }

View File

@ -54,11 +54,6 @@ public class Flush implements Commande{
} }
} }
@Override
public String help(String[] args) {
return "`//flush <nbr>`\n:arrow_right:\t*Efface les n derniers messages (Max = 100)*";
}
@Override @Override
public void executed(boolean success, MessageReceivedEvent event) { public void executed(boolean success, MessageReceivedEvent event) {
@ -68,4 +63,9 @@ public class Flush implements Commande{
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return false; return false;
} }
@Override
public boolean isAdminCmd() {
return false;
}
} }

View File

@ -8,11 +8,13 @@ import net.Broken.Tools.PrivateMessage;
import net.dv8tion.jda.core.EmbedBuilder; import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Message; import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageEmbed;
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.awt.*; import java.awt.*;
import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -36,26 +38,39 @@ public class Help implements Commande {
if (MainBot.commandes.containsKey(argsString)) if (MainBot.commandes.containsKey(argsString))
{ {
logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getAuthor().getName()); 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)) { 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) if(args.length<=1)
{ {
Message finalRest = rest;
List<Message> messages = new ArrayList<Message>(){{ List<Message> messages = new ArrayList<Message>(){{
add(rest); add(finalRest);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages,MainBot.messageTimeOut).start(); new MessageTimeOut(messages,MainBot.messageTimeOut).start();
} }
else if(!args[1].toLowerCase().equals("true")){ else if(!args[1].toLowerCase().equals("true")){
Message finalRest1 = rest;
List<Message> messages = new ArrayList<Message>(){{ List<Message> messages = new ArrayList<Message>(){{
add(rest); add(finalRest1);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages,MainBot.messageTimeOut).start(); new MessageTimeOut(messages,MainBot.messageTimeOut).start();
} }
} else{ } 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 @Override
public void executed(boolean success, MessageReceivedEvent event) { public void executed(boolean success, MessageReceivedEvent event) {
@ -116,4 +126,9 @@ public class Help implements Commande {
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return true; return true;
} }
@Override
public boolean isAdminCmd() {
return false;
}
} }

View File

@ -113,70 +113,57 @@ public class Move implements Commande {
user = serveur.getMember(userL.get(0)); user = serveur.getMember(userL.get(0));
serveur=event.getGuild(); serveur=event.getGuild();
logger.info("Tentative de déplacement de "+user.getEffectiveName()+" vers "+roleL+" par l'utilisateur "+event.getAuthor().getName()); 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.info("Autorisation suffisante, deplacement autorisé");
logger.debug("Utilisateur trouvée"); logger.debug("Utilisateur trouvée");
try { try {
boolean erreur=this.exc(user,roleL,true,serveur,serveur.getManager()); boolean erreur=this.exc(user,roleL,true,serveur,serveur.getManager());
if(erreur) if(erreur)
{ {
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Verifier le rôle cible. ")).complete(); Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Verifier le rôle cible. ")).complete();
List<Message> messages = new ArrayList<Message>(){{
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<Message> messages = new ArrayList<Message>(){{
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<Message> messages = new ArrayList<Message>(){{ List<Message> messages = new ArrayList<Message>(){{
add(rest); add(rest);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages,MainBot.messageTimeOut).start(); 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("__");
}
} Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveOk("Déplacement de "+user.getEffectiveName()+" vers "+roleStr.toString()+" reussi.")).complete();
else List<Message> messages = new ArrayList<Message>(){{
{ add(rest);
logger.warn("Autorisation insuffisante, deplacement refusé"); add(event.getMessage());
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getMoveError("Vous n'avez pas l'autorisation de faicre ça!")).complete(); }};
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<Message> messages = new ArrayList<Message>(){{ List<Message> messages = new ArrayList<Message>(){{
add(rest); add(rest);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages,MainBot.messageTimeOut).start(); 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() { public boolean isPrivateUsable() {
return false; return false;
} }
@Override
public boolean isAdminCmd() {
return true;
}
} }

View File

@ -157,12 +157,6 @@ public class Music implements Commande {
} }
} }
@Override
public String help(String[] args) {
return "`//music play <url>`\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) <url>`\n:arrow_right:\t*Ajoute l'url à la playlist en cour.*";
}
@Override @Override
public void executed(boolean success, MessageReceivedEvent event) { public void executed(boolean success, MessageReceivedEvent event) {
@ -173,6 +167,11 @@ public class Music implements Commande {
return false; return false;
} }
@Override
public boolean isAdminCmd() {
return false;
}
public AudioM getAudioManager(){ public AudioM getAudioManager(){
return audio; return audio;
} }

View File

@ -21,4 +21,9 @@ public class Ass extends NumberedCommande {
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return false; return false;
} }
@Override
public boolean isAdminCmd() {
return false;
}
} }

View File

@ -20,4 +20,9 @@ public class Boobs extends NumberedCommande {
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return false; return false;
} }
@Override
public boolean isAdminCmd() {
return false;
}
} }

View File

@ -56,11 +56,6 @@ public class Madame implements Commande{
} }
} }
@Override
public String help(String[] args) {
return HELP;
}
@Override @Override
public void executed(boolean success, MessageReceivedEvent event) { public void executed(boolean success, MessageReceivedEvent event) {
@ -70,4 +65,9 @@ public class Madame implements Commande{
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return false; return false;
} }
@Override
public boolean isAdminCmd() {
return false;
}
} }

View File

@ -54,4 +54,9 @@ public class Pipe extends NumberedCommande {
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return false; return false;
} }
@Override
public boolean isAdminCmd() {
return false;
}
} }

View File

@ -40,11 +40,6 @@ public class SM implements Commande {
} }
@Override
public String help(String[] args) {
return HELP;
}
@Override @Override
public void executed(boolean success, MessageReceivedEvent event) { public void executed(boolean success, MessageReceivedEvent event) {
@ -54,4 +49,9 @@ public class SM implements Commande {
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return false; return false;
} }
@Override
public boolean isAdminCmd() {
return false;
}
} }

View File

@ -16,9 +16,6 @@ import java.util.List;
* Created by seb65 on 19/10/2016. * Created by seb65 on 19/10/2016.
*/ */
public class Ping implements Commande { public class Ping implements Commande {
private String HELP = "`//ping` \n :arrow_right:\t*Renvoi le ping du bot*";
@Override @Override
public boolean called(String[] args, MessageReceivedEvent event) { public boolean called(String[] args, MessageReceivedEvent event) {
return true; return true;
@ -41,12 +38,6 @@ public class Ping implements Commande {
LogManager.getLogger().debug("pong"); LogManager.getLogger().debug("pong");
} }
@Override
public String help(String[] args) {
return HELP;
}
@Override @Override
public void executed(boolean success, MessageReceivedEvent event) public void executed(boolean success, MessageReceivedEvent event)
{ {
@ -58,4 +49,9 @@ public class Ping implements Commande {
public boolean isPrivateUsable() { public boolean isPrivateUsable() {
return true; return true;
} }
@Override
public boolean isAdminCmd() {
return false;
}
} }

View File

@ -76,14 +76,6 @@ public class Spam implements Commande {
} }
@Override
public String help(String[] args)
{
return "`//spam extermine <@utilisateur> <multiplicateur>`\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 @Override
public void executed(boolean success, MessageReceivedEvent event) public void executed(boolean success, MessageReceivedEvent event)
{ {
@ -95,6 +87,11 @@ public class Spam implements Commande {
return false; return false;
} }
@Override
public boolean isAdminCmd() {
return true;
}
public void pardon(MessageReceivedEvent event, String[] args){ public void pardon(MessageReceivedEvent event, String[] args){
Guild serveur = event.getGuild(); Guild serveur = event.getGuild();
@ -125,30 +122,12 @@ public class Spam implements Commande {
else { else {
Member user = serveur.getMember(userL.get(0)); Member user = serveur.getMember(userL.get(0));
logger.info("Tentative de pardon de " + user.getEffectiveName() + " par l'utilisateur " + event.getMember().getEffectiveName()); logger.info("Tentative de pardon de " + user.getEffectiveName() + " par l'utilisateur " + event.getMember().getEffectiveName());
/**************************** /****************************
* c'est un big dady * * virif si en spammer *
****************************/ ****************************/
if (MainBot.spamUtils.containsKey(user.getUser())) {
if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){ if (MainBot.spamUtils.get(user.getUser()).isOnSpam()) {
logger.info("Autorisation suffisante, pardon autorisé"); MainBot.spamUtils.get(user.getUser()).setOnSpam(false);
/****************************
* 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<Message> messages = new ArrayList<Message>(){{
add(rest);
add(event.getMessage());
}};
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
}
} else { } else {
logger.warn("Utilisateur pas en spam."); logger.warn("Utilisateur pas en spam.");
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError(":arrow_right: Utilisateur non spammeur.","pardon")).complete(); 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(); new MessageTimeOut(messages,MainBot.messageTimeOut).start();
} }
} else { } else {
logger.warn("Autorisation insuffisante, pardon refusé"); logger.warn("Utilisateur pas en spam.");
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Vous n'avez pas l'autorisation de faire ça!")).complete(); Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError(":arrow_right: Utilisateur non spammeur.","pardon")).complete();
List<Message> messages = new ArrayList<Message>(){{ List<Message> messages = new ArrayList<Message>(){{
add(rest); add(rest);
add(event.getMessage()); add(event.getMessage());
@ -210,48 +190,36 @@ public class Spam implements Commande {
Guild serveur = event.getGuild(); Guild serveur = event.getGuild();
Member user = serveur.getMember(userL.get(0)); Member user = serveur.getMember(userL.get(0));
logger.info("Tentative d'extermination de "+user.getEffectiveName()+" par l'utilisateur "+event.getAuthor().getName()); 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(MainBot.spamUtils.containsKey(user.getUser()))
if(event.getMember().hasPermission(Permission.ADMINISTRATOR))
{ {
logger.info("Autorisation suffisante, extermination autorisé"); if(!MainBot.spamUtils.get(user.getUser()).isOnSpam())
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
{ {
this.goSpam(user,multiStr,serveur,event); 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<Message> messages = new ArrayList<Message>(){{
add(rest);
add(event.getMessage());
}};
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
}
} }
else else
{ {
logger.warn("Autorisation insuffisante, extermination refusé"); this.goSpam(user,multiStr,serveur,event);
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getSpamError("Vous n'avez pas l'autorisation de faire ça!")).complete();
List<Message> messages = new ArrayList<Message>(){{
add(rest);
add(event.getMessage());
}};
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
} }
} }
@ -300,36 +268,23 @@ public class Spam implements Commande {
else { else {
Member user = serveur.getMember(userL.get(0)); Member user = serveur.getMember(userL.get(0));
logger.info("Tentative de reset de " + user.getEffectiveName() + " par l'utilisateur " + event.getMember().getEffectiveName()); logger.info("Tentative de reset de " + user.getEffectiveName() + " par l'utilisateur " + event.getMember().getEffectiveName());
/**************************** /****************************
* c'est un big dady * * verif utilisteur trouver *
****************************/ ****************************/
if (MainBot.spamUtils.containsKey(user.getUser())) {
if(event.getMember().hasPermission(Permission.ADMINISTRATOR)){ logger.info("Reset du multiplicateur de " + user.getEffectiveName() + " réussi");
logger.info("Autorisation suffisante, pardon autorisé"); Message rest = event.getTextChannel().sendMessage(event.getAuthor().getAsMention() + "\n *Le multiplcicateur de " + user.getEffectiveName() + " a été remit a zéro.*").complete();
/****************************
* 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<Message> messages = new ArrayList<Message>(){{
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();
List<Message> messages = new ArrayList<Message>(){{ List<Message> messages = new ArrayList<Message>(){{
add(rest); add(rest);
add(event.getMessage()); add(event.getMessage());
}}; }};
new MessageTimeOut(messages,MainBot.messageTimeOut).start(); new MessageTimeOut(messages,MainBot.messageTimeOut).start();
MainBot.spamUtils.remove(user.getUser());
} }
} }
} }
else else

View File

@ -27,7 +27,6 @@ public class SpamInfo implements Commande{
private HashMap<User,MessageUpdater> threadHashMap = new HashMap<>(); private HashMap<User,MessageUpdater> threadHashMap = new HashMap<>();
Logger logger = LogManager.getLogger(); 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 @Override
public boolean called(String[] args, MessageReceivedEvent event) { public boolean called(String[] args, MessageReceivedEvent event) {
return false; return false;
@ -93,11 +92,6 @@ public class SpamInfo implements Commande{
}
@Override
public String help(String[] args) {
return HELP;
} }
@Override @Override
@ -110,6 +104,11 @@ public class SpamInfo implements Commande{
return true; return true;
} }
@Override
public boolean isAdminCmd() {
return false;
}
public String formatSecond(int second){ public String formatSecond(int second){
long days = TimeUnit.SECONDS.toDays(second); long days = TimeUnit.SECONDS.toDays(second);
second -= TimeUnit.DAYS.toSeconds(days); second -= TimeUnit.DAYS.toSeconds(days);

View File

@ -3,9 +3,12 @@ package net.Broken;
import net.Broken.RestApi.ApiCommandLoader; import net.Broken.RestApi.ApiCommandLoader;
import net.Broken.Tools.Command.CommandParser; import net.Broken.Tools.Command.CommandParser;
import net.Broken.Tools.EmbedMessageUtils; 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.UserManager.UserRegister;
import net.Broken.Tools.UserSpamUtils; import net.Broken.Tools.UserSpamUtils;
import net.dv8tion.jda.core.JDA; 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.ChannelType;
import net.dv8tion.jda.core.entities.Message; import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.core.entities.User;
@ -20,6 +23,7 @@ import org.springframework.stereotype.Controller;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
/** /**
* Created by seb65 on 19/10/2016. * Created by seb65 on 19/10/2016.
@ -95,19 +99,37 @@ public class MainBot {
if (commandes.containsKey(cmd.commande)) 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).action(cmd.args, cmd.event);
commandes.get(cmd.commande).executed(true, 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)) else{
{ if(cmd.event.isFromType(ChannelType.PRIVATE)){
commandes.get(cmd.commande).action(cmd.args, cmd.event); PrivateMessage.send(cmd.event.getAuthor(),EmbedMessageUtils.getUnautorized(), logger);
commandes.get(cmd.commande).executed(true, cmd.event); }
else{
Message msg = cmd.event.getTextChannel().sendMessage(EmbedMessageUtils.getUnautorized()).complete();
List<Message> messages = new ArrayList<Message>(){{
add(msg);
add(cmd.event.getMessage());
}};
new MessageTimeOut(messages, messageTimeOut).start();
}
} }
else
cmd.event.getPrivateChannel().sendMessage(EmbedMessageUtils.getNoPrivate()).queue();
} }

View File

@ -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 <numero>`\n:arrow_right: *Affiche l'image portant le numero donné*";
}
@Override @Override
public void executed(boolean success, MessageReceivedEvent event) { public void executed(boolean success, MessageReceivedEvent event) {

View File

@ -6,29 +6,35 @@ import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.MessageEmbed; import net.dv8tion.jda.core.entities.MessageEmbed;
import java.awt.*; import java.awt.*;
import java.io.FileNotFoundException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class EmbedMessageUtils { public class EmbedMessageUtils {
public static MessageEmbed getUnknowCommand() { 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) { 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(){ 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){ 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) { 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) { 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(); 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) { 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) { 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) { 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) { public static MessageEmbed getSpamError(String message, String sub) {
@ -60,11 +71,12 @@ public class EmbedMessageUtils {
} }
public static MessageEmbed getSpamInfo(String message) { 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) { 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(); 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!");
}
} }

View File

@ -26,10 +26,10 @@ public class MessageTimeOut extends Thread{
e.printStackTrace(); e.printStackTrace();
} }
} }
logger.debug("Timiout! Deleting message!");
for(Message aMessage: messages) for(Message aMessage: messages)
{ {
try { try {
logger.debug(aMessage.getContent());
aMessage.delete().queue(); aMessage.delete().queue();
}catch (ErrorResponseException e){ }catch (ErrorResponseException e){
logger.warn("Unknown Message"); logger.warn("Unknown Message");

View File

@ -4,6 +4,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Scanner; import java.util.Scanner;
@ -14,13 +15,15 @@ public class ResourceLoader {
private Logger logger = LogManager.getLogger(); private Logger logger = LogManager.getLogger();
public String getFile(String fileName) { public String getFile(String fileName) throws FileNotFoundException {
StringBuilder result = new StringBuilder(""); StringBuilder result = new StringBuilder("");
//Get file from resources folder //Get file from resources folder
ClassLoader classLoader = getClass().getClassLoader(); ClassLoader classLoader = getClass().getClassLoader();
InputStream file = classLoader.getResourceAsStream(fileName); InputStream file = classLoader.getResourceAsStream(fileName);
if(file == null)
throw new FileNotFoundException();
try (Scanner scanner = new Scanner(file, "UTF-8")) { try (Scanner scanner = new Scanner(file, "UTF-8")) {

View File

@ -18,6 +18,7 @@ import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceS
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import java.io.FileNotFoundException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -86,7 +87,12 @@ public class UserRegister {
pendingUserEntity = pendingUserRepository.save(pendingUserEntity); 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); message = message.replace("%code",token);

View File

@ -0,0 +1,4 @@
Ho! Regarde! Un chat!
Mais il est different à chaque fois en plus!
C'est trop cute! :cat:

View File

@ -0,0 +1,2 @@
L'aide pour cette commande n'est pas encore disponible !
Pour contribué: https://github.com/BrokenFire/BrokenDiscordBot

View File

@ -0,0 +1,3 @@
`//flush <nbr>`
:arrow_right: *Efface les n derniers messages (Max = 100)*

View File

@ -0,0 +1,2 @@
`//move <@utilisateur> <@rôleCible>`
:arrow_right: *Deplacement d'un utilisateur vers un rôle cible, attention à bien faire des montions.*

View File

@ -0,0 +1,26 @@
`//music play <url>`
: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) <url>`
:arrow_right: *Ajoute l'url à la playlist en cour.*

View File

@ -0,0 +1,2 @@
`//ping`
:arrow_right: *Renvoi le ping du bot*

View File

@ -0,0 +1,8 @@
`//spam extermine <@utilisateur> <multiplicateur>`
: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.*

View File

@ -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)*