Show only usable command on help #10

This commit is contained in:
BrokenFire 2018-02-24 17:28:16 +01:00
parent aa392d8cf2
commit 44ddf2b24e
2 changed files with 67 additions and 33 deletions

View File

@ -2,10 +2,12 @@ package net.Broken.Commands;
import net.Broken.Commande; import net.Broken.Commande;
import net.Broken.MainBot; import net.Broken.MainBot;
import net.Broken.RestApi.CommandInterface;
import net.Broken.Tools.EmbedMessageUtils; import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.MessageTimeOut; import net.Broken.Tools.MessageTimeOut;
import net.Broken.Tools.PrivateMessage; import net.Broken.Tools.PrivateMessage;
import net.dv8tion.jda.core.EmbedBuilder; import net.dv8tion.jda.core.EmbedBuilder;
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.MessageEmbed; import net.dv8tion.jda.core.entities.MessageEmbed;
@ -37,41 +39,61 @@ public class Help implements Commande {
//System.out.println(argsString); //System.out.println(argsString);
if (MainBot.commandes.containsKey(argsString)) if (MainBot.commandes.containsKey(argsString))
{ {
logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getAuthor().getName()); Commande cmdObj = MainBot.commandes.get(argsString);
MessageEmbed messageEmbed; if(!cmdObj.isAdminCmd() || event.getMember().hasPermission(Permission.ADMINISTRATOR))
try { {
messageEmbed = EmbedMessageUtils.getHelp(argsString); logger.info("Aide demmander pour la cmd "+argsString+" par "+event.getAuthor().getName());
} catch (FileNotFoundException e) { MessageEmbed messageEmbed;
try { try {
messageEmbed = EmbedMessageUtils.getHelp("Default"); messageEmbed = EmbedMessageUtils.getHelp(argsString);
} catch (FileNotFoundException e1) { } catch (FileNotFoundException e) {
messageEmbed = EmbedMessageUtils.getInternalError(); try {
logger.catching(e1); messageEmbed = EmbedMessageUtils.getHelp("Default");
} } catch (FileNotFoundException e1) {
} messageEmbed = EmbedMessageUtils.getInternalError();
if(!event.isFromType(ChannelType.PRIVATE)) { logger.catching(e1);
Message rest = event.getTextChannel().sendMessage(messageEmbed).complete(); }
if(args.length<=1)
{
Message finalRest = rest;
List<Message> messages = new ArrayList<Message>(){{
add(finalRest);
add(event.getMessage());
}};
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
}
else if(!args[1].toLowerCase().equals("true")){
Message finalRest1 = rest;
List<Message> messages = new ArrayList<Message>(){{
add(finalRest1);
add(event.getMessage());
}};
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
} }
if(!event.isFromType(ChannelType.PRIVATE)) {
Message rest = event.getTextChannel().sendMessage(messageEmbed).complete();
if(args.length<=1)
{
Message finalRest = rest;
List<Message> messages = new ArrayList<Message>(){{
add(finalRest);
add(event.getMessage());
}};
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
}
else if(!args[1].toLowerCase().equals("true")){
Message finalRest1 = rest;
List<Message> messages = new ArrayList<Message>(){{
add(finalRest1);
add(event.getMessage());
}};
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
}
} else{ } else{
PrivateMessage.send(event.getAuthor(), messageEmbed,logger); PrivateMessage.send(event.getAuthor(), messageEmbed,logger);
}
} }
else
{
logger.info("Help wanted for admin command, Denied!");
if(!event.isFromType(ChannelType.PRIVATE)) {
Message rest = event.getTextChannel().sendMessage(EmbedMessageUtils.getUnautorized()).complete();
List<Message> messages = new ArrayList<Message>(){{
add(rest);
add(event.getMessage());
}};
new MessageTimeOut(messages,MainBot.messageTimeOut).start();
} else{
PrivateMessage.send(event.getAuthor(), EmbedMessageUtils.getUnautorized(), logger);
}
}
} }
@ -94,7 +116,8 @@ public class Help implements Commande {
{ {
StringBuilder txt= new StringBuilder(); StringBuilder txt= new StringBuilder();
for (Map.Entry<String, Commande> e : MainBot.commandes.entrySet()) { for (Map.Entry<String, Commande> e : MainBot.commandes.entrySet()) {
txt.append("\n- ").append(e.getKey()); if(!e.getValue().isAdminCmd() || event.getMember().hasPermission(Permission.ADMINISTRATOR))
txt.append("\n- ").append(e.getKey());
} }
if(!event.isFromType(ChannelType.PRIVATE)){ if(!event.isFromType(ChannelType.PRIVATE)){
@ -106,7 +129,14 @@ public class Help implements Commande {
new MessageTimeOut(messages,MainBot.messageTimeOut).start(); new MessageTimeOut(messages,MainBot.messageTimeOut).start();
} }
PrivateMessage.send(event.getAuthor(),new EmbedBuilder().setTitle("Command du bot").setDescription(txt.toString()).setFooter("Utilise '//help <commande>' pour plus de détails.",null).setColor(Color.green).setThumbnail(event.getJDA().getSelfUser().getAvatarUrl()).build(),logger);
String role;
if(event.getMember().hasPermission(Permission.ADMINISTRATOR))
role = "Admin";
else
role = "Non Admin";
PrivateMessage.send(event.getAuthor(),EmbedMessageUtils.getHelpList(role, txt.toString()),logger);

View File

@ -98,5 +98,9 @@ public class EmbedMessageUtils {
return getError("Vous n'avez pas l'autorisation de faire ça!"); return getError("Vous n'avez pas l'autorisation de faire ça!");
} }
public static MessageEmbed getHelpList(String role, String list){
return new EmbedBuilder().setTitle("Command du bot ("+role+")").setDescription(list).setFooter("Utilise '//help <commande>' pour plus de détails.",null).setColor(Color.green).setThumbnail(MainBot.jda.getSelfUser().getAvatarUrl()).build();
}
} }