Skip to content

Commit

Permalink
Add 'Auto-invite Moderator Role' option (#382)
Browse files Browse the repository at this point in the history
* Add 'Auto-invite Moderator Role' option

* Fix v7 migration

* Fix compilation
  • Loading branch information
TheKodeToad committed Feb 9, 2024
1 parent c499974 commit 631e8e2
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ data class ModerationConfigData(
val autoPunishOnWarn: Boolean?,
val publicLogging: Boolean?,
val banDmMessage: String?,
val autoInviteModeratorRole: Boolean?
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -121,6 +122,7 @@ object Migrator : KordExKoinComponent {
4 -> ::configV4
5 -> ::configV5
6 -> ::configV6
7 -> ::configV7
else -> break
}(db.configDatabase)

Expand Down
Original file line number Diff line number Diff line change
@@ -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>("moderationConfigData")) {
updateMany(
ModerationConfigData::autoInviteModeratorRole exists false,
setValue(ModerationConfigData::autoInviteModeratorRole, null)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Config : Extension() {
null,
null,
null,
null,
null
)
)
Expand Down Expand Up @@ -134,7 +135,7 @@ class Config : Extension() {
field {
name = "Log publicly"
value = when (arguments.logPublicly) {
true -> "True"
true -> "Enabled"
false -> "Disabled"
null -> "Disabled"
}
Expand All @@ -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}"
}
Expand All @@ -175,7 +184,8 @@ class Config : Extension() {
arguments.quickTimeoutLength,
arguments.warnAutoPunishments,
arguments.logPublicly,
arguments.banDmMessage
arguments.banDmMessage,
arguments.autoInviteModeratorRole
)
)

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ModThreadInviting : Extension() {
anyGuild()
failIf {
event.channel.ownerId == kord.selfId ||
event.channel.member != null
event.channel.member != null
}
}

Expand All @@ -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

Expand Down

0 comments on commit 631e8e2

Please sign in to comment.