From 67222290d91de3f3bea7571b9d2750b773afcf9b Mon Sep 17 00:00:00 2001 From: dkim19375 Date: Sun, 16 May 2021 15:25:26 -0400 Subject: [PATCH] add Whitelist to SpecialEventsManager --- build.gradle | 2 +- .../managers/SpecialEventsManager.kt | 23 +++---------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index c47c03e..27fb756 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.4' +version '2.2.5' //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 638698b..3c6250b 100644 --- a/src/main/java/me/dkim19375/dkim19375jdautils/managers/SpecialEventsManager.kt +++ b/src/main/java/me/dkim19375/dkim19375jdautils/managers/SpecialEventsManager.kt @@ -2,11 +2,10 @@ package me.dkim19375.dkim19375jdautils.managers import me.dkim19375.dkim19375jdautils.BotBase import me.dkim19375.dkim19375jdautils.annotation.API +import me.dkim19375.dkim19375jdautils.data.Whitelist import me.dkim19375.dkim19375jdautils.util.EventType import me.dkim19375.dkim19375jdautils.util.getMessageId import me.dkim19375.dkim19375jdautils.util.getUserId -import me.dkim19375.dkim19375jdautils.util.hasPermission -import net.dv8tion.jda.api.Permission import net.dv8tion.jda.api.entities.* import net.dv8tion.jda.api.events.Event import net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent @@ -57,8 +56,7 @@ open class SpecialEventsManager(private val bot: BotBase) : ListenerAdapter() { requiredMessage: Long = 0, requiredChannel: Long = 0, requiredGuild: Long = 0, - whitelist: Set? = null, - requiredPerms: Set = emptySet(), + whitelist: Whitelist = Whitelist(bot.jda), removeIfNoPerms: Boolean = false, reaction: MessageReaction.ReactionEmote? = null, debug: Boolean = false @@ -184,23 +182,8 @@ open class SpecialEventsManager(private val bot: BotBase) : ListenerAdapter() { } retrievedMessage.queue message@{ msg -> jda.retrieveUserById(userId).queue userQ@{ user -> - if (whitelist?.contains(userId) == false) { - if (debug) { - println("no whitelist") - } - if (!removeIfNoPerms) { - future.complete(false) - return@userQ - } - when { - emoji.isEmoji -> msg.removeReaction(emoji.emoji, user).queue() - emoji.isEmote -> msg.removeReaction(emoji.emote, user).queue() - } - future.complete(false) - return@userQ - } guild?.retrieveMemberById(userId)?.queue memberQueue@{ member -> - if (!member.hasPermission(requiredPerms, channel as? GuildChannel)) { + if (!whitelist.hasAccess(user, member, channel as? GuildChannel)) { if (debug) { println("no permissions") }