Skip to content

Commit

Permalink
Merge branch 'autotrigger-alias' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjr committed Aug 21, 2021
2 parents e460565 + 736863b commit 86ccf50
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
16 changes: 8 additions & 8 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,20 +1033,20 @@ async def trigger_auto_triggers(self, message, channel, *, cls=commands.Context)
alias = self.auto_triggers[trigger]

ctxs = []

if alias is not None:
ctxs = []
aliases = normalize_alias(alias)
if not aliases:
logger.warning("Alias %s is invalid as called in autotrigger.", invoker)

for alias in aliases:
view = StringView(invoked_prefix + alias)
ctx_ = cls(prefix=self.prefix, view=view, bot=self, message=message)
ctx_.thread = thread
discord.utils.find(view.skip_string, await self.get_prefix())
ctx_.invoked_with = view.get_word().lower()
ctx_.command = self.all_commands.get(ctx_.invoked_with)
ctxs += [ctx_]
message.author = thread.recipient # Allow for get_contexts to work

for alias in aliases:
message.content = invoked_prefix + alias
ctxs += await self.get_contexts(message)

message.author = self.modmail_guild.me # Fix message so commands execute properly

for ctx in ctxs:
if ctx.command:
Expand Down
2 changes: 2 additions & 0 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,9 @@ async def reply(self, ctx, *, msg: str = ""):
Supports attachments and images as well as
automatically embedding image URLs.
"""

ctx.message.content = msg

async with ctx.typing():
await ctx.thread.reply(ctx.message)

Expand Down
19 changes: 17 additions & 2 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,13 @@ async def autotrigger_add(self, ctx, keyword, *, command):
valid = True
break

if not valid and self.bot.aliases:
for n in range(1, len(split_cmd) + 1):
if self.bot.aliases.get(" ".join(split_cmd[0:n])):
print(self.bot.aliases.get(" ".join(split_cmd[0:n])))
valid = True
break

if valid:
self.bot.auto_triggers[keyword] = command
await self.bot.config.update()
Expand All @@ -1765,7 +1772,7 @@ async def autotrigger_add(self, ctx, keyword, *, command):
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description="Invalid command. Note that autotriggers do not work with aliases.",
description="Invalid command. Please provide a valid command or alias.",
)

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

if not valid and self.bot.aliases:
for n in range(1, len(split_cmd) + 1):
print(" ".join(split_cmd[0:n]), self.bot.aliases.get(" ".join(split_cmd[0:n])))
if self.bot.aliases.get(" ".join(split_cmd[0:n])):
print(self.bot.aliases.get(" ".join(split_cmd[0:n])))
valid = True
break

if valid:
self.bot.auto_triggers[keyword] = command
await self.bot.config.update()
Expand All @@ -1798,7 +1813,7 @@ async def autotrigger_edit(self, ctx, keyword, *, command):
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description="Invalid command. Note that autotriggers do not work with aliases.",
description="Invalid command. Please provide a valid command or alias.",
)

await ctx.send(embed=embed)
Expand Down
1 change: 1 addition & 0 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class Author:
async def activate_auto_triggers():
if initial_message:
message = DummyMessage(copy.copy(initial_message))

try:
return await self.bot.trigger_auto_triggers(message, channel)
except RuntimeError:
Expand Down

0 comments on commit 86ccf50

Please sign in to comment.