diff --git a/docs/commands.md b/docs/commands.md index 53e00423..02ea5d53 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -47,6 +47,7 @@ Required Member Permissions: Manage Server * `warn-auto-punishments` - Whether to automatically punish users for reach a certain threshold on warns - Optional Boolean * `log-publicly` - Whether to log moderation publicly or not. - Optional Boolean * `ban-dm-message` - A custom message to send to users when they are banned. - Optional String + * `auto-invite-moderator-role` - Silently ping moderators to invite them to new threads. - Optional Boolean --- #### Command name: `config logging` diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/Config.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/Config.kt index 84a256af..519c9744 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/Config.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/Config.kt @@ -56,6 +56,7 @@ data class ModerationConfigData( val autoPunishOnWarn: Boolean?, val publicLogging: Boolean?, val banDmMessage: String?, + val autoInviteModeratorRole: Boolean? ) /** diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/Migrator.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/Migrator.kt index 3c8af692..8497b07d 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/Migrator.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/Migrator.kt @@ -24,6 +24,7 @@ import org.hyacinthbots.lilybot.database.migrations.config.configV3 import org.hyacinthbots.lilybot.database.migrations.config.configV4 import org.hyacinthbots.lilybot.database.migrations.config.configV5 import org.hyacinthbots.lilybot.database.migrations.config.configV6 +import org.hyacinthbots.lilybot.database.migrations.config.configV7 import org.hyacinthbots.lilybot.database.migrations.main.mainV1 import org.hyacinthbots.lilybot.database.migrations.main.mainV2 import org.hyacinthbots.lilybot.database.migrations.main.mainV3 @@ -121,6 +122,7 @@ object Migrator : KordExKoinComponent { 4 -> ::configV4 5 -> ::configV5 6 -> ::configV6 + 7 -> ::configV7 else -> break }(db.configDatabase) diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV7.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV7.kt new file mode 100644 index 00000000..6af25904 --- /dev/null +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV7.kt @@ -0,0 +1,15 @@ +package org.hyacinthbots.lilybot.database.migrations.config + +import org.hyacinthbots.lilybot.database.entities.ModerationConfigData +import org.litote.kmongo.coroutine.CoroutineDatabase +import org.litote.kmongo.exists +import org.litote.kmongo.setValue + +suspend fun configV7(db: CoroutineDatabase) { + with(db.getCollection("moderationConfigData")) { + updateMany( + ModerationConfigData::autoInviteModeratorRole exists false, + setValue(ModerationConfigData::autoInviteModeratorRole, null) + ) + } +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/extensions/config/Config.kt b/src/main/kotlin/org/hyacinthbots/lilybot/extensions/config/Config.kt index d8e42dc7..d873e6c5 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/extensions/config/Config.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/extensions/config/Config.kt @@ -80,6 +80,7 @@ class Config : Extension() { null, null, null, + null, null ) ) @@ -134,7 +135,7 @@ class Config : Extension() { field { name = "Log publicly" value = when (arguments.logPublicly) { - true -> "True" + true -> "Enabled" false -> "Disabled" null -> "Disabled" } @@ -155,6 +156,14 @@ class Config : Extension() { name = "Ban DM Message" value = arguments.banDmMessage ?: "No custom Ban DM message set" } + field { + name = "Auto-invite Moderator Role" + value = when (arguments.autoInviteModeratorRole) { + true -> "Enabled" + false -> "Disabled" + null -> "Disabled" + } + } footer { text = "Configured by ${user.asUserOrNull()?.username}" } @@ -175,7 +184,8 @@ class Config : Extension() { arguments.quickTimeoutLength, arguments.warnAutoPunishments, arguments.logPublicly, - arguments.banDmMessage + arguments.banDmMessage, + arguments.autoInviteModeratorRole ) ) @@ -632,20 +642,39 @@ class Config : Extension() { } field { name = "Action log" - value = - config.channel?.let { guild!!.getChannelOrNull(it)?.mention } ?: "Disabled" + value = config.channel?.let { guild!!.getChannelOrNull(it)?.mention } ?: "Disabled" } field { name = "Log publicly" value = when (config.publicLogging) { - true -> "True" + true -> "Enabled" + false -> "Disabled" + null -> "Disabled" + } + } + field { + name = "Quick timeout length" + value = config.quickTimeoutLength.interval() ?: "No quick timeout length set" + } + field { + name = "Warning Auto-punishments" + value = when (config.autoPunishOnWarn) { + true -> "Enabled" false -> "Disabled" null -> "Disabled" } } field { name = "Ban DM Message" - value = config.banDmMessage ?: "None" + value = config.banDmMessage ?: "No custom Ban DM message set" + } + field { + name = "Auto-invite Moderator Role" + value = when (config.autoInviteModeratorRole) { + true -> "Enabled" + false -> "Disabled" + null -> "Disabled" + } } timestamp = Clock.System.now() } @@ -765,6 +794,11 @@ class Config : Extension() { name = "ban-dm-message" description = "A custom message to send to users when they are banned." } + + val autoInviteModeratorRole by optionalBoolean { + name = "auto-invite-moderator-role" + description = "Silently ping moderators to invite them to new threads." + } } inner class LoggingArgs : Arguments() { diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/extensions/events/ModThreadInviting.kt b/src/main/kotlin/org/hyacinthbots/lilybot/extensions/events/ModThreadInviting.kt index 0bb51484..fb3466ec 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/extensions/events/ModThreadInviting.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/extensions/events/ModThreadInviting.kt @@ -21,7 +21,7 @@ class ModThreadInviting : Extension() { anyGuild() failIf { event.channel.ownerId == kord.selfId || - event.channel.member != null + event.channel.member != null } } @@ -38,7 +38,7 @@ class ModThreadInviting : Extension() { val config = ModerationConfigCollection().getConfig(channel.guildId) ?: return@action - if (!config.enabled || config.role == null) return@action + if (!config.enabled || config.role == null || config.autoInviteModeratorRole != true) return@action val moderatorRole = channel.guild.getRoleOrNull(config.role) ?: return@action