Skip to content

Commit 041b23e

Browse files
committed
resolve change request.
1 parent 71a8f54 commit 041b23e

2 files changed

Lines changed: 106 additions & 29 deletions

File tree

cogs/modmail.py

Lines changed: 104 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from dateutil import parser
1717

1818
from core import checks
19-
from core.models import DMDisabled, PermissionLevel, SimilarCategoryConverter, UnseenFormatter, getLogger
19+
from core.models import DMDisabled, PermissionLevel, SimilarCategoryConverter, getLogger
2020
from core.paginator import EmbedPaginatorSession
2121
from core.thread import Thread
2222
from core.time import UserFriendlyTime, human_timedelta
@@ -25,6 +25,10 @@
2525
logger = getLogger(__name__)
2626

2727

28+
# Arg names reserved by formatreply commands (channel, recipient, author).
29+
RESERVED_ARG_NAMES = {"channel", "recipient", "author"}
30+
31+
2832
class Modmail(commands.Cog):
2933
"""Commands directly related to Modmail functionality."""
3034

@@ -209,7 +213,7 @@ async def snippet(self, ctx, *, name: str.lower = None):
209213
210214
When `{prefix}snippet` is used by itself, this will retrieve
211215
a list of snippets that are currently set. `{prefix}snippet-name` will show what the
212-
snippet point to.
216+
snippet points to.
213217
214218
To create a snippet:
215219
- `{prefix}snippet add snippet-name A pre-defined text.`
@@ -634,6 +638,15 @@ async def args_add(self, ctx, name: str.lower, *, value: commands.clean_content)
634638
)
635639
return await ctx.send(embed=embed)
636640

641+
if name in RESERVED_ARG_NAMES:
642+
embed = discord.Embed(
643+
title="Error",
644+
color=self.bot.error_color,
645+
description=f"Arg name `{name}` is reserved (used by formatreply commands). "
646+
f"Reserved names: {', '.join(f'`{n}`' for n in sorted(RESERVED_ARG_NAMES))}.",
647+
)
648+
return await ctx.send(embed=embed)
649+
637650
if len(name) > 120:
638651
embed = discord.Embed(
639652
title="Error",
@@ -693,35 +706,45 @@ async def args_rename(self, ctx, name: str.lower, *, value):
693706
"""
694707
Rename an arg.
695708
"""
696-
if name in self.bot.args:
697-
if value in self.bot.args:
698-
embed = discord.Embed(
699-
title="Error",
700-
color=self.bot.error_color,
701-
description=f"Arg `{value}` already exists.",
702-
)
703-
return await ctx.send(embed=embed)
709+
if name not in self.bot.args:
710+
embed = create_not_found_embed(name, self.bot.args.keys(), "Arg")
711+
return await ctx.send(embed=embed)
704712

705-
if len(value) > 120:
706-
embed = discord.Embed(
707-
title="Error",
708-
color=self.bot.error_color,
709-
description="Arg names cannot be longer than 120 characters.",
710-
)
711-
return await ctx.send(embed=embed)
713+
if value in self.bot.args:
714+
embed = discord.Embed(
715+
title="Error",
716+
color=self.bot.error_color,
717+
description=f"Arg `{value}` already exists.",
718+
)
719+
return await ctx.send(embed=embed)
712720

713-
old_arg_value = self.bot.args[name]
714-
self.bot.args.pop(name)
715-
self.bot.args[value] = old_arg_value
716-
await self.bot.config.update()
721+
if value in RESERVED_ARG_NAMES:
722+
embed = discord.Embed(
723+
title="Error",
724+
color=self.bot.error_color,
725+
description=f"Arg name `{value}` is reserved (used by formatreply commands). "
726+
f"Reserved names: {', '.join(f'`{n}`' for n in sorted(RESERVED_ARG_NAMES))}.",
727+
)
728+
return await ctx.send(embed=embed)
717729

730+
if len(value) > 120:
718731
embed = discord.Embed(
719-
title="Renamed arg",
720-
color=self.bot.main_color,
721-
description=f'`{name}` has been renamed to "{value}".',
732+
title="Error",
733+
color=self.bot.error_color,
734+
description="Arg names cannot be longer than 120 characters.",
722735
)
723-
else:
724-
embed = create_not_found_embed(name, self.bot.args.keys(), "Arg")
736+
return await ctx.send(embed=embed)
737+
738+
old_arg_value = self.bot.args[name]
739+
self.bot.args.pop(name)
740+
self.bot.args[value] = old_arg_value
741+
await self.bot.config.update()
742+
743+
embed = discord.Embed(
744+
title="Renamed arg",
745+
color=self.bot.main_color,
746+
description=f'`{name}` has been renamed to "{value}".',
747+
)
725748
await ctx.send(embed=embed)
726749

727750
@commands.command(usage="<category> [options]")
@@ -1700,7 +1723,17 @@ async def reply(self, ctx, *, msg: str = ""):
17001723
"""
17011724

17021725
if self.bot.args:
1703-
msg = UnseenFormatter().format(msg, **self.bot.args)
1726+
msg = self.bot.formatter.format(msg, **self.bot.args)
1727+
1728+
if len(msg) > 4096:
1729+
return await ctx.send(
1730+
embed=discord.Embed(
1731+
title="Error",
1732+
color=self.bot.error_color,
1733+
description="The resulting message is too long to fit in an embed description "
1734+
f"({len(msg)}/4096 characters). Please shorten your message or args.",
1735+
)
1736+
)
17041737

17051738
# Ensure logs record only the reply text, not the command.
17061739
ctx.message.content = msg
@@ -1729,6 +1762,17 @@ async def freply(self, ctx, *, msg: str = ""):
17291762
recipient=ctx.thread.recipient,
17301763
author=ctx.message.author,
17311764
)
1765+
1766+
if len(msg) > 4096:
1767+
return await ctx.send(
1768+
embed=discord.Embed(
1769+
title="Error",
1770+
color=self.bot.error_color,
1771+
description="The resulting message is too long to fit in an embed description "
1772+
f"({len(msg)}/4096 characters). Please shorten your message or args.",
1773+
)
1774+
)
1775+
17321776
# Ensure logs record only the reply text, not the command.
17331777
ctx.message.content = msg
17341778
async with safe_typing(ctx):
@@ -1756,6 +1800,17 @@ async def fareply(self, ctx, *, msg: str = ""):
17561800
recipient=ctx.thread.recipient,
17571801
author=ctx.message.author,
17581802
)
1803+
1804+
if len(msg) > 4096:
1805+
return await ctx.send(
1806+
embed=discord.Embed(
1807+
title="Error",
1808+
color=self.bot.error_color,
1809+
description="The resulting message is too long to fit in an embed description "
1810+
f"({len(msg)}/4096 characters). Please shorten your message or args.",
1811+
)
1812+
)
1813+
17591814
# Ensure logs record only the reply text, not the command.
17601815
ctx.message.content = msg
17611816
async with safe_typing(ctx):
@@ -1783,6 +1838,17 @@ async def fpreply(self, ctx, *, msg: str = ""):
17831838
recipient=ctx.thread.recipient,
17841839
author=ctx.message.author,
17851840
)
1841+
1842+
if len(msg) > 4096:
1843+
return await ctx.send(
1844+
embed=discord.Embed(
1845+
title="Error",
1846+
color=self.bot.error_color,
1847+
description="The resulting message is too long to fit in an embed description "
1848+
f"({len(msg)}/4096 characters). Please shorten your message or args.",
1849+
)
1850+
)
1851+
17861852
# Ensure logs record only the reply text, not the command.
17871853
ctx.message.content = msg
17881854
async with safe_typing(ctx):
@@ -1810,6 +1876,17 @@ async def fpareply(self, ctx, *, msg: str = ""):
18101876
recipient=ctx.thread.recipient,
18111877
author=ctx.message.author,
18121878
)
1879+
1880+
if len(msg) > 4096:
1881+
return await ctx.send(
1882+
embed=discord.Embed(
1883+
title="Error",
1884+
color=self.bot.error_color,
1885+
description="The resulting message is too long to fit in an embed description "
1886+
f"({len(msg)}/4096 characters). Please shorten your message or args.",
1887+
)
1888+
)
1889+
18131890
# Ensure logs record only the reply text, not the command.
18141891
ctx.message.content = msg
18151892
async with safe_typing(ctx):

cogs/utility.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async def format_cog_help(self, cog, *, no_cog=False):
109109
return embeds
110110

111111
def process_help_msg(self, help_: str):
112-
return help_.replace("{prefix}", self.context.clean_prefix) if help_ else "No help message."
112+
return help_.format(prefix=self.context.clean_prefix) if help_ else "No help message."
113113

114114
async def send_bot_help(self, mapping):
115115
embeds = []
@@ -1048,7 +1048,7 @@ async def alias(self, ctx, *, name: str.lower = None):
10481048
10491049
When `{prefix}alias` is used by itself, this will retrieve
10501050
a list of alias that are currently set. `{prefix}alias-name` will show what the
1051-
alias point to.
1051+
alias points to.
10521052
10531053
To use alias:
10541054

0 commit comments

Comments
 (0)