use regex match to check if message starts with command

This commit is contained in:
Frank Becker 2020-02-13 22:50:23 +01:00
parent ed020229a0
commit 6d0d960eef
1 changed files with 5 additions and 1 deletions

6
bot.py
View File

@ -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