Skip to content

Commit

Permalink
Add a config option to stop logging member role changes as it gets sp…
Browse files Browse the repository at this point in the history
…ammy, fix config view not displaying everything
  • Loading branch information
NoComment1105 committed Sep 25, 2024
1 parent ac4ea58 commit c89aee8
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 31 deletions.
30 changes: 21 additions & 9 deletions docs/commands.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
## Slash Commands

### Command name: `about`
**Description**: Learn about this bot
### Command name: `about copyright`
**Description**: Library, licencing, and copyright information

* Arguments:
* **Arguments**:
None
---
### Command name: `about general`
**Description**: General information

* **Arguments**:
None
---
### Command name: `auto-threading enable`
Expand Down Expand Up @@ -136,8 +142,10 @@ None
* `quick-timeout-length` - The length of timeouts to use for quick timeouts - Coalescing Optional Duration
* `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
* `dm-default` - The default value for whether to DM a user in a ban action 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
* `log-member-role-changes` - Whether to log changes to the roles members have in a guild. - Optional Boolean

---
### Command name: `config utility`
Expand All @@ -147,6 +155,10 @@ None

* **Arguments**:
* `utility-log` - The channel to log various utility actions too. - Optional Channel
* `log-channel-updates` - Whether to log changes made to channels in this guild. - Defaulting Boolean
* `log-event-updates` - Whether to log changes made to scheduled events in this guild. - Defaulting Boolean
* `log-invite-updates` - Whether to log changes made to invites in this guild. - Defaulting Boolean
* `log-role-updates` - Whether to log changes made to roles in this guild. - Defaulting Boolean

---
### Command name: `config clear`
Expand Down Expand Up @@ -346,7 +358,7 @@ None
* `delete-message-days` - The number of days worth of messages to delete - Int
* `reason` - The reason for the ban - Defaulting String
* `soft-ban` - Weather to soft-ban this user (unban them once messages are deleted) - Defaulting Boolean
* `dm` - Whether to send a direct message to the user about the ban - Defaulting Boolean
* `dm` - Whether to send a direct message to the user about the ban - Optional Boolean
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

---
Expand All @@ -360,7 +372,7 @@ None
* `delete-message-days` - The number of days worth of messages to delete - Int
* `duration` - The duration of the temporary ban. - Coalescing Duration
* `reason` - The reason for the ban - Defaulting String
* `dm` - Whether to send a direct message to the user about the ban - Defaulting Boolean
* `dm` - Whether to send a direct message to the user about the ban - Optional Boolean
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

---
Expand Down Expand Up @@ -390,7 +402,7 @@ None
* Arguments:
* `user` - Person to kick - User
* `reason` - The reason for the Kick - Defaulting String
* `dm` - Whether to send a direct message to the user about the kick - Defaulting Boolean
* `dm` - Whether to send a direct message to the user about the kick - Optional Boolean
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

---
Expand All @@ -403,7 +415,7 @@ None
* `user` - Person to timeout - User
* `duration` - Duration of timeout - Coalescing Optional Duration
* `reason` - Reason for timeout - Defaulting String
* `dm` - Whether to send a direct message to the user about the timeout - Defaulting Boolean
* `dm` - Whether to send a direct message to the user about the timeout - Optional Boolean
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

---
Expand All @@ -414,7 +426,7 @@ None

* Arguments:
* `user` - Person to remove timeout from - User
* `dm` - Whether to dm the user about this or not - Defaulting Boolean
* `dm` - Whether to dm the user about this or not - Optional Boolean

---
### Command name: `warn`
Expand All @@ -425,7 +437,7 @@ None
* Arguments:
* `user` - Person to warn - User
* `reason` - Reason for warning - Defaulting String
* `dm` - Whether to send a direct message to the user about the warning - Defaulting Boolean
* `dm` - Whether to send a direct message to the user about the warning - Optional Boolean
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ data class LoggingConfigData(
* @property autoPunishOnWarn Whether to automatically apply punishments for reaching certain warn strike counts
* @property publicLogging Whether to log moderation actions publicly in the channel the command was run in
* @property banDmMessage The message to send in a DM to a user when they are banned.
* @property autoInviteModeratorRole Whether to automatically add moderators to newly created threads
* @property logMemberRoleChanges Whether to log changes to the roles members have in the guild
* @since 4.0.0
*/
@Serializable
Expand All @@ -57,7 +59,8 @@ data class ModerationConfigData(
val publicLogging: Boolean?,
val dmDefault: Boolean?,
val banDmMessage: String?,
val autoInviteModeratorRole: Boolean?
val autoInviteModeratorRole: Boolean?,
val logMemberRoleChanges: Boolean?
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,8 @@ import org.hyacinthbots.lilybot.database.collections.ConfigMetaCollection
import org.hyacinthbots.lilybot.database.collections.MainMetaCollection
import org.hyacinthbots.lilybot.database.entities.ConfigMetaData
import org.hyacinthbots.lilybot.database.entities.MainMetaData
import org.hyacinthbots.lilybot.database.migrations.config.configV1
import org.hyacinthbots.lilybot.database.migrations.config.configV2
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.mainV10
import org.hyacinthbots.lilybot.database.migrations.main.mainV11
import org.hyacinthbots.lilybot.database.migrations.main.mainV2
import org.hyacinthbots.lilybot.database.migrations.main.mainV3
import org.hyacinthbots.lilybot.database.migrations.main.mainV4
import org.hyacinthbots.lilybot.database.migrations.main.mainV5
import org.hyacinthbots.lilybot.database.migrations.main.mainV6
import org.hyacinthbots.lilybot.database.migrations.main.mainV7
import org.hyacinthbots.lilybot.database.migrations.main.mainV8
import org.hyacinthbots.lilybot.database.migrations.main.mainV9
import org.hyacinthbots.lilybot.database.migrations.config.*
import org.hyacinthbots.lilybot.database.migrations.main.*
import org.koin.core.component.inject

object Migrator : KordExKoinComponent {
Expand Down Expand Up @@ -127,6 +111,7 @@ object Migrator : KordExKoinComponent {
5 -> ::configV5
6 -> ::configV6
7 -> ::configV7
8 -> ::configV8
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 configV8(db: CoroutineDatabase) {
with(db.getCollection<ModerationConfigData>("moderationConfigData")) {
updateMany(
ModerationConfigData::logMemberRoleChanges exists false,
setValue(ModerationConfigData::logMemberRoleChanges, null)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ suspend fun SlashCommand<*, *, *>.configViewCommand() = ephemeralSubCommand(::Vi
null -> "Disabled"
}
}
field {
name = "Log member role changes"
value = when (config.logMemberRoleChanges) {
true -> "Enabled"
false -> "Disabled"
null -> "Disabled"
}
}
timestamp = Clock.System.now()
}
}
Expand Down Expand Up @@ -159,6 +167,22 @@ suspend fun SlashCommand<*, *, *>.configViewCommand() = ephemeralSubCommand(::Vi
config.utilityLogChannel?.let { guild!!.getChannelOrNull(it)?.mention } ?: "None"
} ${config.utilityLogChannel?.let { guild!!.getChannelOrNull(it)?.name } ?: ""}"
}
field {
name = "Log Channel updates"
value = config.logChannelUpdates.toString()
}
field {
name = "Log Event updates"
value = config.logEventUpdates.toString()
}
field {
name = "Log Invite updates"
value = config.logInviteUpdates.toString()
}
field {
name = "Log Role updates"
value = config.logRoleUpdates.toString()
}
timestamp = Clock.System.now()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ suspend fun EmbedBuilder.moderationEmbed(arguments: ModerationArgs, user: UserBe
null -> "Disabled"
}
}
field {
name = "Log member role changes"
value = when (arguments.logMemberRoleChanges) {
true -> "Enabled"
false -> "Disabled"
null -> "Disabled"
}
}
footer {
text = "Configured by ${user.asUserOrNull()?.username}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ class ModerationArgs : Arguments() {
name = "auto-invite-moderator-role"
description = "Silently ping moderators to invite them to new threads."
}

val logMemberRoleChanges by optionalBoolean {
name = "log-member-role-changes"
description = "Whether to log changes to the roles members have in a guild."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ suspend fun SlashCommand<*, *, *>.moderationCommand() =
null,
null,
null,
null,
null
)
)
Expand Down Expand Up @@ -109,7 +110,8 @@ suspend fun SlashCommand<*, *, *>.moderationCommand() =
arguments.logPublicly,
arguments.dmDefault,
arguments.banDmMessage,
arguments.autoInviteModeratorRole
arguments.autoInviteModeratorRole,
arguments.logMemberRoleChanges
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ class ModerationEvents : Extension() {
LeftMemberFlagCollection().removeMemberFromLeft(event.guildId, event.member.id)
return@action
}
// Do not log if the moderation system is disabled
if (ModerationConfigCollection().getConfig(event.guildId)?.enabled != true) return@action
// Do not log if member role changes is not true
if (ModerationConfigCollection().getConfig(event.guildId)?.logMemberRoleChanges != true) return@action
val channel = getLoggingChannelWithPerms(ConfigOptions.ACTION_LOG, event.guild)
if (event.old?.timeoutUntil != event.member.timeoutUntil) {
var existingAction =
Expand Down

0 comments on commit c89aee8

Please sign in to comment.