From 9e8797980f59c1d94b87cdce70f3fcd64c69ec49 Mon Sep 17 00:00:00 2001 From: ddivad195 Date: Wed, 25 Aug 2021 14:29:15 +0100 Subject: [PATCH 1/2] fix: add check for delete message days to make sure it can't be more than 7 --- src/main/kotlin/me/ddivad/judgebot/Main.kt | 2 +- src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/me/ddivad/judgebot/Main.kt b/src/main/kotlin/me/ddivad/judgebot/Main.kt index b09981a..83d07dc 100644 --- a/src/main/kotlin/me/ddivad/judgebot/Main.kt +++ b/src/main/kotlin/me/ddivad/judgebot/Main.kt @@ -70,7 +70,7 @@ suspend fun main() { field { name = "Build Info" value = "```" + - "Version: 2.5.1\n" + + "Version: 2.5.2\n" + "DiscordKt: ${versions.library}\n" + "Kord: ${versions.kord}\n" + "Kotlin: $kotlinVersion" + diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt index 78da5ab..e8a13e8 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt @@ -79,6 +79,10 @@ fun createUserCommands( requiredPermission = Permissions.STAFF execute(LowerUserArg, IntegerArg("Delete message days").optional(0), EveryArg) { val (target, deleteDays, reason) = args + if (deleteDays > 7) { + respond("Delete days cannot be more than **7**. You tried with **${deleteDays}**") + return@execute + } val ban = Punishment(target.id.asString, InfractionType.Ban, reason, author.id.asString) banService.banUser(target, guild, ban, deleteDays).also { loggingService.userBanned(guild, target, ban) From 24c0aedd6a8ff38c53b128ded95f63fed0348404 Mon Sep 17 00:00:00 2001 From: ddivad195 Date: Sun, 29 Aug 2021 19:09:42 +0100 Subject: [PATCH 2/2] feat: add report message application --- commands.md | 7 +++--- src/main/kotlin/me/ddivad/judgebot/Main.kt | 2 +- .../judgebot/commands/UtilityCommands.kt | 25 ++++++++++++++++++- .../listeners/MemberReactionListeners.kt | 16 ++---------- .../me/ddivad/judgebot/util/MessageUtils.kt | 21 ++++++++++++++++ 5 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 src/main/kotlin/me/ddivad/judgebot/util/MessageUtils.kt diff --git a/commands.md b/commands.md index 23dab7f..015453b 100644 --- a/commands.md +++ b/commands.md @@ -69,7 +69,8 @@ | whatpfp | User | Perform a reverse image search of a User's profile picture | ## Utility -| Commands | Arguments | Description | -| -------- | --------- | ------------------------- | -| help | [Command] | Display help information. | +| Commands | Arguments | Description | +| -------- | --------- | ---------------------------------------- | +| help | [Command] | Display help information. | +| report | Message | Flag a message for moderators to review. | diff --git a/src/main/kotlin/me/ddivad/judgebot/Main.kt b/src/main/kotlin/me/ddivad/judgebot/Main.kt index b09981a..35acb86 100644 --- a/src/main/kotlin/me/ddivad/judgebot/Main.kt +++ b/src/main/kotlin/me/ddivad/judgebot/Main.kt @@ -70,7 +70,7 @@ suspend fun main() { field { name = "Build Info" value = "```" + - "Version: 2.5.1\n" + + "Version: 2.6.0\n" + "DiscordKt: ${versions.library}\n" + "Kord: ${versions.kord}\n" + "Kotlin: $kotlinVersion" + diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/UtilityCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/UtilityCommands.kt index e17f1dc..748f151 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/UtilityCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/UtilityCommands.kt @@ -1,12 +1,20 @@ package me.ddivad.judgebot.commands +import dev.kord.core.behavior.getChannelOf +import dev.kord.core.entity.channel.TextChannel +import dev.kord.x.emoji.Emojis +import dev.kord.x.emoji.addReaction +import me.ddivad.judgebot.dataclasses.Configuration import me.ddivad.judgebot.dataclasses.Permissions import me.ddivad.judgebot.services.HelpService +import me.ddivad.judgebot.util.createFlagMessage import me.jakejmattson.discordkt.api.arguments.AnyArg +import me.jakejmattson.discordkt.api.arguments.MessageArg import me.jakejmattson.discordkt.api.commands.commands +import me.jakejmattson.discordkt.api.extensions.toSnowflake @Suppress("unused") -fun createInformationCommands(helpService: HelpService) = commands("Utility") { +fun createInformationCommands(helpService: HelpService, configuration: Configuration) = commands("Utility") { command("help") { description = "Display help information." requiredPermission = Permissions.NONE @@ -22,4 +30,19 @@ fun createInformationCommands(helpService: HelpService) = commands("Utility") { } } } + + slash("report", "Report Message") { + description = "Flag a message for moderators to review." + requiredPermission = Permissions.NONE + execute(MessageArg) { + val guild = guild ?: return@execute + val guildConfiguration = configuration[guild.asGuild().id.value] ?: return@execute + + guild.getChannelOf(guildConfiguration.loggingConfiguration.alertChannel.toSnowflake()) + .createMessage(createFlagMessage(author, args.first, channel)) + .addReaction(Emojis.question) + + respond("Message flagged successfully, thanks!") + } + } } \ No newline at end of file diff --git a/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt b/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt index cffa058..ac14eca 100644 --- a/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt +++ b/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt @@ -1,15 +1,13 @@ package me.ddivad.judgebot.listeners -import dev.kord.common.entity.ChannelType import dev.kord.core.behavior.getChannelOf import dev.kord.core.entity.channel.TextChannel -import dev.kord.core.entity.channel.thread.ThreadChannel import dev.kord.core.event.message.ReactionAddEvent import dev.kord.x.emoji.Emojis import dev.kord.x.emoji.addReaction import me.ddivad.judgebot.dataclasses.Configuration +import me.ddivad.judgebot.util.createFlagMessage import me.jakejmattson.discordkt.api.dsl.listeners -import me.jakejmattson.discordkt.api.extensions.jumpLink import me.jakejmattson.discordkt.api.extensions.toSnowflake @Suppress("unused") @@ -23,20 +21,10 @@ fun onMemberReactionAdd(configuration: Configuration) = listeners { guildConfiguration.reactions.flagMessageReaction -> { message.deleteReaction(this.emoji) val channel = message.getChannel() - val isThread = channel.type in setOf(ChannelType.PublicGuildThread, ChannelType.PrivateThread) guild.asGuild() .getChannelOf(guildConfiguration.loggingConfiguration.alertChannel.toSnowflake()) .asChannel() - .createMessage( - "**Message Flagged**" + - "\n**User**: ${user.mention}" + - (if (isThread) - "\n**Thread**: ${channel.mention} (${(channel as? ThreadChannel)?.parent?.mention})" - else - "\n**Channel**: ${channel.mention}") + - "\n**Author:** ${message.asMessage().author?.mention}" + - "\n**Message:** ${message.asMessage().jumpLink()}" - ) + .createMessage(createFlagMessage(user.asUser(), message.asMessage(), channel)) .addReaction(Emojis.question) } } diff --git a/src/main/kotlin/me/ddivad/judgebot/util/MessageUtils.kt b/src/main/kotlin/me/ddivad/judgebot/util/MessageUtils.kt new file mode 100644 index 0000000..f3fe6c7 --- /dev/null +++ b/src/main/kotlin/me/ddivad/judgebot/util/MessageUtils.kt @@ -0,0 +1,21 @@ +package me.ddivad.judgebot.util + +import dev.kord.common.entity.ChannelType +import dev.kord.core.entity.Message +import dev.kord.core.entity.User +import dev.kord.core.entity.channel.MessageChannel +import dev.kord.core.entity.channel.thread.ThreadChannel +import me.jakejmattson.discordkt.api.extensions.jumpLink + +suspend fun createFlagMessage(user: User, message: Message, channel: MessageChannel): String { + val isThread = channel.type in setOf(ChannelType.PublicGuildThread, ChannelType.PrivateThread) + + return "**Message Flagged**" + + "\n**User**: ${user.mention}" + + (if (isThread) + "\n**Thread**: ${channel.mention} (${(channel as? ThreadChannel)?.parent?.mention})" + else + "\n**Channel**: ${channel.mention}") + + "\n**Author:** ${message.author?.mention}" + + "\n**Message:** ${message.jumpLink()}" +} \ No newline at end of file