Skip to content

arged responses - #3418

Open
lorenzo132 wants to merge 17 commits into
developmentfrom
users/lorenzo132/arged-responses
Open

arged responses#3418
lorenzo132 wants to merge 17 commits into
developmentfrom
users/lorenzo132/arged-responses

Conversation

@lorenzo132

Copy link
Copy Markdown
Member

This add a args feature, for example if your arg is called argreply

You can do: `?reply Hello, read the following: {argreply}

This add a args feature, for example if your arg is called `argreply`

You can do: `?reply Hello, read the following: {argreply}
@lorenzo132 lorenzo132 mentioned this pull request Dec 13, 2025
2 tasks
@lorenzo132 lorenzo132 changed the title Users/lorenzo132/arged responses arged responses Dec 13, 2025
martinbndr
martinbndr previously approved these changes Dec 13, 2025
@StephenDaDev
StephenDaDev removed the request for review from ModmailTest December 14, 2025 01:34
StephenDaDev
StephenDaDev previously approved these changes Dec 14, 2025
Comment thread cogs/modmail.py
Comment thread cogs/modmail.py
@lorenzo132
lorenzo132 dismissed stale reviews from StephenDaDev and martinbndr via fed5044 December 14, 2025 02:42
StephenDaDev
StephenDaDev previously approved these changes Dec 14, 2025
@StephenDaDev StephenDaDev added the changelog Changes in PR have been added to draft release that will be used for the changelog on the next ver. label Dec 18, 2025

This comment was marked as spam.

Copilot AI review requested due to automatic review settings January 16, 2026 12:46
Copilot AI review requested due to automatic review settings July 18, 2026 23:00
@lorenzo132
lorenzo132 dismissed stale reviews from StephenDaDev and martinbndr via 8d97f94 July 18, 2026 23:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (5)

cogs/modmail.py:688

  • args_edit stores the new value without commands.clean_content, while args_add uses clean_content. This makes edits behave differently than adds and can reintroduce mentions/markdown that add would have sanitized.
    @args.command(name="edit")
    @checks.has_permissions(PermissionLevel.SUPPORTER)
    async def args_edit(self, ctx, name: str.lower, *, value):
        """
        Edit an arg.

cogs/modmail.py:1762

  • Passing **self.bot.args alongside explicit channel=..., recipient=..., author=... can raise TypeError: got multiple values for keyword argument if the config already contains any reserved keys (e.g. from manual edits or older data). Build a single kwargs dict and let the reserved keys override.
        msg = self.bot.formatter.format(
            msg,
            **self.bot.args,
            channel=ctx.channel,
            recipient=ctx.thread.recipient,

cogs/modmail.py:1800

  • Same reserved-key collision risk as freply: expanding **self.bot.args together with explicit channel/recipient/author can throw TypeError if those keys exist in config. Merge into a single dict so reserved values overwrite safely.
        msg = self.bot.formatter.format(
            msg,
            **self.bot.args,
            channel=ctx.channel,
            recipient=ctx.thread.recipient,

cogs/modmail.py:1838

  • Same reserved-key collision risk as freply: expanding **self.bot.args together with explicit channel/recipient/author can throw TypeError if those keys exist in config. Merge into a single dict so reserved values overwrite safely.
        msg = self.bot.formatter.format(
            msg,
            **self.bot.args,
            channel=ctx.channel,
            recipient=ctx.thread.recipient,

cogs/modmail.py:1876

  • Same reserved-key collision risk as freply: expanding **self.bot.args together with explicit channel/recipient/author can throw TypeError if those keys exist in config. Merge into a single dict so reserved values overwrite safely.
        msg = self.bot.formatter.format(
            msg,
            **self.bot.args,
            channel=ctx.channel,
            recipient=ctx.thread.recipient,

Comment thread core/models.py
Comment thread cogs/modmail.py
Comment thread cogs/modmail.py
Comment thread cogs/modmail.py
Comment thread cogs/modmail.py Outdated
Comment thread cogs/modmail.py

@sebkuip sebkuip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a bug with dotted names within freply (and afreply likely as well)

Comment thread cogs/modmail.py
Copilot AI review requested due to automatic review settings August 1, 2026 11:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (4)

cogs/modmail.py:30

  • RESERVED_ARG_NAMES only blocks channel/recipient/author, but arg names that collide with the args subcommands (add/remove/edit/rename/raw) or the special compact keyword cannot be retrieved via ?args <name> and will be interpreted as commands/modes instead. Treating these as reserved avoids confusing, unretrievable args.
# Arg names reserved by formatreply commands (channel, recipient, author).
RESERVED_ARG_NAMES = {"channel", "recipient", "author"}

cogs/modmail.py:595

  • The embed page count calculation creates an extra empty page when len(self.bot.args) is an exact multiple of 10 (e.g., 10 args -> 2 embeds, second has no fields).
        embeds = [discord.Embed(color=self.bot.main_color) for _ in range((len(self.bot.args) // 10) + 1)]

cogs/modmail.py:698

  • args_add sanitizes the stored value via commands.clean_content, but args_edit does not. This makes it possible to bypass mention/markup sanitization by editing an existing arg, and can lead to unexpected pings when args are expanded in replies.
    @args.command(name="edit")
    @checks.has_permissions(PermissionLevel.SUPPORTER)
    async def args_edit(self, ctx, name: str.lower, *, value):
        """
        Edit an arg.
        """
        if name in self.bot.args:
            self.bot.args[name] = value
            await self.bot.config.update()

            embed = discord.Embed(
                title="Edited arg",
                color=self.bot.main_color,
                description=f'`{name}` will now be replaced with "{value}".',
            )

core/models.py:366

  • SafeFormatter.get_field now returns a kwarg value when the entire field_name matches a key (including dotted names like recipient.name). This changes formatting precedence and allows values in kwargs (e.g., user-defined args) to shadow attribute/index resolution that previously would have been applied, which can break existing {recipient.name} / {channel.id} usage in formatreply when an arg uses the same dotted name.
class SafeFormatter(Formatter):
    def get_field(self, field_name, args, kwargs):
        if field_name in kwargs:
            return kwargs[field_name], field_name

        first, rest = _string.formatter_field_name_split(field_name)

sebkuip

This comment was marked as outdated.

@sebkuip sebkuip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore previous review. Found a bug with copilots help

Comment thread cogs/modmail.py
Copilot AI review requested due to automatic review settings August 1, 2026 12:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (7)

cogs/modmail.py:686

  • args_edit does not sanitize the edited value (unlike args_add, which uses commands.clean_content). Since arg values are later injected into embeds, this allows introducing mention pings (e.g., @everyone) or other unsafe content via edits.
    async def args_edit(self, ctx, name: str.lower, *, value):

cogs/modmail.py:595

  • The paginator page count creates an extra empty embed when the number of args is an exact multiple of 10 (e.g., 10 args => 2 pages, second is blank).
        embeds = [discord.Embed(color=self.bot.main_color) for _ in range((len(self.bot.args) // 10) + 1)]

cogs/modmail.py:1800

  • Passing **self.bot.args alongside explicit channel=.../recipient=.../author=... can raise a TypeError if the args dict contains any of those reserved keys (e.g., via manual config edits), breaking the command at runtime. Filter reserved keys before expanding the args dict.
        msg = self.bot.formatter.format(
            msg,
            **self.bot.args,
            channel=ctx.channel,
            recipient=ctx.thread.recipient,

cogs/modmail.py:1838

  • Passing **self.bot.args alongside explicit channel=.../recipient=.../author=... can raise a TypeError if the args dict contains any of those reserved keys (e.g., via manual config edits), breaking the command at runtime. Filter reserved keys before expanding the args dict.
        msg = self.bot.formatter.format(
            msg,
            **self.bot.args,
            channel=ctx.channel,
            recipient=ctx.thread.recipient,

cogs/modmail.py:1876

  • Passing **self.bot.args alongside explicit channel=.../recipient=.../author=... can raise a TypeError if the args dict contains any of those reserved keys (e.g., via manual config edits), breaking the command at runtime. Filter reserved keys before expanding the args dict.
        msg = self.bot.formatter.format(
            msg,
            **self.bot.args,
            channel=ctx.channel,
            recipient=ctx.thread.recipient,

core/models.py:422

  • UnseenFormatter.get_field currently returns a literal for any non-decimal field not exactly present in kwargs, which prevents attribute/index resolution for known base variables. This breaks existing usages like {bot.user.display_name} in core/config_help.json when formatted via UnseenFormatter() (see cogs/utility.py:1010).
        if field_name in kwargs:
            return kwargs[field_name], field_name
        if field_name.isdecimal():
            return super().get_field(field_name, args, kwargs)
        return "{" + field_name + "}", field_name

cogs/modmail.py:1764

  • Passing **self.bot.args alongside explicit channel=.../recipient=.../author=... can raise a TypeError if the args dict contains any of those reserved keys (e.g., via manual config edits), breaking the command at runtime. Filter reserved keys before expanding the args dict.

This issue also appears in the following locations of the same file:

  • line 1796
  • line 1834
  • line 1872
        msg = self.bot.formatter.format(
            msg,
            **self.bot.args,
            channel=ctx.channel,
            recipient=ctx.thread.recipient,

@sebkuip sebkuip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small things from copilot's suggestions that are confirmed bugs

Comment thread cogs/modmail.py Outdated
Comment thread cogs/modmail.py Outdated
Copilot AI review requested due to automatic review settings August 1, 2026 12:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (6)

core/models.py:422

  • UnseenFormatter.get_field currently returns a literal placeholder for any field name that isn’t an exact key in kwargs, which prevents attribute/index access (e.g. {bot.user.display_name}) from resolving. This breaks existing uses like formatting strings in core/config_help.json via UnseenFormatter().format(..., bot=self.bot).
        if field_name in kwargs:
            return kwargs[field_name], field_name
        if field_name.isdecimal():
            return super().get_field(field_name, args, kwargs)
        return "{" + field_name + "}", field_name

cogs/modmail.py:1836

  • Expanding **self.bot.args here can raise TypeError: got multiple values for keyword argument if the args dict ever contains reserved keys like channel/recipient/author (e.g. from manual config edits). Filter reserved names out before expanding.
            **self.bot.args,

cogs/modmail.py:1760

  • Expanding **self.bot.args here can raise TypeError: got multiple values for keyword argument if the args dict ever contains reserved keys like channel/recipient/author (e.g. from manual config edits). Filter reserved names out before expanding.
            **self.bot.args,

cogs/modmail.py:1798

  • Expanding **self.bot.args here can raise TypeError: got multiple values for keyword argument if the args dict ever contains reserved keys like channel/recipient/author (e.g. from manual config edits). Filter reserved names out before expanding.
            **self.bot.args,

cogs/modmail.py:1874

  • Expanding **self.bot.args here can raise TypeError: got multiple values for keyword argument if the args dict ever contains reserved keys like channel/recipient/author (e.g. from manual config edits). Filter reserved names out before expanding.
            **self.bot.args,

cogs/modmail.py:555

  • This help string includes {arg-name}. Help text is rendered with help_.format(prefix=...) (see cogs/utility.py:111-112), so unescaped braces here can raise a formatting error. Use doubled braces to display a literal {...} to users.
        You can use your arg in a reply with `{arg-name}`.

@sebkuip sebkuip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look all good now. Can't find further bugs myself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved changelog Changes in PR have been added to draft release that will be used for the changelog on the next ver. feature request staged Staged for next version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants