Mod cog: Option to show an extra field with custom content on the ban embed #6593

Merged
VasilisThePikachu merged 10 commits from ban-extra-embed into V3/develop 2025-08-10 23:54:52 +02:00
VasilisThePikachu commented 2025-08-06 22:25:18 +02:00 (Migrated from github.com)

Description of the changes

Added a new option to the base mod cog to show a new field embed with customizable text on the ban embed. The intended reason in this example (and my usage) will be to link a ban appeal link or some other kind of information the banned user may want.

Previously to get this effect you needed to potentially set up a custom cog or another way to first send a message to the user before running the actual ban command.

Additional changes:

  • TempBan now has an embed.

The code is... meh, I have not used python in years and this code seemed pretty old.

Fixes #5591

image

Have the changes in this PR been tested?

Yes I have, I have tested all cases I could think off.

### Description of the changes Added a new option to the base mod cog to show a new field embed with customizable text on the ban embed. The intended reason in this example (and my usage) will be to link a ban appeal link or some other kind of information the banned user may want. Previously to get this effect you needed to potentially set up a custom cog or another way to first send a message to the user before running the actual ban command. Additional changes: - TempBan now has an embed. The code is... meh, I have not used python in years and this code seemed pretty old. Fixes #5591 <img width="695" height="403" alt="image" src="https://github.com/user-attachments/assets/600d3ace-0890-418b-8bbe-b3b52d9dc7c3" /> ### Have the changes in this PR been tested? <!-- Choose one (remove the line that doesn't apply): --> Yes I have, I have tested all cases I could think off. <!-- If the question doesn't apply (for example, it's not a code change), choose Yes. Please respond to this question truthfully. We do not delay nor reject PRs based on the answer to this question but it allows to better review this PR. -->
Flame442 commented 2025-08-06 22:42:01 +02:00 (Migrated from github.com)

This PR is currently failing the style check. This repo uses the Black autoformatter, and your changes need to be modified to comply with its specifications. Instructions on how to use it can be found in our contributing.md file. Be sure to use the -l 99 flag when running Black.

This PR is currently failing the style check. This repo uses the Black autoformatter, and your changes need to be modified to comply with its specifications. Instructions on how to use it can be found in our [contributing.md file](https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/CONTRIBUTING.md#43-style). Be sure to use the `-l 99` flag when running Black.
VasilisThePikachu commented 2025-08-07 17:14:18 +02:00 (Migrated from github.com)

Should I also update the docs for the mod page? I don't see it being a requirement in contrib.md but considering I changed how enabling dm on ban/kick works I feel like it's in order.

Should I also update the docs for the mod page? I don't see it being a requirement in contrib.md but considering I changed how enabling dm on ban/kick works I feel like it's in order.
Flame442 commented 2025-08-08 01:17:23 +02:00 (Migrated from github.com)

If any new commands are added or command docstrings are updated, it would be useful to also update the docs to have parity.

If any new commands are added or command docstrings are updated, it would be useful to also update the docs to have parity.
Flame442 (Migrated from github.com) requested changes 2025-08-09 22:42:09 +02:00
@ -253,7 +253,23 @@ modset dm
Flame442 (Migrated from github.com) commented 2025-08-09 22:41:46 +02:00

You are currently failing the docs style check. The over and under bars on these headers need to be the same length as the text they surround

"""""""""""""""""""""""""""""
modset dm sendmessage
"""""""""""""""""""""""""""""
You are currently failing the docs style check. The over and under bars on these headers need to be the same length as the text they surround ```suggestion """"""""""""""""""""""""""""" modset dm sendmessage """"""""""""""""""""""""""""" ```
@ -658,16 +671,38 @@ class KickBanMixin(MixinMeta):
Flame442 (Migrated from github.com) commented 2025-08-09 22:39:10 +02:00

There is a limit of 256 characters for embed.names and 1024 characters for embed.values. The add_field calls should not ever be passed a string that exceeds this limit.
https://discord.com/developers/docs/resources/message#embed-object-embed-limits

One gotcha is the fact that bold will escape existing markdown formatting unless the escape_formatting kwarg is set to False. This could cause the title to look strange, or cause the escapes to count as extra unexpected characters in whatever logic is used to limit the character count.

There is a limit of `256` characters for `embed.name`s and `1024` characters for `embed.value`s. The `add_field` calls should not ever be passed a string that exceeds this limit. <https://discord.com/developers/docs/resources/message#embed-object-embed-limits> One gotcha is the fact that `bold` will escape existing markdown formatting unless the `escape_formatting` kwarg is set to `False`. This could cause the title to look strange, or cause the escapes to count as extra unexpected characters in whatever logic is used to limit the character count.
Flame442 (Migrated from github.com) commented 2025-08-09 22:40:05 +02:00
                    name=bold(_("Here is an invite for when your ban expires")),
```suggestion name=bold(_("Here is an invite for when your ban expires")), ```
@ -347,9 +359,15 @@ class ModSettings(MixinMeta):
)
Flame442 (Migrated from github.com) commented 2025-08-09 22:29:28 +02:00

I believe this still only applies to kicks and bans, not all moderation actions

I believe this still only applies to kicks and bans, not all moderation actions
@ -370,6 +388,63 @@ class ModSettings(MixinMeta):
_("Bot will no longer attempt to send a DM to user before kick and ban.")
Flame442 (Migrated from github.com) commented 2025-08-09 22:27:15 +02:00

Generally, you cannot use f strings in our repo. Our translation logic (in the _ object, called on a string using _("Example string")) maps a template to a translated string. If the string is pre-interpolated, the translator cannot match to a valid template. For this reason, you will see .format used after the translation throughout our repo:

_("Example {variable}").format(variable=myvar)

This allows the string to be translated to another language with the variable indicator still present, while still allowing the variable to be formatted.

Generally, you cannot use `f` strings in our repo. Our translation logic (in the `_` object, called on a string using `_("Example string")`) maps a template to a translated string. If the string is pre-interpolated, the translator cannot match to a valid template. For this reason, you will see `.format` used _after_ the translation throughout our repo: ```py _("Example {variable}").format(variable=myvar) ``` This allows the string to be translated to another language with the variable indicator still present, while still allowing the variable to be formatted.
Flame442 (Migrated from github.com) commented 2025-08-09 22:29:00 +02:00
        Toggle whether to show an extra customizable field when banning.

        This can be used to add additional information for the banned user, such as a ban appeal link.

Phrasing & formatting (should also be applied in the docs)

```suggestion Toggle whether to show an extra customizable field when banning. This can be used to add additional information for the banned user, such as a ban appeal link. ``` Phrasing & formatting (should also be applied in the docs)
Flame442 (Migrated from github.com) commented 2025-08-09 22:31:08 +02:00

(nitpick) Clearing just sets these two value to the defaults, which are mostly meaningless values intended to act as placeholders. I'm not sure if there is much value to allowing the setting to be reverted like that.

(nitpick) Clearing just sets these two value to the defaults, which are mostly meaningless values intended to act as placeholders. I'm not sure if there is much value to allowing the setting to be reverted like that.
Flame442 (Migrated from github.com) reviewed 2025-08-09 22:44:01 +02:00
@ -658,16 +671,38 @@ class KickBanMixin(MixinMeta):
Flame442 (Migrated from github.com) commented 2025-08-09 22:44:01 +02:00

This also applies to the Cleared embed title and Cleared embed contents strings, if that option is not removed

This also applies to the `Cleared embed title` and `Cleared embed contents` strings, if that option is not removed
VasilisThePikachu (Migrated from github.com) reviewed 2025-08-10 15:59:26 +02:00
@ -658,16 +671,38 @@ class KickBanMixin(MixinMeta):
VasilisThePikachu (Migrated from github.com) commented 2025-08-10 15:59:25 +02:00

From what I can tell, bold just adds the 4 stars to bold a message so that leaves us with 252 characters. From some testing, len does not count escape characters and counts what they become (so \n would be 1)

From what I can tell, `bold` just adds the 4 stars to bold a message so that leaves us with 252 characters. From some testing, `len` does not count escape characters and counts what they become (so \n would be 1)
Flame442 (Migrated from github.com) requested changes 2025-08-10 20:21:18 +02:00
@ -266,6 +282,72 @@ and reason as to why they were kicked/banned.
Flame442 (Migrated from github.com) commented 2025-08-10 20:19:09 +02:00
Set the title for the optional extra embed on ban.

Nitpick

```suggestion Set the title for the optional extra embed on ban. ``` Nitpick
@ -153,6 +155,17 @@ class KickBanMixin(MixinMeta):
value=reason if reason is not None else _("No reason was given."),
Flame442 (Migrated from github.com) commented 2025-08-10 20:19:32 +02:00
                            name=bold(extra_embed_title, escape_formatting=False),

Nitpick

```suggestion name=bold(extra_embed_title, escape_formatting=False), ``` Nitpick
@ -658,16 +671,38 @@ class KickBanMixin(MixinMeta):
Flame442 (Migrated from github.com) commented 2025-08-10 20:18:51 +02:00

From what I can tell, bold just adds the 4 stars to bold a message so that leaves us with 252 characters. From some testing, len does not count escape characters and counts what they become (so \n would be 1)

In the other ban case, you passed False as the second parameter to bold. That is probably why your testing showed that escape characters were not counted, since they were never included at all. In this case (tempbans), formatting is escaped, which results in cases where the ban DM is not sent due to the suppressed discord.HTTPException triggering when the resulting title exceeds the character count. You need to also disable escaping logic here to avoid issues.

                em.add_field(
                    name=bold(extra_embed_title, escape_formatting=False),
                    value=extra_embed_contents,
                    inline=False,
                )
> From what I can tell, `bold` just adds the 4 stars to bold a message so that leaves us with 252 characters. From some testing, `len` does not count escape characters and counts what they become (so \n would be 1) In the other ban case, you passed `False` as the second parameter to `bold`. That is probably why your testing showed that escape characters were not counted, since they were never included at all. In this case (tempbans), formatting is escaped, which results in cases where the ban DM is not sent due to the suppressed `discord.HTTPException` triggering when the resulting title exceeds the character count. You need to also disable escaping logic here to avoid issues. ```suggestion em.add_field( name=bold(extra_embed_title, escape_formatting=False), value=extra_embed_contents, inline=False, ) ```
@ -370,6 +388,63 @@ class ModSettings(MixinMeta):
_("Bot will no longer attempt to send a DM to user before kick and ban.")
Flame442 (Migrated from github.com) commented 2025-08-10 20:01:59 +02:00

The format is currently applied before the translation.

                _(
                    "An extra field will be shown when banning. Configure it with `{prefix}modset dm banextrafieldtitle` and `{prefix}modset dm banextrafieldcontents`"
                ).format(prefix=ctx.prefix)
The format is currently applied before the translation. ```suggestion _( "An extra field will be shown when banning. Configure it with `{prefix}modset dm banextrafieldtitle` and `{prefix}modset dm banextrafieldcontents`" ).format(prefix=ctx.prefix) ```
Flame442 (Migrated from github.com) commented 2025-08-10 20:02:17 +02:00
        Set the title for the optional extra embed on ban.

Nitpick

```suggestion Set the title for the optional extra embed on ban. ``` Nitpick
Flame442 (Migrated from github.com) approved these changes 2025-08-10 23:54:44 +02:00
Flame442 (Migrated from github.com) left a comment

Thank you for contributing!

Thank you for contributing!
Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!6593
No description provided.