Skip to content

Commit ba93b9c

Browse files
committed
Handle multi-word snippets
1 parent 3599f02 commit ba93b9c

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

bot.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,17 @@ async def get_contexts(self, message, *, cls=commands.Context):
10101010

10111011
invoker = view.get_word().lower()
10121012

1013+
# Check if a snippet is being called.
1014+
# This needs to be done before checking for aliases since
1015+
# snippets can have multiple words.
1016+
try:
1017+
snippet_text = self.snippets[message.content.removeprefix(invoked_prefix)]
1018+
except KeyError:
1019+
snippet_text = None
1020+
10131021
# Check if there is any aliases being called.
10141022
alias = self.aliases.get(invoker)
1015-
if alias is not None:
1023+
if alias is not None and snippet_text is None:
10161024
ctxs = []
10171025
aliases = normalize_alias(alias, message.content[len(f"{invoked_prefix}{invoker}") :])
10181026
if not aliases:
@@ -1028,7 +1036,6 @@ async def get_contexts(self, message, *, cls=commands.Context):
10281036
else:
10291037
command = self._get_snippet_command()
10301038
command_invocation_text = f'{invoked_prefix}{command} {snippet_text}'
1031-
10321039
view = StringView(invoked_prefix + command_invocation_text)
10331040
ctx_ = cls(prefix=self.prefix, view=view, bot=self, message=message)
10341041
ctx_.thread = thread
@@ -1040,19 +1047,16 @@ async def get_contexts(self, message, *, cls=commands.Context):
10401047

10411048
ctx.thread = thread
10421049

1043-
try:
1044-
snippet_text = self.snippets[invoker]
1045-
except KeyError:
1046-
# Process regular commands
1047-
ctx.command = self.all_commands.get(invoker)
1048-
ctx.invoked_with = invoker
1049-
else:
1050+
if snippet_text is not None:
10501051
# Process snippets
10511052
ctx.command = self._get_snippet_command()
10521053
reply_view = StringView(f'{invoked_prefix}{ctx.command} {snippet_text}')
10531054
discord.utils.find(reply_view.skip_string, prefixes)
10541055
ctx.invoked_with = reply_view.get_word().lower()
10551056
ctx.view = reply_view
1057+
else:
1058+
ctx.command = self.all_commands.get(invoker)
1059+
ctx.invoked_with = invoker
10561060

10571061
return [ctx]
10581062

cogs/utility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ async def make_alias(self, name, value, action):
10831083
linked_command = view.get_word().lower()
10841084
message = view.read_rest()
10851085

1086-
is_snippet = linked_command in self.bot.snippets and not message
1086+
is_snippet = val in self.bot.snippets
10871087

10881088
if not self.bot.get_command(linked_command) and not is_snippet:
10891089
alias_command = self.bot.aliases.get(linked_command)

0 commit comments

Comments
 (0)