Skip to content

Commit e9e8992

Browse files
committed
v3.3.2-dev4 freply, fixed alias bugs, alias and snippet looks
1 parent faeaf49 commit e9e8992

File tree

7 files changed

+172
-166
lines changed

7 files changed

+172
-166
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.
77
however, insignificant breaking changes does not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319).
88

99

10-
# v3.3.2-dev3
10+
# v3.3.2-dev4
1111

1212
### Added
1313

@@ -20,10 +20,16 @@ however, insignificant breaking changes does not guarantee a major version bump,
2020
- "enable" and "disable" support for yes or no config vars.
2121
- Added "perhaps you meant" section to `?config help`.
2222
- Multi-command alias is now more stable. With support for a single quote escape `\"`.
23+
- New command `?freply`, which behaves exactly like `?reply` with the addition that you can substitute `{channel}`, `{recipient}`, and `{author}` to be their respective values.
24+
25+
### Changed
26+
27+
- The look of alias and snippet when previewing.
2328

2429
### Fixed
2530

2631
- Setting config vars using human time wasn't working.
32+
- Fixed some bugs with aliases.
2733

2834
### Internal
2935

bot.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.3.2-dev3"
1+
__version__ = "3.3.2-dev4"
22

33

44
import asyncio
@@ -612,7 +612,7 @@ def check_manual_blocked(self, author: discord.Member) -> bool:
612612
return False
613613

614614
async def _process_blocked(self, message):
615-
sent_emoji, blocked_emoji = await self.retrieve_emoji()
615+
_, blocked_emoji = await self.retrieve_emoji()
616616
if await self.is_blocked(message.author, channel=message.channel, send_message=True):
617617
await self.add_reaction(message, blocked_emoji)
618618
return True
@@ -770,7 +770,7 @@ async def get_contexts(self, message, *, cls=commands.Context):
770770

771771
view = StringView(message.content)
772772
ctx = cls(prefix=self.prefix, view=view, bot=self, message=message)
773-
ctx.thread = await self.threads.find(channel=ctx.channel)
773+
thread = await self.threads.find(channel=ctx.channel)
774774

775775
if self._skip_check(message.author.id, self.user.id):
776776
return [ctx]
@@ -791,16 +791,18 @@ async def get_contexts(self, message, *, cls=commands.Context):
791791
if not aliases:
792792
logger.warning("Alias %s is invalid, removing.", invoker)
793793
self.aliases.pop(invoker)
794+
794795
for alias in aliases:
795-
view = StringView(alias)
796-
ctx = cls(prefix=self.prefix, view=view, bot=self, message=message)
797-
ctx.thread = await self.threads.find(channel=ctx.channel)
798-
ctx.view = view
799-
ctx.invoked_with = view.get_word()
800-
ctx.command = self.all_commands.get(ctx.invoked_with)
801-
ctxs += [ctx]
796+
view = StringView(invoked_prefix + alias)
797+
ctx_ = cls(prefix=self.prefix, view=view, bot=self, message=message)
798+
ctx_.thread = thread
799+
discord.utils.find(view.skip_string, prefixes)
800+
ctx_.invoked_with = view.get_word().lower()
801+
ctx_.command = self.all_commands.get(ctx_.invoked_with)
802+
ctxs += [ctx_]
802803
return ctxs
803804

805+
ctx.thread = thread
804806
ctx.invoked_with = invoker
805807
ctx.command = self.all_commands.get(invoker)
806808
return [ctx]
@@ -872,11 +874,8 @@ async def process_commands(self, message):
872874

873875
# Process snippets
874876
if cmd in self.snippets:
875-
thread = await self.threads.find(channel=message.channel)
876877
snippet = self.snippets[cmd]
877-
if thread:
878-
snippet = self.formatter.format(snippet, recipient=thread.recipient)
879-
message.content = f"{self.prefix}reply {snippet}"
878+
message.content = f"{self.prefix}freply {snippet}"
880879

881880
ctxs = await self.get_contexts(message)
882881
for ctx in ctxs:

cogs/modmail.py

+36-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import discord
88
from discord.ext import commands
9-
from discord.utils import escape_markdown, escape_mentions
9+
from discord.utils import escape_markdown
1010

1111
from dateutil import parser
1212
from natural.date import duration
@@ -21,6 +21,7 @@
2121
create_not_found_embed,
2222
format_description,
2323
trigger_typing,
24+
escape_code_block,
2425
)
2526

2627
logger = getLogger(__name__)
@@ -155,8 +156,10 @@ async def snippet(self, ctx, *, name: str.lower = None):
155156
val = self.bot.snippets.get(name)
156157
if val is None:
157158
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)
160163

161164
if not self.bot.snippets:
162165
embed = discord.Embed(
@@ -186,8 +189,11 @@ async def snippet_raw(self, ctx, *, name: str.lower):
186189
val = self.bot.snippets.get(name)
187190
if val is None:
188191
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)
191197

192198
@snippet.command(name="add")
193199
@checks.has_permissions(PermissionLevel.SUPPORTER)
@@ -782,10 +788,32 @@ async def reply(self, ctx, *, msg: str = ""):
782788
async with ctx.typing():
783789
await ctx.thread.reply(ctx.message)
784790

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"])
786814
@checks.has_permissions(PermissionLevel.SUPPORTER)
787815
@checks.thread_only()
788-
async def anonreply(self, ctx, *, msg: str = ""):
816+
async def areply(self, ctx, *, msg: str = ""):
789817
"""
790818
Reply to a thread anonymously.
791819
@@ -823,11 +851,10 @@ async def find_linked_message(self, ctx, message_id):
823851
continue
824852
# TODO: use regex to find the linked message id
825853
linked_message_id = str(embed.author.url).split("/")[-1]
826-
break
854+
827855
elif message_id and msg.id == message_id:
828856
url = msg.embeds[0].author.url
829857
linked_message_id = str(url).split("/")[-1]
830-
break
831858

832859
return linked_message_id
833860

cogs/plugins.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,12 @@ async def plugins_registry(self, ctx, *, plugin_name: typing.Union[int, str] = N
539539

540540
return await ctx.send(embed=embed)
541541

542-
for plugin_name, details in registry:
543-
details = self.registry[plugin_name]
542+
for name, details in registry:
543+
details = self.registry[name]
544544
user, repo = details["repository"].split("/", maxsplit=1)
545545
branch = details.get("branch")
546546

547-
plugin = Plugin(user, repo, plugin_name, branch)
547+
plugin = Plugin(user, repo, name, branch)
548548

549549
embed = discord.Embed(
550550
color=self.bot.main_color,
@@ -554,7 +554,7 @@ async def plugins_registry(self, ctx, *, plugin_name: typing.Union[int, str] = N
554554
)
555555

556556
embed.add_field(
557-
name="Installation", value=f"```{self.bot.prefix}plugins add {plugin_name}```"
557+
name="Installation", value=f"```{self.bot.prefix}plugins add {name}```"
558558
)
559559

560560
embed.set_author(

0 commit comments

Comments
 (0)