From 6d0d960eef31a7a79cb362d6c481450e96f18c68 Mon Sep 17 00:00:00 2001 From: Frank Becker Date: Thu, 13 Feb 2020 22:50:23 +0100 Subject: [PATCH] use regex match to check if message starts with command --- bot.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 6f08848..6ffdaa9 100755 --- a/bot.py +++ b/bot.py @@ -113,7 +113,7 @@ class Bot: body = event.body if len(body) == 0: return - if body[0] != '!': + if self.starts_with_command(body) is None: return command = body.split().pop(0) @@ -140,6 +140,10 @@ class Bot: await self.send_text(room, f"Sorry. I don't know what to do. Execute !help to get a list of available commands.") + @staticmethod + def starts_with_command(body): + return re.match(r"^!\w.*", body) + async def invite_cb(self, room, event): room: MatrixRoom event: InviteEvent