@@ -955,6 +955,16 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
955
955
await self .add_reaction (message , sent_emoji )
956
956
self .dispatch ("thread_reply" , thread , False , message , False , False )
957
957
958
+ def _get_snippet_command (self ) -> commands .Command :
959
+ """Get the correct reply command based on the snippet config"""
960
+ modifiers = "f"
961
+ if self .config ["plain_snippets" ]:
962
+ modifiers += "p"
963
+ if self .config ["anonymous_snippets" ]:
964
+ modifiers += "a"
965
+
966
+ return self .get_command (f'{ modifiers } reply' )
967
+
958
968
async def get_contexts (self , message , * , cls = commands .Context ):
959
969
"""
960
970
Returns all invocation contexts from the message.
@@ -986,18 +996,40 @@ async def get_contexts(self, message, *, cls=commands.Context):
986
996
self .aliases .pop (invoker )
987
997
988
998
for alias in aliases :
989
- view = StringView (invoked_prefix + alias )
999
+ command = None
1000
+ try :
1001
+ snippet_text = self .snippets [alias ]
1002
+ except KeyError :
1003
+ command_invocation_text = alias
1004
+ else :
1005
+ command = self ._get_snippet_command ()
1006
+ command_invocation_text = f'{ invoked_prefix } { command } { snippet_text } '
1007
+
1008
+ view = StringView (invoked_prefix + command_invocation_text )
990
1009
ctx_ = cls (prefix = self .prefix , view = view , bot = self , message = message )
991
1010
ctx_ .thread = thread
992
1011
discord .utils .find (view .skip_string , prefixes )
993
1012
ctx_ .invoked_with = view .get_word ().lower ()
994
- ctx_ .command = self .all_commands .get (ctx_ .invoked_with )
1013
+ ctx_ .command = command or self .all_commands .get (ctx_ .invoked_with )
995
1014
ctxs += [ctx_ ]
996
1015
return ctxs
997
1016
998
1017
ctx .thread = thread
999
- ctx .invoked_with = invoker
1000
- ctx .command = self .all_commands .get (invoker )
1018
+
1019
+ try :
1020
+ snippet_text = self .snippets [invoker ]
1021
+ except KeyError :
1022
+ # Process regular commands
1023
+ ctx .command = self .all_commands .get (invoker )
1024
+ ctx .invoked_with = invoker
1025
+ else :
1026
+ # Process snippets
1027
+ ctx .command = self ._get_snippet_command ()
1028
+ reply_view = StringView (f'{ invoked_prefix } { ctx .command } { snippet_text } ' )
1029
+ discord .utils .find (reply_view .skip_string , prefixes )
1030
+ ctx .invoked_with = reply_view .get_word ().lower ()
1031
+ ctx .view = reply_view
1032
+
1001
1033
return [ctx ]
1002
1034
1003
1035
async def trigger_auto_triggers (self , message , channel , * , cls = commands .Context ):
@@ -1139,20 +1171,6 @@ async def process_commands(self, message):
1139
1171
if isinstance (message .channel , discord .DMChannel ):
1140
1172
return await self .process_dm_modmail (message )
1141
1173
1142
- if message .content .startswith (self .prefix ):
1143
- cmd = message .content [len (self .prefix ) :].strip ()
1144
-
1145
- # Process snippets
1146
- cmd = cmd .lower ()
1147
- if cmd in self .snippets :
1148
- snippet = self .snippets [cmd ]
1149
- modifiers = "f"
1150
- if self .config ["plain_snippets" ]:
1151
- modifiers += "p"
1152
- if self .config ["anonymous_snippets" ]:
1153
- modifiers += "a"
1154
- message .content = f"{ self .prefix } { modifiers } reply { snippet } "
1155
-
1156
1174
ctxs = await self .get_contexts (message )
1157
1175
for ctx in ctxs :
1158
1176
if ctx .command :
0 commit comments