From ac4fef7cb23edf432704603a8d607340b1319ed4 Mon Sep 17 00:00:00 2001 From: dkim19375 Date: Sun, 16 May 2021 16:38:58 -0400 Subject: [PATCH] fix whitelist --- build.gradle | 2 +- .../managers/SpecialEventsManager.kt | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 1f213a1..b25e31b 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 compileJava.options.encoding 'UTF-8' group 'me.dkim19375' -version '2.2.6' +version '2.2.7' //noinspection GrUnresolvedAccess compileKotlin.kotlinOptions { diff --git a/src/main/java/me/dkim19375/dkim19375jdautils/managers/SpecialEventsManager.kt b/src/main/java/me/dkim19375/dkim19375jdautils/managers/SpecialEventsManager.kt index 3c6250b..d53ff0d 100644 --- a/src/main/java/me/dkim19375/dkim19375jdautils/managers/SpecialEventsManager.kt +++ b/src/main/java/me/dkim19375/dkim19375jdautils/managers/SpecialEventsManager.kt @@ -98,10 +98,6 @@ open class SpecialEventsManager(private val bot: BotBase) : ListenerAdapter() { if (debug) { println("passed userId test") } - val guild: Guild? = when (event) { - is GuildMessageReactionAddEvent -> event.guild - else -> null - } val emoji: MessageReaction.ReactionEmote = when (event) { is GuildMessageReactionAddEvent -> event.reactionEmote is MessageReactionAddEvent -> event.reactionEmote @@ -126,6 +122,7 @@ open class SpecialEventsManager(private val bot: BotBase) : ListenerAdapter() { if (debug) { println("passed channel test") } + val guild: Guild? = (channel as? GuildChannel)?.guild if (requiredChannel != 0L && requiredChannel != channel.idLong) { if (debug) { println("stopped - requiredChannel: $requiredChannel, channel: ${channel.idLong}") @@ -182,30 +179,37 @@ open class SpecialEventsManager(private val bot: BotBase) : ListenerAdapter() { } retrievedMessage.queue message@{ msg -> jda.retrieveUserById(userId).queue userQ@{ user -> - guild?.retrieveMemberById(userId)?.queue memberQueue@{ member -> + val removeNoPerms: (Member?) -> Boolean = removeNoPermsLabel@{ member -> if (!whitelist.hasAccess(user, member, channel as? GuildChannel)) { if (debug) { println("no permissions") } if (!removeIfNoPerms) { future.complete(false) - return@memberQueue + return@removeNoPermsLabel false } when { emoji.isEmoji -> msg.removeReaction(emoji.emoji, user).queue() emoji.isEmote -> msg.removeReaction(emoji.emote, user).queue() } future.complete(false) + return@removeNoPermsLabel false + } + future.complete(true) + action(event, guild, emoji, channel, user, msg, member) + return@removeNoPermsLabel true + } + guild?.retrieveMemberById(userId)?.queue memberQueue@{ member -> + if (!removeNoPerms(member)) { return@memberQueue } if (debug) { println("called action - guild") } - future.complete(true) - action(event, guild, emoji, channel, user, msg, member) } ?: let { - future.complete(true) - action(event, guild, emoji, channel, user, msg, null) + if (!removeNoPerms(null)) { + return@let + } if (debug) { println("called action - null guild") }