Skip to content

Commit 1bc9e60

Browse files
authored
Added more shortcuts in our test server and noticed some bugs, have been resolved now.
1 parent c03a5b3 commit 1bc9e60

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"githubPullRequests.ignoredPullRequestBranches": [
3+
"master"
4+
]
5+
}

dozer/cogs/shortcuts.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -143,35 +143,35 @@ async def on_message(self, msg: discord.Message):
143143
prefix = setting.prefix
144144
prefix_index = msg.content.find(prefix)
145145

146+
146147
if prefix_index != -1:
147148
# before running any chatgpt stuff, check if there's a space between prefix and shortcut
148149
if prefix_index + len(prefix) < len(msg.content) and msg.content[prefix_index + len(prefix)] == ' ':
149150
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
151152
start_index = prefix_index + len(prefix)
152153
remaining_content = msg.content[start_index:].strip()
154+
first_word = remaining_content.split()[0] if remaining_content else ''
153155

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)
156158
all_shortcuts = [s.name for s in all_shortcuts]
157159

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)
159161

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
161163
shortcut_name = best_match[0]
162164

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)
175175
else:
176176
# If the prefix is not found in the message, do nothing
177177
pass

0 commit comments

Comments
 (0)