|
6 | 6 |
|
7 | 7 | import discord
|
8 | 8 | from discord.ext import commands
|
9 |
| -from discord.utils import escape_markdown, escape_mentions |
| 9 | +from discord.utils import escape_markdown |
10 | 10 |
|
11 | 11 | from dateutil import parser
|
12 | 12 | from natural.date import duration
|
|
21 | 21 | create_not_found_embed,
|
22 | 22 | format_description,
|
23 | 23 | trigger_typing,
|
| 24 | + escape_code_block, |
24 | 25 | )
|
25 | 26 |
|
26 | 27 | logger = getLogger(__name__)
|
@@ -155,8 +156,10 @@ async def snippet(self, ctx, *, name: str.lower = None):
|
155 | 156 | val = self.bot.snippets.get(name)
|
156 | 157 | if val is None:
|
157 | 158 | embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
|
158 |
| - return await ctx.send(embed=embed) |
159 |
| - return await ctx.send(escape_mentions(val)) |
| 159 | + else: |
| 160 | + embed = discord.Embed(color=self.bot.main_color) |
| 161 | + embed.add_field(name=f"`{name}` will send:", value=val) |
| 162 | + return await ctx.send(embed=embed) |
160 | 163 |
|
161 | 164 | if not self.bot.snippets:
|
162 | 165 | embed = discord.Embed(
|
@@ -186,8 +189,11 @@ async def snippet_raw(self, ctx, *, name: str.lower):
|
186 | 189 | val = self.bot.snippets.get(name)
|
187 | 190 | if val is None:
|
188 | 191 | embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
|
189 |
| - return await ctx.send(embed=embed) |
190 |
| - return await ctx.send(escape_markdown(escape_mentions(val)).replace("<", "\\<")) |
| 192 | + else: |
| 193 | + embed = discord.Embed(color=self.bot.main_color) |
| 194 | + val = escape_code_block(val) |
| 195 | + embed.add_field(name=f"`{name}` will send:", value=f"```\n{val}```") |
| 196 | + return await ctx.send(embed=embed) |
191 | 197 |
|
192 | 198 | @snippet.command(name="add")
|
193 | 199 | @checks.has_permissions(PermissionLevel.SUPPORTER)
|
@@ -782,10 +788,32 @@ async def reply(self, ctx, *, msg: str = ""):
|
782 | 788 | async with ctx.typing():
|
783 | 789 | await ctx.thread.reply(ctx.message)
|
784 | 790 |
|
785 |
| - @commands.command() |
| 791 | + @commands.command(aliases=["formatreply"]) |
| 792 | + @checks.has_permissions(PermissionLevel.SUPPORTER) |
| 793 | + @checks.thread_only() |
| 794 | + async def freply(self, ctx, *, msg: str = ""): |
| 795 | + """ |
| 796 | + Reply to a Modmail thread with variables. |
| 797 | +
|
| 798 | + Works just like `{prefix}reply`, however with the addition of three variables: |
| 799 | + - `{channel}` - the `discord.TextChannel` object |
| 800 | + - `{recipient}` - the `discord.User` object of the recipient |
| 801 | + - `{author}` - the `discord.User` object of the author |
| 802 | +
|
| 803 | + Supports attachments and images as well as |
| 804 | + automatically embedding image URLs. |
| 805 | + """ |
| 806 | + msg = self.bot.formatter.format( |
| 807 | + msg, channel=ctx.channel, recipient=ctx.thread.recipient, author=ctx.message.author |
| 808 | + ) |
| 809 | + ctx.message.content = msg |
| 810 | + async with ctx.typing(): |
| 811 | + await ctx.thread.reply(ctx.message) |
| 812 | + |
| 813 | + @commands.command(aliases=["anonreply", "anonymousreply"]) |
786 | 814 | @checks.has_permissions(PermissionLevel.SUPPORTER)
|
787 | 815 | @checks.thread_only()
|
788 |
| - async def anonreply(self, ctx, *, msg: str = ""): |
| 816 | + async def areply(self, ctx, *, msg: str = ""): |
789 | 817 | """
|
790 | 818 | Reply to a thread anonymously.
|
791 | 819 |
|
@@ -823,11 +851,10 @@ async def find_linked_message(self, ctx, message_id):
|
823 | 851 | continue
|
824 | 852 | # TODO: use regex to find the linked message id
|
825 | 853 | linked_message_id = str(embed.author.url).split("/")[-1]
|
826 |
| - break |
| 854 | + |
827 | 855 | elif message_id and msg.id == message_id:
|
828 | 856 | url = msg.embeds[0].author.url
|
829 | 857 | linked_message_id = str(url).split("/")[-1]
|
830 |
| - break |
831 | 858 |
|
832 | 859 | return linked_message_id
|
833 | 860 |
|
|
0 commit comments