diff --git a/src/main/kotlin/me/ddivad/judgebot/arguments/LowerMemberArg.kt b/src/main/kotlin/me/ddivad/judgebot/arguments/LowerMemberArg.kt index 951570b..ed3822b 100644 --- a/src/main/kotlin/me/ddivad/judgebot/arguments/LowerMemberArg.kt +++ b/src/main/kotlin/me/ddivad/judgebot/arguments/LowerMemberArg.kt @@ -29,6 +29,6 @@ open class LowerMemberArg(override val name: String = "LowerMemberArg") : Argume override fun formatData(data: Member) = "@${data.tag}" } -private suspend fun Member.isHigherRankedThan(permissions: PermissionsService, targetMember: Member) = +suspend fun Member.isHigherRankedThan(permissions: PermissionsService, targetMember: Member) = permissions.getPermissionRank(this) < permissions.getPermissionRank(targetMember) diff --git a/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt b/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt index bc4ee52..cd47fe6 100644 --- a/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt +++ b/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt @@ -3,6 +3,8 @@ package me.ddivad.judgebot.listeners import com.gitlab.kordlib.core.behavior.getChannelOf import com.gitlab.kordlib.core.entity.channel.TextChannel import com.gitlab.kordlib.core.event.message.ReactionAddEvent +import com.gitlab.kordlib.kordx.emoji.Emojis +import com.gitlab.kordlib.kordx.emoji.addReaction import me.ddivad.judgebot.dataclasses.Configuration import me.ddivad.judgebot.extensions.jumpLink import me.jakejmattson.discordkt.api.dsl.listeners @@ -15,11 +17,13 @@ fun onMemberReactionAdd(configuration: Configuration) = listeners { val guildConfiguration = configuration[guild.asGuild().id.longValue] if (!guildConfiguration?.reactions!!.enabled) return@on - if(this.emoji.name == guildConfiguration.reactions.flagMessageReaction) { - message.deleteReaction(this.emoji) - guild.asGuild().getChannelOf(guildConfiguration.loggingConfiguration.alertChannel.toSnowflake()) - .asChannel().createMessage("User ${user.mention} flagged the message: " + - "${this.message.asMessage().jumpLink(guild.id.value)} in: ${this.channel.mention}") + when (this.emoji.name) { + guildConfiguration.reactions.flagMessageReaction -> { + message.deleteReaction(this.emoji) + guild.asGuild().getChannelOf(guildConfiguration.loggingConfiguration.alertChannel.toSnowflake()).asChannel() + .createMessage("User ${user.mention} flagged the message: ${this.message.asMessage().jumpLink(guild.id.value)} in: ${this.channel.mention}") + .addReaction(Emojis.whiteCheckMark) + } } } } diff --git a/src/main/kotlin/me/ddivad/judgebot/listeners/StaffReactionListeners.kt b/src/main/kotlin/me/ddivad/judgebot/listeners/StaffReactionListeners.kt index 8fd20d9..f04bf32 100644 --- a/src/main/kotlin/me/ddivad/judgebot/listeners/StaffReactionListeners.kt +++ b/src/main/kotlin/me/ddivad/judgebot/listeners/StaffReactionListeners.kt @@ -2,6 +2,7 @@ package me.ddivad.judgebot.listeners import com.gitlab.kordlib.common.exception.RequestException import com.gitlab.kordlib.core.event.message.ReactionAddEvent +import me.ddivad.judgebot.arguments.isHigherRankedThan import me.ddivad.judgebot.dataclasses.Configuration import me.ddivad.judgebot.embeds.createMessageDeleteEmbed import me.ddivad.judgebot.embeds.createSelfHistoryEmbed @@ -21,36 +22,34 @@ fun onStaffReactionAdd(muteService: MuteService, val guild = guild?.asGuildOrNull() ?: return@on val guildConfiguration = configuration[guild.asGuild().id.longValue] if (!guildConfiguration?.reactions!!.enabled) return@on - - user.asMemberOrNull(guild.id)?.let { - if (permissionsService.hasPermission(it, PermissionLevel.Moderator)) { - val messageAuthor = message.asMessage().author ?: return@on - - when (this.emoji.name) { - guildConfiguration.reactions.gagReaction -> { - message.deleteReaction(this.emoji) - muteService.gag(messageAuthor.asMember(guild.id)) - it.sendPrivateMessage("${messageAuthor.mention} gagged.") - } - guildConfiguration.reactions.historyReaction -> { - message.deleteReaction(this.emoji) - val target = databaseService.users.getOrCreateUser(messageAuthor, guild.asGuild()) - it.sendPrivateMessage { createSelfHistoryEmbed(messageAuthor, target, guild.asGuild(), configuration) } - } - guildConfiguration.reactions.deleteMessageReaction -> { - val content = message.asMessage() - message.deleteReaction(this.emoji) - message.delete() - try { - messageAuthor.sendPrivateMessage { - createMessageDeleteEmbed(guild, content) - } - } catch (ex: RequestException) { - this.user.sendPrivateMessage("User ${messageAuthor.mention} has DM's disabled." + - " Message deleted without notification.") + val member = user.asMemberOrNull(guild.id) ?: return@on + val messageAuthor = message.asMessage().author?.asMemberOrNull(guild.id) ?: return@on + + if (permissionsService.hasPermission(member, PermissionLevel.Moderator) && !member.isHigherRankedThan(permissionsService, messageAuthor)) { + when (this.emoji.name) { + guildConfiguration.reactions.gagReaction -> { + message.deleteReaction(this.emoji) + muteService.gag(messageAuthor.asMember(guild.id)) + member.sendPrivateMessage("${messageAuthor.mention} gagged.") + } + guildConfiguration.reactions.historyReaction -> { + message.deleteReaction(this.emoji) + val target = databaseService.users.getOrCreateUser(messageAuthor, guild.asGuild()) + member.sendPrivateMessage { createSelfHistoryEmbed(messageAuthor, target, guild.asGuild(), configuration) } + } + guildConfiguration.reactions.deleteMessageReaction -> { + val content = message.asMessage() + message.deleteReaction(this.emoji) + message.delete() + try { + messageAuthor.sendPrivateMessage { + createMessageDeleteEmbed(guild, content) } - + } catch (ex: RequestException) { + this.user.sendPrivateMessage("User ${messageAuthor.mention} has DM's disabled." + + " Message deleted without notification.") } + } } }