Skip to content

Commit

Permalink
Dm default false (#421)
Browse files Browse the repository at this point in the history
* Theoretically make the DM option default to a certain value. Needs testing :)

* Forgot migration 😎
  • Loading branch information
NoComment1105 committed Sep 20, 2024
1 parent 1998d2e commit 22d399f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ data class ModerationConfigData(
val quickTimeoutLength: DateTimePeriod?,
val autoPunishOnWarn: Boolean?,
val publicLogging: Boolean?,
val dmDefault: Boolean?,
val banDmMessage: String?,
val autoInviteModeratorRole: Boolean?
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ suspend fun configV7(db: CoroutineDatabase) {
ModerationConfigData::autoInviteModeratorRole exists false,
setValue(ModerationConfigData::autoInviteModeratorRole, null)
)
updateMany(
ModerationConfigData::dmDefault exists false,
setValue(ModerationConfigData::dmDefault, true)
)
}
with(db.getCollection<UtilityConfigData>("utilityConfigData")) {
updateMany(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ suspend fun EmbedBuilder.moderationEmbed(arguments: ModerationArgs, user: UserBe
null -> "Disabled"
}
}
field {
name = "DM Default"
value = when (arguments.dmDefault) {
true -> "DM argument will default to true"
false -> "DM argument will default to false"
null -> "DM argument will default to false"
}
}
field {
name = "Ban DM Message"
value = arguments.banDmMessage ?: "No custom Ban DM message set"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import dev.kordex.core.commands.converters.impl.defaultingBoolean
import dev.kordex.core.commands.converters.impl.defaultingString
import dev.kordex.core.commands.converters.impl.int
import dev.kordex.core.commands.converters.impl.optionalAttachment
import dev.kordex.core.commands.converters.impl.optionalBoolean
import dev.kordex.core.commands.converters.impl.user
import dev.kordex.core.components.components
import dev.kordex.core.components.ephemeralStringSelectMenu
Expand Down Expand Up @@ -488,7 +489,8 @@ class ModerationCommands : Extension() {

val modConfig = ModerationConfigCollection().getConfig(guild!!.id)
var dmStatus: Message? = null
if (arguments.dm) {
val dmControl = if (arguments.dm != null) arguments.dm!! else modConfig?.dmDefault == true
if (dmControl) {
dmStatus = arguments.userArgument.dm {
embed {
title = "You have been banned from ${guild?.asGuildOrNull()?.name}"
Expand Down Expand Up @@ -580,7 +582,8 @@ class ModerationCommands : Extension() {
val duration = now.plus(arguments.duration, TimeZone.UTC)
val modConfig = ModerationConfigCollection().getConfig(guild!!.id)
var dmStatus: Message? = null
if (arguments.dm) {
val dmControl = if (arguments.dm != null) arguments.dm!! else modConfig?.dmDefault == true
if (dmControl) {
dmStatus = arguments.userArgument.dm {
embed {
title = "You have been temporarily banned from ${guild?.fetchGuild()?.name}"
Expand Down Expand Up @@ -737,7 +740,8 @@ class ModerationCommands : Extension() {

val modConfig = ModerationConfigCollection().getConfig(guild!!.id)
var dmStatus: Message? = null
if (arguments.dm) {
val dmControl = if (arguments.dm != null) arguments.dm!! else modConfig?.dmDefault == true
if (dmControl) {
dmStatus = arguments.userArgument.dm {
embed {
title = "You have been kicked from ${guild?.fetchGuild()?.name}"
Expand Down Expand Up @@ -787,7 +791,8 @@ class ModerationCommands : Extension() {
isBotOrModerator(event.kord, arguments.userArgument, guild, "timeout") ?: return@action

var dmStatus: Message? = null
if (arguments.dm) {
val dmControl = if (arguments.dm != null) arguments.dm!! else modConfig?.dmDefault == true
if (dmControl) {
dmStatus = arguments.userArgument.dm {
embed {
title = "You have been timed out in ${guild?.fetchGuild()?.name}"
Expand Down Expand Up @@ -846,8 +851,10 @@ class ModerationCommands : Extension() {
}

action {
val config = ModerationConfigCollection().getConfig(guild!!.id)
var dmStatus: Message? = null
if (arguments.dm) {
val dmControl = if (arguments.dm != null) arguments.dm!! else config?.dmDefault == true
if (dmControl) {
dmStatus = arguments.userArgument.dm {
embed {
title = "Timeout removed in ${guild!!.asGuildOrNull()?.name}"
Expand Down Expand Up @@ -901,7 +908,9 @@ class ModerationCommands : Extension() {

var dmStatus: Message? = null

if (arguments.dm) {
val dmControl = if (arguments.dm != null) arguments.dm!! else config.dmDefault == true

if (dmControl) {
val warnText = if (config.autoPunishOnWarn == false) {
"No moderation action has been taken.\n $warnSuffix"
} else {
Expand Down Expand Up @@ -937,7 +946,7 @@ class ModerationCommands : Extension() {
title = "Warning"
image = arguments.image?.url
baseModerationEmbed(arguments.reason, arguments.userArgument, user)
dmNotificationStatusEmbedField(dmStatus, arguments.dm)
dmNotificationStatusEmbedField(dmStatus, dmControl)
timestamp = Clock.System.now()
field {
name = "Total strikes"
Expand Down Expand Up @@ -1104,10 +1113,9 @@ class ModerationCommands : Extension() {
}

/** Whether to DM the user or not. */
val dm by defaultingBoolean {
val dm by optionalBoolean {
name = "dm"
description = "Whether to send a direct message to the user about the ban"
defaultValue = true
}

/** An image that the user wishes to provide for context to the ban. */
Expand Down Expand Up @@ -1144,10 +1152,9 @@ class ModerationCommands : Extension() {
}

/** Whether to DM the user or not. */
val dm by defaultingBoolean {
val dm by optionalBoolean {
name = "dm"
description = "Whether to send a direct message to the user about the ban"
defaultValue = true
}

/** An image that the user wishes to provide for context to the ban. */
Expand Down Expand Up @@ -1187,10 +1194,9 @@ class ModerationCommands : Extension() {
}

/** Whether to DM the user or not. */
val dm by defaultingBoolean {
val dm by optionalBoolean {
name = "dm"
description = "Whether to send a direct message to the user about the kick"
defaultValue = true
}

/** An image that the user wishes to provide for context to the kick. */
Expand Down Expand Up @@ -1221,10 +1227,9 @@ class ModerationCommands : Extension() {
}

/** Whether to DM the user or not. */
val dm by defaultingBoolean {
val dm by optionalBoolean {
name = "dm"
description = "Whether to send a direct message to the user about the timeout"
defaultValue = true
}

/** An image that the user wishes to provide for context to the kick. */
Expand All @@ -1242,10 +1247,9 @@ class ModerationCommands : Extension() {
}

/** Whether to DM the user about the timeout removal or not. */
val dm by defaultingBoolean {
val dm by optionalBoolean {
name = "dm"
description = "Whether to dm the user about this or not"
defaultValue = true
}
}

Expand All @@ -1264,10 +1268,9 @@ class ModerationCommands : Extension() {
}

/** Whether to DM the user or not. */
val dm by defaultingBoolean {
val dm by optionalBoolean {
name = "dm"
description = "Whether to send a direct message to the user about the warning"
defaultValue = true
}

/** An image that the user wishes to provide for context to the kick. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class ModerationArgs : Arguments() {
description = "Whether to log moderation publicly or not."
}

val dmDefault by optionalBoolean {
name = "dm-default"
description = "The default value for whether to DM a user in a ban action or not."
}

val banDmMessage by optionalString {
name = "ban-dm-message"
description = "A custom message to send to users when they are banned."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ suspend fun SlashCommand<*, *, *>.moderationCommand() =
null,
null,
null,
null,
null
)
)
Expand Down Expand Up @@ -106,6 +107,7 @@ suspend fun SlashCommand<*, *, *>.moderationCommand() =
arguments.quickTimeoutLength,
arguments.warnAutoPunishments,
arguments.logPublicly,
arguments.dmDefault,
arguments.banDmMessage,
arguments.autoInviteModeratorRole
)
Expand Down

0 comments on commit 22d399f

Please sign in to comment.