Skip to content

Commit

Permalink
add Whitelist to SpecialEventsManager
Browse files Browse the repository at this point in the history
  • Loading branch information
dkim19375 committed May 16, 2021
1 parent 32d836a commit 6722229
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,8 +56,7 @@ open class SpecialEventsManager(private val bot: BotBase) : ListenerAdapter() {
requiredMessage: Long = 0,
requiredChannel: Long = 0,
requiredGuild: Long = 0,
whitelist: Set<Long>? = null,
requiredPerms: Set<Permission> = emptySet(),
whitelist: Whitelist = Whitelist(bot.jda),
removeIfNoPerms: Boolean = false,
reaction: MessageReaction.ReactionEmote? = null,
debug: Boolean = false
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 6722229

Please sign in to comment.