@@ -143,35 +143,35 @@ async def on_message(self, msg: discord.Message):
143
143
prefix = setting .prefix
144
144
prefix_index = msg .content .find (prefix )
145
145
146
+
146
147
if prefix_index != - 1 :
147
148
# before running any chatgpt stuff, check if there's a space between prefix and shortcut
148
149
if prefix_index + len (prefix ) < len (msg .content ) and msg .content [prefix_index + len (prefix )] == ' ' :
149
150
return # there's a space, so it was probably meant to be used in text rather than call a shortcut
150
- # Extract the command part from the message directly after the prefix
151
+ # Extract the word immediately after the prefix
151
152
start_index = prefix_index + len (prefix )
152
153
remaining_content = msg .content [start_index :].strip ()
154
+ first_word = remaining_content .split ()[0 ] if remaining_content else ''
153
155
154
- # Check if the remaining content starts with a valid command name
155
- all_shortcuts = await ShortcutEntry .get_by (guild_id = msg .guild .id )
156
+ # Check if the first word is a valid command name
157
+ all_shortcuts = await ShortcutEntry .get_by (guild_id = msg .guild .id )
156
158
all_shortcuts = [s .name for s in all_shortcuts ]
157
159
158
- best_match = process .extractOne (remaining_content , all_shortcuts , scorer = fuzz .partial_ratio )
160
+ best_match = process .extractOne (first_word , all_shortcuts , scorer = fuzz .partial_ratio )
159
161
160
- if best_match and best_match [1 ] > 90 : # Adjust the threshold as needed
162
+ if best_match and best_match [1 ] > 80 : # Adjust the threshold as needed
161
163
shortcut_name = best_match [0 ]
162
164
163
- # Ensure the command follows immediately after the prefix without any intervening characters
164
- if remaining_content .startswith (shortcut_name .casefold ()):
165
- shortcut = await ShortcutEntry .get_unique_by (guild_id = msg .guild .id , name = shortcut_name )
166
- if msg .reference :
167
- # Fetch the original message being replied to
168
- original_message = await msg .channel .fetch_message (msg .reference .message_id )
169
- if original_message :
170
- # Ping the original author in the new message
171
- await original_message .reply (f"{ shortcut .value } " )
172
- else :
173
- # Send the shortcut value without pinging if original message is not found
174
- await msg .channel .send (shortcut .value )
165
+ shortcut = await ShortcutEntry .get_unique_by (guild_id = msg .guild .id , name = shortcut_name )
166
+ if msg .reference :
167
+ # Fetch the original message being replied to
168
+ original_message = await msg .channel .fetch_message (msg .reference .message_id )
169
+ if original_message :
170
+ # Ping the original author in the new message
171
+ await original_message .reply (f"{ shortcut .value } " )
172
+ else :
173
+ # Send the shortcut value without pinging if original message is not found
174
+ await msg .channel .send (shortcut .value )
175
175
else :
176
176
# If the prefix is not found in the message, do nothing
177
177
pass
0 commit comments