From e691f784ea8ac64c602b86baa542139b19bf4801 Mon Sep 17 00:00:00 2001 From: ddivad195 Date: Sun, 15 Aug 2021 14:43:29 +0100 Subject: [PATCH 1/2] feat: update to latest discordkt snapshot --- .github/workflows/discord-release.yml | 19 +++++++++++++ build.gradle.kts | 2 +- src/main/kotlin/me/ddivad/judgebot/Main.kt | 11 +++++--- .../judgebot/arguments/GuildConfigArg.kt | 4 +-- .../judgebot/arguments/LowerMemberArg.kt | 8 +++--- .../ddivad/judgebot/arguments/LowerUserArg.kt | 10 ++++--- .../me/ddivad/judgebot/arguments/RuleArg.kt | 4 +-- .../ddivad/judgebot/commands/GuildCommands.kt | 3 ++- .../ddivad/judgebot/commands/InfoCommands.kt | 2 +- .../judgebot/commands/InfractionCommands.kt | 4 ++- .../ddivad/judgebot/commands/MuteCommands.kt | 2 +- .../ddivad/judgebot/commands/NoteCommands.kt | 2 +- .../ddivad/judgebot/commands/RuleCommands.kt | 9 +++---- .../ddivad/judgebot/commands/UserCommands.kt | 5 ++-- .../judgebot/commands/UtilityCommands.kt | 3 +-- .../conversations/GuildChoiceConversation.kt | 27 ++++++++++--------- .../conversations/InfractionConversation.kt | 2 ++ .../guild/EditConfigConversation.kt | 24 ++++++++--------- .../guild/GuildConfigConversation.kt | 14 +++++----- .../rules/AddRuleConversation.kt | 9 +++---- .../rules/ArchiveRuleConversation.kt | 2 +- .../rules/EditRuleConversation.kt | 16 +++++------ .../judgebot/dataclasses/GuildMember.kt | 5 ---- .../judgebot/dataclasses/Permissions.kt | 1 + .../judgebot/embeds/InfractionEmbeds.kt | 3 +++ .../listeners/MemberReactionListeners.kt | 4 ++- .../listeners/NewChannelOverrideListener.kt | 8 +++--- .../listeners/StaffReactionListeners.kt | 1 - .../judgebot/services/BotStatsService.kt | 3 +-- .../judgebot/services/DatabaseService.kt | 3 +-- .../ddivad/judgebot/services/HelpService.kt | 27 +++++++++---------- .../services/database/JoinLeaveOperations.kt | 1 - .../services/database/UserOperations.kt | 4 --- .../services/infractions/BadPfpService.kt | 1 - .../services/infractions/BadnameService.kt | 4 +-- .../services/infractions/BanService.kt | 3 +-- .../services/infractions/InfractionService.kt | 1 - .../services/infractions/MuteService.kt | 15 +++++++---- 38 files changed, 147 insertions(+), 119 deletions(-) create mode 100644 .github/workflows/discord-release.yml diff --git a/.github/workflows/discord-release.yml b/.github/workflows/discord-release.yml new file mode 100644 index 0000000..b4557a4 --- /dev/null +++ b/.github/workflows/discord-release.yml @@ -0,0 +1,19 @@ +name: Post Release to Discord + +on: + release: + types: + - created + +jobs: + run_main: + runs-on: ubuntu-18.04 + name: Discord Webhook + steps: + - name: Send message + uses: ddivad195/discord-styled-releases@main + with: + project_name: "Judgebot" + embed_colour: "1315909" + webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }} + webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index ec7f2c7..28230fe 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -36,5 +36,5 @@ tasks { object Versions { const val BOT = "1.0.0" - const val DISCORDKT = "0.22.0-SNAPSHOT" + const val DISCORDKT = "0.23.0-SNAPSHOT" } \ No newline at end of file diff --git a/src/main/kotlin/me/ddivad/judgebot/Main.kt b/src/main/kotlin/me/ddivad/judgebot/Main.kt index 43c4ca1..a6a672b 100644 --- a/src/main/kotlin/me/ddivad/judgebot/Main.kt +++ b/src/main/kotlin/me/ddivad/judgebot/Main.kt @@ -1,5 +1,6 @@ package me.ddivad.judgebot +import dev.kord.common.annotation.KordPreview import dev.kord.common.kColor import dev.kord.core.supplier.EntitySupplyStrategy import dev.kord.gateway.Intent @@ -14,8 +15,9 @@ import me.jakejmattson.discordkt.api.dsl.bot import me.jakejmattson.discordkt.api.extensions.addInlineField import java.awt.Color +@KordPreview @PrivilegedIntent -suspend fun main(args: Array) { +suspend fun main() { val token = System.getenv("BOT_TOKEN") ?: null val defaultPrefix = System.getenv("DEFAULT_PREFIX") ?: "j!" @@ -31,7 +33,7 @@ suspend fun main(args: Array) { allowMentionPrefix = true commandReaction = null theme = Color.MAGENTA - entitySupplyStrategy = EntitySupplyStrategy.cacheWithCachingRestFallback + entitySupplyStrategy = EntitySupplyStrategy.cacheWithRestFallback permissions(Permissions.NONE) intents = Intents( Intent.GuildMembers, @@ -67,10 +69,11 @@ suspend fun main(args: Array) { field { name = "Build Info" value = "```" + - "Version: 2.4.1\n" + + "Version: 2.5.0\n" + "DiscordKt: ${versions.library}\n" + + "Kord: ${versions.kord}\n" + "Kotlin: $kotlinVersion" + - "```" + "```" } field { name = "Uptime" diff --git a/src/main/kotlin/me/ddivad/judgebot/arguments/GuildConfigArg.kt b/src/main/kotlin/me/ddivad/judgebot/arguments/GuildConfigArg.kt index a158765..162d53b 100644 --- a/src/main/kotlin/me/ddivad/judgebot/arguments/GuildConfigArg.kt +++ b/src/main/kotlin/me/ddivad/judgebot/arguments/GuildConfigArg.kt @@ -1,7 +1,7 @@ package me.ddivad.judgebot.arguments import me.jakejmattson.discordkt.api.arguments.* -import me.jakejmattson.discordkt.api.dsl.CommandEvent +import me.jakejmattson.discordkt.api.commands.CommandEvent val validConfigParameters = mutableListOf( "setPrefix", @@ -23,7 +23,7 @@ val validConfigParameters = mutableListOf( "options" ) -open class GuildConfigArg(override val name: String = "GuildConfig") : ArgumentType { +open class GuildConfigArg(override val name: String = "GuildConfig") : Argument { override val description = "A Guild configuration" companion object : GuildConfigArg() diff --git a/src/main/kotlin/me/ddivad/judgebot/arguments/LowerMemberArg.kt b/src/main/kotlin/me/ddivad/judgebot/arguments/LowerMemberArg.kt index da78ede..6fafc3f 100644 --- a/src/main/kotlin/me/ddivad/judgebot/arguments/LowerMemberArg.kt +++ b/src/main/kotlin/me/ddivad/judgebot/arguments/LowerMemberArg.kt @@ -2,10 +2,11 @@ package me.ddivad.judgebot.arguments import dev.kord.core.entity.Member import me.jakejmattson.discordkt.api.arguments.* -import me.jakejmattson.discordkt.api.dsl.CommandEvent +import me.jakejmattson.discordkt.api.commands.CommandEvent +import me.jakejmattson.discordkt.api.extensions.isSelf import me.jakejmattson.discordkt.api.extensions.toSnowflakeOrNull -open class LowerMemberArg(override val name: String = "LowerMemberArg") : ArgumentType { +open class LowerMemberArg(override val name: String = "LowerMemberArg") : Argument { companion object : LowerMemberArg() override val description = "A Member with a lower rank" @@ -19,8 +20,9 @@ open class LowerMemberArg(override val name: String = "LowerMemberArg") : Argume val author = event.author.asMember(event.guild!!.id) return when { - event.discord.permissions.isHigherLevel(event.discord, member, author) -> + event.discord.permissions.isHigherLevel(event.discord, member, author) || event.author.isSelf() -> Error("You don't have the permission to use this command on the target user.") + event.author == member -> Error("You can't use this command on yourself!") else -> Success(member) } } diff --git a/src/main/kotlin/me/ddivad/judgebot/arguments/LowerUserArg.kt b/src/main/kotlin/me/ddivad/judgebot/arguments/LowerUserArg.kt index 3349fb1..8a599bd 100644 --- a/src/main/kotlin/me/ddivad/judgebot/arguments/LowerUserArg.kt +++ b/src/main/kotlin/me/ddivad/judgebot/arguments/LowerUserArg.kt @@ -2,10 +2,11 @@ package me.ddivad.judgebot.arguments import dev.kord.core.entity.User import me.jakejmattson.discordkt.api.arguments.* -import me.jakejmattson.discordkt.api.dsl.CommandEvent +import me.jakejmattson.discordkt.api.commands.CommandEvent +import me.jakejmattson.discordkt.api.extensions.isSelf import me.jakejmattson.discordkt.api.extensions.toSnowflakeOrNull -open class LowerUserArg(override val name: String = "LowerUserArg") : ArgumentType { +open class LowerUserArg(override val name: String = "LowerUserArg") : Argument { companion object : LowerUserArg() override val description = "A user with a lower rank" @@ -20,9 +21,12 @@ open class LowerUserArg(override val name: String = "LowerUserArg") : ArgumentTy val author = event.author.asMember(event.guild!!.id) return when { - event.discord.permissions.isHigherLevel(event.discord, member, author) -> + event.discord.permissions.isHigherLevel(event.discord, member, author) || event.author.isSelf() -> Error("You don't have the permission to use this command on the target user.") + event.author == member -> Error("You can't use this command on yourself!") else -> Success(member.asUser()) } } + + override fun formatData(data: User) = "@${data.tag}" } \ No newline at end of file diff --git a/src/main/kotlin/me/ddivad/judgebot/arguments/RuleArg.kt b/src/main/kotlin/me/ddivad/judgebot/arguments/RuleArg.kt index 245dc0a..54ccf1a 100644 --- a/src/main/kotlin/me/ddivad/judgebot/arguments/RuleArg.kt +++ b/src/main/kotlin/me/ddivad/judgebot/arguments/RuleArg.kt @@ -4,9 +4,9 @@ import dev.kord.core.entity.Guild import me.ddivad.judgebot.dataclasses.Rule import me.ddivad.judgebot.services.DatabaseService import me.jakejmattson.discordkt.api.arguments.* -import me.jakejmattson.discordkt.api.dsl.CommandEvent +import me.jakejmattson.discordkt.api.commands.CommandEvent -open class RuleArg(override val name: String = "Rule") : ArgumentType { +open class RuleArg(override val name: String = "Rule") : Argument { override val description = "A rule number" override suspend fun generateExamples(event: CommandEvent<*>): List = mutableListOf("1", "2", "3") diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/GuildCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/GuildCommands.kt index f7e1ba2..9318621 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/GuildCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/GuildCommands.kt @@ -8,8 +8,9 @@ import me.ddivad.judgebot.dataclasses.Permissions import me.ddivad.judgebot.embeds.createActivePunishmentsEmbed import me.ddivad.judgebot.services.DatabaseService import me.ddivad.judgebot.services.infractions.MuteService -import me.jakejmattson.discordkt.api.dsl.commands +import me.jakejmattson.discordkt.api.commands.commands +@Suppress("unused") fun guildConfigCommands(configuration: Configuration, databaseService: DatabaseService, muteService: MuteService) = commands("Guild") { diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/InfoCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/InfoCommands.kt index 10a59e0..05d8979 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/InfoCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/InfoCommands.kt @@ -11,7 +11,7 @@ import me.ddivad.judgebot.extensions.testDmStatus import me.ddivad.judgebot.services.DatabaseService import me.jakejmattson.discordkt.api.arguments.EveryArg import me.jakejmattson.discordkt.api.arguments.IntegerArg -import me.jakejmattson.discordkt.api.dsl.commands +import me.jakejmattson.discordkt.api.commands.commands import me.jakejmattson.discordkt.api.extensions.sendPrivateMessage @Suppress("unused") diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/InfractionCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/InfractionCommands.kt index 595bdbd..000b5ca 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/InfractionCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/InfractionCommands.kt @@ -1,5 +1,6 @@ package me.ddivad.judgebot.commands +import dev.kord.common.annotation.KordPreview import me.ddivad.judgebot.arguments.LowerUserArg import dev.kord.common.exception.RequestException import dev.kord.core.behavior.reply @@ -19,9 +20,10 @@ import me.ddivad.judgebot.services.infractions.InfractionService import me.jakejmattson.discordkt.api.arguments.BooleanArg import me.jakejmattson.discordkt.api.arguments.EveryArg import me.jakejmattson.discordkt.api.arguments.IntegerArg +import me.jakejmattson.discordkt.api.commands.commands import me.jakejmattson.discordkt.api.conversations.ConversationResult -import me.jakejmattson.discordkt.api.dsl.commands +@KordPreview @Suppress("unused") fun createInfractionCommands(databaseService: DatabaseService, config: Configuration, diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt index e8000fe..412a7ac 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt @@ -11,7 +11,7 @@ import me.ddivad.judgebot.services.infractions.RoleState import me.ddivad.judgebot.util.timeToString import me.jakejmattson.discordkt.api.arguments.EveryArg import me.jakejmattson.discordkt.api.arguments.TimeArg -import me.jakejmattson.discordkt.api.dsl.commands +import me.jakejmattson.discordkt.api.commands.commands import kotlin.math.roundToLong @Suppress("unused") diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/NoteCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/NoteCommands.kt index db1822e..9e4c36d 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/NoteCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/NoteCommands.kt @@ -6,7 +6,7 @@ import me.ddivad.judgebot.services.DatabaseService import me.jakejmattson.discordkt.api.arguments.EveryArg import me.jakejmattson.discordkt.api.arguments.IntegerArg import me.jakejmattson.discordkt.api.arguments.UserArg -import me.jakejmattson.discordkt.api.dsl.commands +import me.jakejmattson.discordkt.api.commands.commands @Suppress("unused") fun noteCommands(databaseService: DatabaseService) = commands("Note") { diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/RuleCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/RuleCommands.kt index b97f9cd..08883e1 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/RuleCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/RuleCommands.kt @@ -12,12 +12,11 @@ import me.ddivad.judgebot.embeds.createRulesEmbed import me.ddivad.judgebot.embeds.createRulesEmbedDetailed import me.ddivad.judgebot.services.DatabaseService import me.jakejmattson.discordkt.api.arguments.MessageArg -import me.jakejmattson.discordkt.api.dsl.commands +import me.jakejmattson.discordkt.api.commands.commands import me.jakejmattson.discordkt.api.extensions.jumpLink @Suppress("unused") -fun ruleCommands(configuration: Configuration, - databaseService: DatabaseService) = commands("Rule") { +fun ruleCommands(databaseService: DatabaseService) = commands("Rule") { guildCommand("addRule") { description = "Add a rule to this guild." @@ -55,7 +54,7 @@ fun ruleCommands(configuration: Configuration, execute(MessageArg.optionalNullable(null)) { val messageToEdit = args.first if (messageToEdit != null) { - messageToEdit.edit { this.embed { createRulesEmbed(guild, databaseService.guilds.getRules(guild)) } } + messageToEdit.edit { this.embeds?.first()?.createRulesEmbed(guild, databaseService.guilds.getRules(guild)) } respond("Existing embed updated: ${messageToEdit.jumpLink()}") } else { respond { @@ -71,7 +70,7 @@ fun ruleCommands(configuration: Configuration, execute(MessageArg.optionalNullable(null)) { val messageToEdit = args.first if (messageToEdit != null) { - messageToEdit.edit { this.embed { createRulesEmbedDetailed(guild, databaseService.guilds.getRules(guild)) } } + messageToEdit.edit { embeds?.first()?.createRulesEmbedDetailed(guild, databaseService.guilds.getRules(guild))} respond("Existing embed updated: ${messageToEdit.jumpLink()}") } else { respond { diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt index 1d45566..78da5ab 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt @@ -15,7 +15,7 @@ import me.ddivad.judgebot.services.DatabaseService import me.ddivad.judgebot.services.LoggingService import me.ddivad.judgebot.services.infractions.BanService import me.jakejmattson.discordkt.api.arguments.* -import me.jakejmattson.discordkt.api.dsl.commands +import me.jakejmattson.discordkt.api.commands.commands import me.jakejmattson.discordkt.api.extensions.mutualGuilds import me.jakejmattson.discordkt.api.extensions.sendPrivateMessage import java.awt.Color @@ -33,7 +33,6 @@ fun createUserCommands( execute(UserArg) { val user = databaseService.users.getOrCreateUser(args.first, guild) databaseService.users.incrementUserHistory(user, guild) - val linkedAccounts = user.getLinkedAccounts(guild) respondMenu { createHistoryEmbed(args.first, user, guild, config, databaseService) } @@ -148,7 +147,7 @@ fun createUserCommands( user.sendPrivateMessage { createSelfHistoryEmbed(user, guildMember, currentGuild, config) } - this.message.addReaction(Emojis.whiteCheckMark) + this.message?.addReaction(Emojis.whiteCheckMark) } else { guildChoiceConversation(mutualGuilds, config).startPrivately(discord, author) } diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/UtilityCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/UtilityCommands.kt index b853eb4..e17f1dc 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/UtilityCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/UtilityCommands.kt @@ -3,8 +3,7 @@ package me.ddivad.judgebot.commands import me.ddivad.judgebot.dataclasses.Permissions import me.ddivad.judgebot.services.HelpService import me.jakejmattson.discordkt.api.arguments.AnyArg -import me.jakejmattson.discordkt.api.arguments.CommandArg -import me.jakejmattson.discordkt.api.dsl.commands +import me.jakejmattson.discordkt.api.commands.commands @Suppress("unused") fun createInformationCommands(helpService: HelpService) = commands("Utility") { diff --git a/src/main/kotlin/me/ddivad/judgebot/conversations/GuildChoiceConversation.kt b/src/main/kotlin/me/ddivad/judgebot/conversations/GuildChoiceConversation.kt index c3c355c..e71392a 100644 --- a/src/main/kotlin/me/ddivad/judgebot/conversations/GuildChoiceConversation.kt +++ b/src/main/kotlin/me/ddivad/judgebot/conversations/GuildChoiceConversation.kt @@ -5,7 +5,6 @@ import dev.kord.core.entity.Guild import me.ddivad.judgebot.dataclasses.Configuration import me.ddivad.judgebot.embeds.createSelfHistoryEmbed import me.ddivad.judgebot.services.DatabaseService -import me.jakejmattson.discordkt.api.arguments.IntegerRangeArg import me.jakejmattson.discordkt.api.conversations.conversation import java.awt.Color @@ -14,21 +13,25 @@ fun guildChoiceConversation( configuration: Configuration ) = conversation { val databaseService = discord.getInjectionObjects(DatabaseService::class) - val guildIndex = promptEmbed(IntegerRangeArg(1, guilds.size)) { - title = "Select Server" - description = "Respond with the server you want to view your history for." - thumbnail { - url = discord.kord.getSelf().avatar.url + val guild = promptButton { + embed { + color = Color.MAGENTA.kColor + title = "Select Server" + description = "Select the server you to view history for." + thumbnail { + url = discord.kord.getSelf().avatar.url + } } - color = Color.MAGENTA.kColor - guilds.toList().forEachIndexed { index, guild -> - field { - name = "${index + 1}) ${guild.name}" + + guilds.toList().chunked(5).forEach { row -> + buttons { + row.forEach { guild -> + button(guild.name, null, guild) + } } } - } - 1 + } - val guild = guilds[guildIndex] val guildMember = databaseService.users.getOrCreateUser(user, guild) respond { diff --git a/src/main/kotlin/me/ddivad/judgebot/conversations/InfractionConversation.kt b/src/main/kotlin/me/ddivad/judgebot/conversations/InfractionConversation.kt index 3bd416d..0afbf21 100644 --- a/src/main/kotlin/me/ddivad/judgebot/conversations/InfractionConversation.kt +++ b/src/main/kotlin/me/ddivad/judgebot/conversations/InfractionConversation.kt @@ -1,5 +1,6 @@ package me.ddivad.judgebot.conversations +import dev.kord.common.annotation.KordPreview import dev.kord.common.entity.ButtonStyle import dev.kord.core.entity.Guild import dev.kord.core.entity.Member @@ -10,6 +11,7 @@ import me.ddivad.judgebot.services.DatabaseService import me.ddivad.judgebot.services.infractions.InfractionService import me.jakejmattson.discordkt.api.conversations.conversation +@KordPreview class InfractionConversation( private val databaseService: DatabaseService, private val configuration: Configuration, diff --git a/src/main/kotlin/me/ddivad/judgebot/conversations/guild/EditConfigConversation.kt b/src/main/kotlin/me/ddivad/judgebot/conversations/guild/EditConfigConversation.kt index 8a1462f..d28fce8 100644 --- a/src/main/kotlin/me/ddivad/judgebot/conversations/guild/EditConfigConversation.kt +++ b/src/main/kotlin/me/ddivad/judgebot/conversations/guild/EditConfigConversation.kt @@ -14,17 +14,17 @@ class EditConfigConversation(private val configuration: Configuration) { val guildConfiguration = configuration[guild.id.value]!! when (parameter) { "addadminrole" -> { - val role = promptMessage(RoleArg, "Enter Admin role:") + val role = prompt(RoleArg, "Enter Admin role:") guildConfiguration.adminRoles.add(role.id.asString) respond("Added **${role.name}** to Admin roles.") } "addstaffrole" -> { - val role = promptMessage(RoleArg, "Enter Staff role:") + val role = prompt(RoleArg, "Enter Staff role:") guildConfiguration.staffRoles.add(role.id.asString) respond("Added **${role.name}** to Staff roles.") } "addmoderatorrole" -> { - val role = promptMessage(RoleArg, "Enter Moderator role:") + val role = prompt(RoleArg, "Enter Moderator role:") guildConfiguration.moderatorRoles.add(role.id.asString) respond("Added **${role.name}** to moderator roles.") } @@ -59,47 +59,47 @@ class EditConfigConversation(private val configuration: Configuration) { respond("Removed **${role.name}** from Moderator roles.") } "setmutedrole" -> { - val mutedRole = promptMessage(RoleArg, "Enter Mute role:") + val mutedRole = prompt(RoleArg, "Enter Mute role:") guildConfiguration.mutedRole = mutedRole.id.asString respond("Muted role set to **${mutedRole.name}**.") } "setlogchannel" -> { - val logChannel = promptMessage(ChannelArg(), "Enter Logging channel:") + val logChannel = prompt(ChannelArg(), "Enter Logging channel:") guildConfiguration.loggingConfiguration.loggingChannel = logChannel.id.asString respond("Log channel set to ${logChannel.mention}") } "setalertchannel" -> { - val alertChannel = promptMessage(ChannelArg(), "Enter Logging channel:") + val alertChannel = prompt(ChannelArg(), "Enter Logging channel:") guildConfiguration.loggingConfiguration.alertChannel = alertChannel.id.asString respond("Alert channel set to ${alertChannel.mention}") } "setprefix" -> { - val prefix = promptMessage(EveryArg, "Enter Prefix:") + val prefix = prompt(EveryArg, "Enter Prefix:") guildConfiguration.prefix = prefix respond("Prefix set to **${prefix}**") } "setgagreaction" -> { - val reaction = promptMessage(UnicodeEmojiArg, "Enter Reaction:") + val reaction = prompt(UnicodeEmojiArg, "Enter Reaction:") guildConfiguration.reactions.gagReaction = reaction.unicode respond("Reaction set to ${reaction.unicode}") } "sethistoryreaction" -> { - val reaction = promptMessage(UnicodeEmojiArg, "Enter Reaction:") + val reaction = prompt(UnicodeEmojiArg, "Enter Reaction:") guildConfiguration.reactions.historyReaction = reaction.unicode respond("Reaction set to ${reaction.unicode}") } "setdeletemessagereaction" -> { - val reaction = promptMessage(UnicodeEmojiArg, "Enter Reaction:") + val reaction = prompt(UnicodeEmojiArg, "Enter Reaction:") guildConfiguration.reactions.deleteMessageReaction = reaction.unicode respond("Reaction set to ${reaction.unicode}") } "setflagmessagereaction" -> { - val reaction = promptMessage(UnicodeEmojiArg, "Enter Reaction:") + val reaction = prompt(UnicodeEmojiArg, "Enter Reaction:") guildConfiguration.reactions.flagMessageReaction = reaction.unicode respond("Reaction set to ${reaction.unicode}") } "enablereactions" -> { - val enabled = promptMessage(BooleanArg("reaactions", "enable", "disable"), "enable / disable:") + val enabled = prompt(BooleanArg("reaactions", "enable", "disable"), "enable / disable:") guildConfiguration.reactions.enabled = enabled respond("Reactions set to $enabled") } diff --git a/src/main/kotlin/me/ddivad/judgebot/conversations/guild/GuildConfigConversation.kt b/src/main/kotlin/me/ddivad/judgebot/conversations/guild/GuildConfigConversation.kt index 5ee9d85..1e0a750 100644 --- a/src/main/kotlin/me/ddivad/judgebot/conversations/guild/GuildConfigConversation.kt +++ b/src/main/kotlin/me/ddivad/judgebot/conversations/guild/GuildConfigConversation.kt @@ -11,13 +11,13 @@ import me.jakejmattson.discordkt.api.conversations.conversation class GuildSetupConversation(private val configuration: Configuration, private val muteService: MuteService) { fun createSetupConversation(guild: Guild) = conversation("cancel") { - val prefix = promptMessage(EveryArg, "Bot prefix:") - val adminRole = promptMessage(RoleArg, "Admin role:") - val staffRole = promptMessage(RoleArg, "Staff role:") - val moderatorRole = promptMessage(RoleArg, "Moderator role:") - val logChannel = promptMessage(ChannelArg, "Log Channel:") - val alertChannel = promptMessage(ChannelArg, "Alert Channel:") - val mutedRole = promptMessage(RoleArg, "Muted role:") + val prefix = prompt(EveryArg, "Bot prefix:") + val adminRole = prompt(RoleArg, "Admin role:") + val staffRole = prompt(RoleArg, "Staff role:") + val moderatorRole = prompt(RoleArg, "Moderator role:") + val logChannel = prompt(ChannelArg, "Log Channel:") + val alertChannel = prompt(ChannelArg, "Alert Channel:") + val mutedRole = prompt(RoleArg, "Muted role:") configuration.setup( guild, diff --git a/src/main/kotlin/me/ddivad/judgebot/conversations/rules/AddRuleConversation.kt b/src/main/kotlin/me/ddivad/judgebot/conversations/rules/AddRuleConversation.kt index 8653790..4b34779 100644 --- a/src/main/kotlin/me/ddivad/judgebot/conversations/rules/AddRuleConversation.kt +++ b/src/main/kotlin/me/ddivad/judgebot/conversations/rules/AddRuleConversation.kt @@ -1,7 +1,6 @@ package me.ddivad.judgebot.conversations.rules import dev.kord.core.entity.Guild -import me.ddivad.judgebot.dataclasses.Configuration import me.ddivad.judgebot.dataclasses.Rule import me.ddivad.judgebot.embeds.createRuleEmbed import me.ddivad.judgebot.services.DatabaseService @@ -15,12 +14,12 @@ class AddRuleConversation(private val databaseService: DatabaseService) { val rules = databaseService.guilds.getRules(guild) val nextId = rules.size.plus(1) - val ruleName = promptMessage(EveryArg, "Please enter rule name:") - val ruleText = promptMessage(EveryArg, "Please enter rule text") - val addLink = promptMessage(BooleanArg("Add link to rule?", "Y", "N"), + val ruleName = prompt(EveryArg, "Please enter rule name:") + val ruleText = prompt(EveryArg, "Please enter rule text") + val addLink = prompt(BooleanArg("Add link to rule?", "Y", "N"), "Do you want to add a link to the rule? (Y/N)") val ruleLink = when { - addLink -> promptMessage(UrlArg, "Please enter the link") + addLink -> prompt(UrlArg, "Please enter the link") else -> "" } diff --git a/src/main/kotlin/me/ddivad/judgebot/conversations/rules/ArchiveRuleConversation.kt b/src/main/kotlin/me/ddivad/judgebot/conversations/rules/ArchiveRuleConversation.kt index 6ebc560..72aa069 100644 --- a/src/main/kotlin/me/ddivad/judgebot/conversations/rules/ArchiveRuleConversation.kt +++ b/src/main/kotlin/me/ddivad/judgebot/conversations/rules/ArchiveRuleConversation.kt @@ -7,7 +7,7 @@ import me.jakejmattson.discordkt.api.conversations.conversation class ArchiveRuleConversation(private val databaseService: DatabaseService) { fun createArchiveRuleConversation(guild: Guild) = conversation("cancel") { - val ruleToArchive = promptMessage(IntegerArg, "Please enter rule number to archive:") + val ruleToArchive = prompt(IntegerArg, "Please enter rule number to archive:") databaseService.guilds.archiveRule(guild, ruleToArchive) respond("Rule archived.") diff --git a/src/main/kotlin/me/ddivad/judgebot/conversations/rules/EditRuleConversation.kt b/src/main/kotlin/me/ddivad/judgebot/conversations/rules/EditRuleConversation.kt index 17b0cf2..b80e011 100644 --- a/src/main/kotlin/me/ddivad/judgebot/conversations/rules/EditRuleConversation.kt +++ b/src/main/kotlin/me/ddivad/judgebot/conversations/rules/EditRuleConversation.kt @@ -13,25 +13,25 @@ import me.jakejmattson.discordkt.api.conversations.conversation class EditRuleConversation(private val databaseService: DatabaseService) { fun createAddRuleConversation(guild: Guild) = conversation("cancel") { val rules = databaseService.guilds.getRules(guild) - val ruleNumberToUpdate = promptMessage(IntegerArg, "Which rule would you like to update?") + val ruleNumberToUpdate = prompt(IntegerArg, "Which rule would you like to update?") val ruleToUpdate = rules.find { it.number == ruleNumberToUpdate } ?: return@conversation respond("Current Rule:") respond { createRuleEmbed(guild, ruleToUpdate) } - val updateNumber = promptMessage(BooleanArg(truthValue = "y", falseValue = "n"), + val updateNumber = prompt(BooleanArg(truthValue = "y", falseValue = "n"), "Update Rule number? (Y/N)") val ruleNumber = when { updateNumber -> promptUntil( - argumentType = IntegerArg, + argument = IntegerArg, prompt = "Please enter rule number:", isValid = { number -> !rules.any { it.number == number } }, error = "Rule with that number already exists" ) else -> ruleToUpdate.number } - val updateName = promptMessage(BooleanArg(truthValue = "y", falseValue = "n"), + val updateName = prompt(BooleanArg(truthValue = "y", falseValue = "n"), "Update Rule name? (Y/N)") val ruleName = when { updateName -> promptUntil( @@ -43,17 +43,17 @@ class EditRuleConversation(private val databaseService: DatabaseService) { else -> ruleToUpdate.title } - val updateText = promptMessage(BooleanArg(truthValue = "y", falseValue = "n"), + val updateText = prompt(BooleanArg(truthValue = "y", falseValue = "n"), "Update Rule text? (Y/N)") val ruleText = when { - updateText -> promptMessage(EveryArg, "Please enter rule text:") + updateText -> prompt(EveryArg, "Please enter rule text:") else -> ruleToUpdate.description } - val updateLink = promptMessage(BooleanArg(truthValue = "y", falseValue = "n"), + val updateLink = prompt(BooleanArg(truthValue = "y", falseValue = "n"), "Update Rule link? (Y/N)") val ruleLink = when { - updateLink -> promptMessage(UrlArg, "Please enter the link") + updateLink -> prompt(UrlArg, "Please enter the link") else -> ruleToUpdate.link } diff --git a/src/main/kotlin/me/ddivad/judgebot/dataclasses/GuildMember.kt b/src/main/kotlin/me/ddivad/judgebot/dataclasses/GuildMember.kt index b67bb9d..322f2f0 100644 --- a/src/main/kotlin/me/ddivad/judgebot/dataclasses/GuildMember.kt +++ b/src/main/kotlin/me/ddivad/judgebot/dataclasses/GuildMember.kt @@ -4,11 +4,6 @@ import dev.kord.core.entity.Guild import org.joda.time.DateTime import org.joda.time.Weeks -data class GuildLeave( - val joinDate: Long, - var leaveDate: Long? -) - data class GuildMemberDetails( val guildId: String, val notes: MutableList = mutableListOf(), diff --git a/src/main/kotlin/me/ddivad/judgebot/dataclasses/Permissions.kt b/src/main/kotlin/me/ddivad/judgebot/dataclasses/Permissions.kt index ea3d346..9d61206 100644 --- a/src/main/kotlin/me/ddivad/judgebot/dataclasses/Permissions.kt +++ b/src/main/kotlin/me/ddivad/judgebot/dataclasses/Permissions.kt @@ -5,6 +5,7 @@ import dev.kord.core.any import me.jakejmattson.discordkt.api.dsl.PermissionContext import me.jakejmattson.discordkt.api.dsl.PermissionSet +@Suppress("unused") enum class Permissions : PermissionSet { BOT_OWNER { override suspend fun hasPermission(context: PermissionContext) = diff --git a/src/main/kotlin/me/ddivad/judgebot/embeds/InfractionEmbeds.kt b/src/main/kotlin/me/ddivad/judgebot/embeds/InfractionEmbeds.kt index e5e9918..2a00d04 100644 --- a/src/main/kotlin/me/ddivad/judgebot/embeds/InfractionEmbeds.kt +++ b/src/main/kotlin/me/ddivad/judgebot/embeds/InfractionEmbeds.kt @@ -187,6 +187,9 @@ fun EmbedBuilder.createMessageDeleteEmbed(guild: Guild, message: Message) { if (message.attachments.isNotEmpty()) { addField("Filename", "```${message.attachments.first().filename}```") } + field { + value = "If you think this to be unjustified, please **do not** post about it in a public channel but take it up with Modmail." + } footer { icon = guild.getIconUrl(Image.Format.PNG) ?: "" text = guild.name diff --git a/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt b/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt index 5ca3884..556b597 100644 --- a/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt +++ b/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt @@ -1,7 +1,9 @@ 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 @@ -26,7 +28,7 @@ fun onMemberReactionAdd(configuration: Configuration) = listeners { .createMessage( "**Message Flagged**" + "\n**User**: ${user.mention}" + - "\n**Channel**: ${message.channel.mention}" + + (if(message.getChannel().type == ChannelType.PublicGuildThread) "\n**Thread**: " else "\n**Channel**: ") + message.channel.mention + "\n**Author:** ${message.asMessage().author?.mention}" + "\n**Message:** ${message.asMessage().jumpLink()}" ) diff --git a/src/main/kotlin/me/ddivad/judgebot/listeners/NewChannelOverrideListener.kt b/src/main/kotlin/me/ddivad/judgebot/listeners/NewChannelOverrideListener.kt index 6e75e4a..75d5e0c 100644 --- a/src/main/kotlin/me/ddivad/judgebot/listeners/NewChannelOverrideListener.kt +++ b/src/main/kotlin/me/ddivad/judgebot/listeners/NewChannelOverrideListener.kt @@ -4,6 +4,7 @@ import dev.kord.common.entity.Permission import dev.kord.common.entity.Permissions import dev.kord.core.entity.PermissionOverwrite import dev.kord.core.event.channel.TextChannelCreateEvent +import dev.kord.core.event.channel.thread.ThreadChannelCreateEvent import me.ddivad.judgebot.dataclasses.Configuration import me.ddivad.judgebot.services.LoggingService import me.jakejmattson.discordkt.api.dsl.listeners @@ -17,12 +18,13 @@ fun onChannelCreated(configuration: Configuration, loggingService: LoggingServic val guildConfiguration = configuration[guild.id.value] ?: return@on val mutedRole = guild.getRole(guildConfiguration.mutedRole.toSnowflake()) val deniedPermissions = channel.getPermissionOverwritesForRole(mutedRole.id)?.denied ?: Permissions() - if (!deniedPermissions.contains(Permission.SendMessages) || !deniedPermissions.contains(Permission.AddReactions)) { + if (deniedPermissions.values.any { it in setOf(Permission.SendMessages, Permission.AddReactions, Permission.UsePublicThreads, Permission.UsePrivateThreads) }) { channel.addOverwrite( PermissionOverwrite.forRole( mutedRole.id, - denied = deniedPermissions.plus(Permission.SendMessages).plus(Permission.AddReactions) - ) + denied = deniedPermissions.plus(Permission.SendMessages).plus(Permission.AddReactions).plus(Permission.UsePublicThreads).plus(Permission.UsePrivateThreads) + ), + "Judgebot Overwrite" ) loggingService.channelOverrideAdded(guild, channel) } diff --git a/src/main/kotlin/me/ddivad/judgebot/listeners/StaffReactionListeners.kt b/src/main/kotlin/me/ddivad/judgebot/listeners/StaffReactionListeners.kt index 7f342c4..5dbb74f 100644 --- a/src/main/kotlin/me/ddivad/judgebot/listeners/StaffReactionListeners.kt +++ b/src/main/kotlin/me/ddivad/judgebot/listeners/StaffReactionListeners.kt @@ -57,7 +57,6 @@ fun onStaffReactionAdd( loggingService.staffReactionUsed(guild, staffMember, messageAuthor, this.emoji) } guildConfiguration.reactions.deleteMessageReaction -> { - msg.deleteReaction(this.emoji) msg.delete() databaseService.users.addMessageDelete( guild, diff --git a/src/main/kotlin/me/ddivad/judgebot/services/BotStatsService.kt b/src/main/kotlin/me/ddivad/judgebot/services/BotStatsService.kt index 67ce4cc..758877e 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/BotStatsService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/BotStatsService.kt @@ -1,13 +1,12 @@ package me.ddivad.judgebot.services -import me.ddivad.judgebot.dataclasses.Configuration import me.ddivad.judgebot.util.timeToString import me.jakejmattson.discordkt.api.Discord import me.jakejmattson.discordkt.api.annotations.Service import java.util.* @Service -class BotStatsService(private val configuration: Configuration, private val discord: Discord) { +class BotStatsService(private val discord: Discord) { private var startTime: Date = Date() val uptime: String diff --git a/src/main/kotlin/me/ddivad/judgebot/services/DatabaseService.kt b/src/main/kotlin/me/ddivad/judgebot/services/DatabaseService.kt index 554bd73..cec4e72 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/DatabaseService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/DatabaseService.kt @@ -10,5 +10,4 @@ open class DatabaseService( val users: UserOperations, val guilds: GuildOperations, val joinLeaves: JoinLeaveOperations -) { -} \ No newline at end of file +) \ No newline at end of file diff --git a/src/main/kotlin/me/ddivad/judgebot/services/HelpService.kt b/src/main/kotlin/me/ddivad/judgebot/services/HelpService.kt index 1b85719..7ee8cc2 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/HelpService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/HelpService.kt @@ -1,22 +1,21 @@ package me.ddivad.judgebot.services +import dev.kord.common.annotation.KordPreview import dev.kord.common.entity.ButtonStyle import dev.kord.common.kColor -import dev.kord.core.entity.Guild -import dev.kord.core.entity.User import dev.kord.x.emoji.DiscordEmoji import dev.kord.x.emoji.Emojis import kotlinx.coroutines.runBlocking -import me.jakejmattson.discordkt.api.Discord import me.jakejmattson.discordkt.api.annotations.Service -import me.jakejmattson.discordkt.api.arguments.ArgumentType +import me.jakejmattson.discordkt.api.arguments.Argument import me.jakejmattson.discordkt.api.arguments.OptionalArg -import me.jakejmattson.discordkt.api.dsl.Command -import me.jakejmattson.discordkt.api.dsl.CommandEvent -import me.jakejmattson.discordkt.api.dsl.Execution +import me.jakejmattson.discordkt.api.commands.Command +import me.jakejmattson.discordkt.api.commands.CommandEvent +import me.jakejmattson.discordkt.api.commands.Execution +@KordPreview @Service -class HelpService(private val discord: Discord) { +class HelpService { suspend fun buildHelpEmbed(event: CommandEvent<*>) = event.respondMenu { val container = event.discord.commands fun joinNames(value: List) = @@ -57,7 +56,7 @@ class HelpService(private val discord: Discord) { field { name = "Don't see what you're looking for?" - value = "Try `search `. If the command exists in a bot, it will react with ${Emojis.whiteCheckMark}" + value = "Try `search `. If the command exists in a bot, it will react with ${Emojis.whiteCheckMark}" } } } @@ -65,7 +64,7 @@ class HelpService(private val discord: Discord) { categoryNames.chunked(5).forEachIndexed { index, category -> buttons { category.forEachIndexed { page, name -> - button("$name", getEmojiForCategory(name), ButtonStyle.Secondary) { + button(name, getEmojiForCategory(name), ButtonStyle.Secondary) { loadPage(page + index * 5) } } @@ -88,9 +87,9 @@ class HelpService(private val discord: Discord) { } } - suspend fun sendHelpEmbed(event: CommandEvent<*>, command: Command) = event.respond() { + suspend fun sendHelpEmbed(event: CommandEvent<*>, command: Command) = event.respond { color = event.discord.configuration.theme?.kColor - title = "${command.names.joinToString(", ")}" + title = command.names.joinToString(", ") description = command.description val commandInvocation = "${event.prefix()}${command.names.first()}" @@ -105,11 +104,11 @@ class HelpService(private val discord: Discord) { """.trimMargin() } field { - this.value = helpBundle!!.joinToString("\n\n") { it } + this.value = helpBundle.joinToString("\n\n") { it } } } - private fun ArgumentType<*>.generateExample(event: CommandEvent<*>) = + private fun Argument<*>.generateExample(event: CommandEvent<*>) = runBlocking { generateExamples(event) } .takeIf { it.isNotEmpty() } ?.random() diff --git a/src/main/kotlin/me/ddivad/judgebot/services/database/JoinLeaveOperations.kt b/src/main/kotlin/me/ddivad/judgebot/services/database/JoinLeaveOperations.kt index d818490..39250d2 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/database/JoinLeaveOperations.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/database/JoinLeaveOperations.kt @@ -1,7 +1,6 @@ package me.ddivad.judgebot.services.database import dev.kord.core.entity.Member -import dev.kord.core.entity.User import me.ddivad.judgebot.dataclasses.JoinLeave import me.jakejmattson.discordkt.api.annotations.Service import org.joda.time.DateTime diff --git a/src/main/kotlin/me/ddivad/judgebot/services/database/UserOperations.kt b/src/main/kotlin/me/ddivad/judgebot/services/database/UserOperations.kt index e1f9632..b382e76 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/database/UserOperations.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/database/UserOperations.kt @@ -35,10 +35,6 @@ class UserOperations( } } - suspend fun getUserOrNull(target: User): GuildMember? { - return userCollection.findOne(GuildMember::userId eq target.id.asString) - } - suspend fun addNote(guild: Guild, user: GuildMember, note: String, moderator: String): GuildMember { user.addNote(note, moderator, guild) return this.updateUser(user) diff --git a/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadPfpService.kt b/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadPfpService.kt index 6334fd7..ecf1bd6 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadPfpService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadPfpService.kt @@ -9,7 +9,6 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.launch import me.ddivad.judgebot.embeds.createBadPfpEmbed -import me.ddivad.judgebot.embeds.createUnmuteEmbed import me.ddivad.judgebot.services.LoggingService import me.jakejmattson.discordkt.api.Discord import me.jakejmattson.discordkt.api.annotations.Service diff --git a/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadnameService.kt b/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadnameService.kt index 37af2eb..4a7d60c 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadnameService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadnameService.kt @@ -4,12 +4,12 @@ import dev.kord.core.behavior.edit import dev.kord.core.entity.Member import me.jakejmattson.discordkt.api.annotations.Service -val names = mutableListOf( +val names = mutableListOf( "Stephen","Bob","Joe","Timmy","Arnold","Jeff","Tim","Doug" ) @Service -class BadnameService() { +class BadnameService { suspend fun chooseRandomNickname(member: Member) { member.edit { nickname = names.random() } } diff --git a/src/main/kotlin/me/ddivad/judgebot/services/infractions/BanService.kt b/src/main/kotlin/me/ddivad/judgebot/services/infractions/BanService.kt index 42b6839..c544430 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/infractions/BanService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/infractions/BanService.kt @@ -2,7 +2,6 @@ package me.ddivad.judgebot.services.infractions import dev.kord.core.behavior.ban import dev.kord.core.entity.Guild -import dev.kord.core.entity.Member import dev.kord.core.entity.User import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job @@ -58,7 +57,7 @@ class BanService( try { configuration.guildConfigurations.forEach { config -> val guild = config.value.id.toSnowflake().let { discord.kord.getGuild(it) } ?: return@forEach - databaseService.guilds.getPunishmentsForGuild(guild, InfractionType.Ban).forEach() { + databaseService.guilds.getPunishmentsForGuild(guild, InfractionType.Ban).forEach { if (it.clearTime != null) { val difference = it.clearTime - DateTime.now().millis guild.kord.getUser(it.userId.toSnowflake())?.let { user -> diff --git a/src/main/kotlin/me/ddivad/judgebot/services/infractions/InfractionService.kt b/src/main/kotlin/me/ddivad/judgebot/services/infractions/InfractionService.kt index 938803d..7e9f205 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/infractions/InfractionService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/infractions/InfractionService.kt @@ -6,7 +6,6 @@ import dev.kord.core.entity.Member import kotlinx.coroutines.Job import me.ddivad.judgebot.dataclasses.* import me.ddivad.judgebot.embeds.createInfractionEmbed -import me.ddivad.judgebot.embeds.createUnmuteEmbed import me.ddivad.judgebot.services.DatabaseService import me.ddivad.judgebot.services.LoggingService import me.jakejmattson.discordkt.api.annotations.Service diff --git a/src/main/kotlin/me/ddivad/judgebot/services/infractions/MuteService.kt b/src/main/kotlin/me/ddivad/judgebot/services/infractions/MuteService.kt index ca850b6..cf7c764 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/infractions/MuteService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/infractions/MuteService.kt @@ -7,6 +7,7 @@ import dev.kord.core.entity.Guild import dev.kord.core.entity.Member import dev.kord.core.entity.PermissionOverwrite import dev.kord.core.entity.User +import dev.kord.core.supplier.EntitySupplyStrategy import kotlinx.coroutines.Job import kotlinx.coroutines.flow.toList import kotlinx.coroutines.runBlocking @@ -160,14 +161,18 @@ class MuteService(val configuration: Configuration, private suspend fun setupMutedRole(guild: Guild) { val mutedRole = guild.getRole(configuration[guild.id.value]!!.mutedRole.toSnowflake()) - guild.channels.toList().forEach { + guild.withStrategy(EntitySupplyStrategy.cachingRest).channels.toList().forEach { val deniedPermissions = it.getPermissionOverwritesForRole(mutedRole.id)?.denied ?: Permissions() - if (!deniedPermissions.contains(Permission.SendMessages) || !deniedPermissions.contains(Permission.AddReactions)) { + if (deniedPermissions.values.any { permission -> permission in setOf(Permission.SendMessages, Permission.AddReactions, Permission.UsePublicThreads, Permission.UsePrivateThreads) }) { try { + it.addOverwrite( - PermissionOverwrite.forRole( - mutedRole.id, - denied = deniedPermissions.plus(Permission.SendMessages).plus(Permission.AddReactions)) + PermissionOverwrite.forRole( + mutedRole.id, + denied = deniedPermissions.plus(Permission.SendMessages).plus(Permission.AddReactions) + .plus(Permission.UsePublicThreads).plus(Permission.UsePrivateThreads) + ), + "Judgebot Overwrite" ) } catch (ex: RequestException) { println("No permssions to add overwrite to ${it.id.value} - ${it.name}") From c69ea37070eebb978fb147ed4641d63b8ea4a2d5 Mon Sep 17 00:00:00 2001 From: ddivad195 Date: Mon, 16 Aug 2021 13:47:22 +0100 Subject: [PATCH 2/2] feat: add parent channel mention to flagged messages inside threads --- .../ddivad/judgebot/listeners/MemberReactionListeners.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt b/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt index 556b597..cffa058 100644 --- a/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt +++ b/src/main/kotlin/me/ddivad/judgebot/listeners/MemberReactionListeners.kt @@ -22,13 +22,18 @@ fun onMemberReactionAdd(configuration: Configuration) = listeners { when (this.emoji.name) { 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(message.getChannel().type == ChannelType.PublicGuildThread) "\n**Thread**: " else "\n**Channel**: ") + message.channel.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()}" )