hpreston / webexteamsbot

Python package for creating Webex Teams chat bots.
MIT License
54 stars 33 forks source link

The exact command not found #4

Open DockCZ opened 4 years ago

DockCZ commented 4 years ago

Description

When I use bot.add_command and add some test command. Like this: bot.add_command("test", "Test command", getTest)

Than if I send message to my bot where the command word is placed. I get response for the command even if it is not exact command.

From DEBUG

Message content:
Webex Teams Message:
{
  "id": "",
  "roomId": "",
  "roomType": "direct",
  "text": "MyTest",
  "personId": "",
  "personEmail": "",
  "created": "2019-10-22T10:36:15.253Z"
}
Message from: 
Found command: test

Solution

From source: webexteamsbot.py line 312 - 319

            # Find the command that was sent, if any
            command = ""
            for c in sorted(self.commands.items()):
                if message.text.lower().find(c[0]) != -1:
                    command = c[0]
                    sys.stderr.write("Found command: " + command + "\n")
                    # If a command was found, stop looking for others
                    break

My code:

            # Find the command that was sent, if any
            command = ""
            for c in self.commands.items():
                # Checking only for exact match
                if message.text.lower() == c[0]:
                    command = c[0]
                    sys.stderr.write("Found command: " + command + "\n")
                    # If a command was found, stop looking for others
                    break