Catching all exeption and add error command #22

This commit is contained in:
BrokenFire 2018-02-26 11:39:13 +01:00
parent 9cec8b3ff1
commit 4cb83c8725
3 changed files with 83 additions and 29 deletions

View File

@ -4,11 +4,14 @@ import net.Broken.Commands.Move;
import net.Broken.Commands.Music;
import net.Broken.Tools.AntiSpam;
import net.Broken.Tools.Command.CommandParser;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.Moderateur;
import net.Broken.Tools.PrivateMessage;
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.entities.TextChannel;
import net.dv8tion.jda.core.events.ExceptionEvent;
import net.dv8tion.jda.core.events.ReadyEvent;
import net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.core.events.guild.member.GuildMemberRoleRemoveEvent;
@ -85,6 +88,8 @@ public class BotListener extends ListenerAdapter {
public void onMessageReceived(MessageReceivedEvent event) {
// ----------------------Test pour eviter eco de commande-------------------------
try{
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());
@ -113,10 +118,18 @@ public class BotListener extends ListenerAdapter {
}
}
}catch (Exception e){
logger.catching(e);
if(event.isFromType(ChannelType.PRIVATE))
PrivateMessage.send(event.getAuthor(), EmbedMessageUtils.getInternalError(), logger);
else
event.getTextChannel().sendMessage(EmbedMessageUtils.getInternalError()).queue();
}
}
}
}

View File

@ -0,0 +1,41 @@
package net.Broken.Commands;
import net.Broken.Commande;
import net.Broken.Tools.EmbedMessageUtils;
import net.Broken.Tools.PrivateMessage;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Error implements Commande{
private Logger logger = LogManager.getLogger();
@Override
public boolean called(String[] args, MessageReceivedEvent event) {
return false;
}
@Override
public void action(String[] args, MessageReceivedEvent event) {
if(event.isFromType(ChannelType.PRIVATE))
PrivateMessage.send(event.getAuthor(), EmbedMessageUtils.getInternalError(), logger);
else
event.getTextChannel().sendMessage(EmbedMessageUtils.getInternalError()).queue();
}
@Override
public void executed(boolean success, MessageReceivedEvent event) {
}
@Override
public boolean isPrivateUsable() {
return true;
}
@Override
public boolean isAdminCmd() {
return true;
}
}

View File

@ -15,9 +15,9 @@ public class EmbedMessageUtils {
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 EmbedBuilder getError(String message) {
EmbedBuilder temp = new EmbedBuilder().setTitle(":warning: Error! :warning:").setColor(Color.red).setDescription(message);
return buildStandar(temp);
return temp;
}
@ -85,7 +85,7 @@ public class EmbedMessageUtils {
}
public static MessageEmbed getInternalError(){
return getError("Je... Je... je ne me sent pas bien... :thermometer_face: \nContactez vite mon developeur!");
return buildStandar(getError("Je... Je... je ne me sens pas bien... :thermometer_face: \nContactez vite mon developeur!").setImage("https://media.giphy.com/media/Rkis28kMJd1aE/giphy.gif"));
}
public static MessageEmbed buildStandar(EmbedBuilder embedBuilder){
@ -95,7 +95,7 @@ public class EmbedMessageUtils {
}
public static MessageEmbed getUnautorized(){
return getError("Vous n'avez pas l'autorisation de faire ça!");
return buildStandar(getError("Vous n'avez pas l'autorisation de faire ça!"));
}
public static MessageEmbed getHelpList(String role, String list){