|
16 | 16 | from dateutil import parser |
17 | 17 |
|
18 | 18 | from core import checks |
19 | | -from core.models import DMDisabled, PermissionLevel, SimilarCategoryConverter, UnseenFormatter, getLogger |
| 19 | +from core.models import DMDisabled, PermissionLevel, SimilarCategoryConverter, getLogger |
20 | 20 | from core.paginator import EmbedPaginatorSession |
21 | 21 | from core.thread import Thread |
22 | 22 | from core.time import UserFriendlyTime, human_timedelta |
|
25 | 25 | logger = getLogger(__name__) |
26 | 26 |
|
27 | 27 |
|
| 28 | +# Arg names reserved by formatreply commands (channel, recipient, author). |
| 29 | +RESERVED_ARG_NAMES = {"channel", "recipient", "author"} |
| 30 | + |
| 31 | + |
28 | 32 | class Modmail(commands.Cog): |
29 | 33 | """Commands directly related to Modmail functionality.""" |
30 | 34 |
|
@@ -209,7 +213,7 @@ async def snippet(self, ctx, *, name: str.lower = None): |
209 | 213 |
|
210 | 214 | When `{prefix}snippet` is used by itself, this will retrieve |
211 | 215 | a list of snippets that are currently set. `{prefix}snippet-name` will show what the |
212 | | - snippet point to. |
| 216 | + snippet points to. |
213 | 217 |
|
214 | 218 | To create a snippet: |
215 | 219 | - `{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) |
634 | 638 | ) |
635 | 639 | return await ctx.send(embed=embed) |
636 | 640 |
|
| 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 | + |
637 | 650 | if len(name) > 120: |
638 | 651 | embed = discord.Embed( |
639 | 652 | title="Error", |
@@ -693,35 +706,45 @@ async def args_rename(self, ctx, name: str.lower, *, value): |
693 | 706 | """ |
694 | 707 | Rename an arg. |
695 | 708 | """ |
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) |
704 | 712 |
|
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) |
712 | 720 |
|
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) |
717 | 729 |
|
| 730 | + if len(value) > 120: |
718 | 731 | 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.", |
722 | 735 | ) |
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 | + ) |
725 | 748 | await ctx.send(embed=embed) |
726 | 749 |
|
727 | 750 | @commands.command(usage="<category> [options]") |
@@ -1700,7 +1723,17 @@ async def reply(self, ctx, *, msg: str = ""): |
1700 | 1723 | """ |
1701 | 1724 |
|
1702 | 1725 | 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 | + ) |
1704 | 1737 |
|
1705 | 1738 | # Ensure logs record only the reply text, not the command. |
1706 | 1739 | ctx.message.content = msg |
@@ -1729,6 +1762,17 @@ async def freply(self, ctx, *, msg: str = ""): |
1729 | 1762 | recipient=ctx.thread.recipient, |
1730 | 1763 | author=ctx.message.author, |
1731 | 1764 | ) |
| 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 | + |
1732 | 1776 | # Ensure logs record only the reply text, not the command. |
1733 | 1777 | ctx.message.content = msg |
1734 | 1778 | async with safe_typing(ctx): |
@@ -1756,6 +1800,17 @@ async def fareply(self, ctx, *, msg: str = ""): |
1756 | 1800 | recipient=ctx.thread.recipient, |
1757 | 1801 | author=ctx.message.author, |
1758 | 1802 | ) |
| 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 | + |
1759 | 1814 | # Ensure logs record only the reply text, not the command. |
1760 | 1815 | ctx.message.content = msg |
1761 | 1816 | async with safe_typing(ctx): |
@@ -1783,6 +1838,17 @@ async def fpreply(self, ctx, *, msg: str = ""): |
1783 | 1838 | recipient=ctx.thread.recipient, |
1784 | 1839 | author=ctx.message.author, |
1785 | 1840 | ) |
| 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 | + |
1786 | 1852 | # Ensure logs record only the reply text, not the command. |
1787 | 1853 | ctx.message.content = msg |
1788 | 1854 | async with safe_typing(ctx): |
@@ -1810,6 +1876,17 @@ async def fpareply(self, ctx, *, msg: str = ""): |
1810 | 1876 | recipient=ctx.thread.recipient, |
1811 | 1877 | author=ctx.message.author, |
1812 | 1878 | ) |
| 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 | + |
1813 | 1890 | # Ensure logs record only the reply text, not the command. |
1814 | 1891 | ctx.message.content = msg |
1815 | 1892 | async with safe_typing(ctx): |
|
0 commit comments