Skip to content

Commit 86ccf50

Browse files
committed
Merge branch 'autotrigger-alias' into development
2 parents e460565 + 736863b commit 86ccf50

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

bot.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,20 +1033,20 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context)
10331033
alias = self.auto_triggers[trigger]
10341034

10351035
ctxs = []
1036+
10361037
if alias is not None:
10371038
ctxs = []
10381039
aliases = normalize_alias(alias)
10391040
if not aliases:
10401041
logger.warning("Alias %s is invalid as called in autotrigger.", invoker)
10411042

1042-
for alias in aliases:
1043-
view = StringView(invoked_prefix + alias)
1044-
ctx_ = cls(prefix=self.prefix, view=view, bot=self, message=message)
1045-
ctx_.thread = thread
1046-
discord.utils.find(view.skip_string, await self.get_prefix())
1047-
ctx_.invoked_with = view.get_word().lower()
1048-
ctx_.command = self.all_commands.get(ctx_.invoked_with)
1049-
ctxs += [ctx_]
1043+
message.author = thread.recipient # Allow for get_contexts to work
1044+
1045+
for alias in aliases:
1046+
message.content = invoked_prefix + alias
1047+
ctxs += await self.get_contexts(message)
1048+
1049+
message.author = self.modmail_guild.me # Fix message so commands execute properly
10501050

10511051
for ctx in ctxs:
10521052
if ctx.command:

cogs/modmail.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,9 @@ async def reply(self, ctx, *, msg: str = ""):
11661166
Supports attachments and images as well as
11671167
automatically embedding image URLs.
11681168
"""
1169+
11691170
ctx.message.content = msg
1171+
11701172
async with ctx.typing():
11711173
await ctx.thread.reply(ctx.message)
11721174

cogs/utility.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,13 @@ async def autotrigger_add(self, ctx, keyword, *, command):
17521752
valid = True
17531753
break
17541754

1755+
if not valid and self.bot.aliases:
1756+
for n in range(1, len(split_cmd) + 1):
1757+
if self.bot.aliases.get(" ".join(split_cmd[0:n])):
1758+
print(self.bot.aliases.get(" ".join(split_cmd[0:n])))
1759+
valid = True
1760+
break
1761+
17551762
if valid:
17561763
self.bot.auto_triggers[keyword] = command
17571764
await self.bot.config.update()
@@ -1765,7 +1772,7 @@ async def autotrigger_add(self, ctx, keyword, *, command):
17651772
embed = discord.Embed(
17661773
title="Error",
17671774
color=self.bot.error_color,
1768-
description="Invalid command. Note that autotriggers do not work with aliases.",
1775+
description="Invalid command. Please provide a valid command or alias.",
17691776
)
17701777

17711778
await ctx.send(embed=embed)
@@ -1785,6 +1792,14 @@ async def autotrigger_edit(self, ctx, keyword, *, command):
17851792
valid = True
17861793
break
17871794

1795+
if not valid and self.bot.aliases:
1796+
for n in range(1, len(split_cmd) + 1):
1797+
print(" ".join(split_cmd[0:n]), self.bot.aliases.get(" ".join(split_cmd[0:n])))
1798+
if self.bot.aliases.get(" ".join(split_cmd[0:n])):
1799+
print(self.bot.aliases.get(" ".join(split_cmd[0:n])))
1800+
valid = True
1801+
break
1802+
17881803
if valid:
17891804
self.bot.auto_triggers[keyword] = command
17901805
await self.bot.config.update()
@@ -1798,7 +1813,7 @@ async def autotrigger_edit(self, ctx, keyword, *, command):
17981813
embed = discord.Embed(
17991814
title="Error",
18001815
color=self.bot.error_color,
1801-
description="Invalid command. Note that autotriggers do not work with aliases.",
1816+
description="Invalid command. Please provide a valid command or alias.",
18021817
)
18031818

18041819
await ctx.send(embed=embed)

core/thread.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class Author:
264264
async def activate_auto_triggers():
265265
if initial_message:
266266
message = DummyMessage(copy.copy(initial_message))
267+
267268
try:
268269
return await self.bot.trigger_auto_triggers(message, channel)
269270
except RuntimeError:

0 commit comments

Comments
 (0)