Skip to content

Commit

Permalink
Fix command processing to check for equality
Browse files Browse the repository at this point in the history
The selection on which command was executed used a startswith check. When we have multiple commands that start with the same name, the wrong one might be selected.
In this PR we extract the first token instead and check for equality.
  • Loading branch information
TimJentzsch committed Jan 27, 2022
1 parent 8eec9d1 commit 1da957a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions api/slack/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ def process_message(data: Dict) -> None:
"dadjoke": dadjoke_cmd,
}

for key in options.keys():
if message.startswith(key):
options[key](channel, message)
return
tokens = message.split()

if len(tokens) > 0:
# Find the command corresponding to the message
cmd_name = tokens[0].casefold()
for key in options.keys():
if cmd_name == key:
options[key](channel, message)
return

# if we fall through here, we got a message that we don't understand.
client.chat_postMessage(
Expand Down

0 comments on commit 1da957a

Please sign in to comment.