Skip to content

Commit

Permalink
fix whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
dkim19375 committed May 16, 2021
1 parent a1752b0 commit ac4fef7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 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.6'
version '2.2.7'

//noinspection GrUnresolvedAccess
compileKotlin.kotlinOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit ac4fef7

Please sign in to comment.