Catching some permission error

This commit is contained in:
Sebastien 2019-09-27 09:17:31 +02:00
parent 1389a11e46
commit 87e820f6fe

View File

@ -21,6 +21,7 @@ import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.managers.GuildManager;
import org.apache.logging.log4j.LogManager;
@ -109,9 +110,7 @@ public class BotListener extends ListenerAdapter {
new Move().exc(event.getMember(), roles, false, event.getGuild(), event.getGuild().getManager());
MainBot.roleFlag = false;
}
}
else
{
} else {
logger.debug("ignore it");
MainBot.roleFlag = false;
}
@ -119,7 +118,6 @@ public class BotListener extends ListenerAdapter {
}
}
@ -140,8 +138,7 @@ public class BotListener extends ListenerAdapter {
@Override
public void onGuildVoiceLeave(GuildVoiceLeaveEvent event) {
super.onGuildVoiceLeave(event);
if(event.getGuild().getAudioManager().isConnected())
{
if (event.getGuild().getAudioManager().isConnected()) {
logger.trace("User disconnected from voice channel.");
if (event.getGuild().getAudioManager().getConnectedChannel().getMembers().size() == 1) {
@ -165,23 +162,17 @@ public class BotListener extends ListenerAdapter {
UserEntity user = users.size() == 0 ? null : users.get(0);
MainBot.handleCommand(new CommandParser().parse(event.getMessage().getContentRaw(), event), user);
}
else if (!event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId()))
{
} else if (!event.getMessage().getAuthor().getId().equals(event.getJDA().getSelfUser().getId())) {
if (!event.isFromType(ChannelType.PRIVATE)) {
Guild serveur = event.getGuild();
GuildPreferenceEntity guildPref = getPreference(serveur);
if (!guildPref.isAntiSpam())
return;
try {
GuildManager guildManager = serveur.getManager();
Member user = event.getMember();
@ -193,6 +184,11 @@ public class BotListener extends ListenerAdapter {
}
} else if (event.getMessage().getContentRaw().length() == 0)
logger.error("Image detected, ignoring it.");
} catch (InsufficientPermissionException e) {
logger.warn("Insufficient permission for guild " + e.getGuild(MainBot.jda).getName() + " Missing " + e.getPermission() + " permission.");
}
}
@ -207,7 +203,6 @@ public class BotListener extends ListenerAdapter {
}
}
@Override
@ -221,7 +216,16 @@ public class BotListener extends ListenerAdapter {
"\nYou can access to my web UI with: " + MainBot.url)
.setImage("https://i.imgur.com/Anf1Srg.gif");
event.getGuild().getDefaultChannel().sendMessage(EmbedMessageUtils.buildStandar(eb)).complete();
TextChannel defaultChan = event.getGuild().getDefaultChannel();
if (defaultChan != null && defaultChan.canTalk())
defaultChan.sendMessage(EmbedMessageUtils.buildStandar(eb)).queue();
else {
for(TextChannel chan : event.getGuild().getTextChannels()){
if(chan.canTalk()){
chan.sendMessage(EmbedMessageUtils.buildStandar(eb)).queue();
}
}
}
}
private GuildPreferenceEntity getPreference(Guild guild) {
@ -231,8 +235,7 @@ public class BotListener extends ListenerAdapter {
logger.info("Generate default pref");
guildPref = GuildPreferenceEntity.getDefault(guild);
guildPreferenceRepository.save(guildPref);
}
else
} else
guildPref = guildPrefList.get(0);
return guildPref;
}