Merge pull request #45 from ancho/feature/handle-command

use regex match to check if message starts with command
This commit is contained in:
Frank Becker 2020-02-15 12:04:36 +01:00 committed by GitHub
commit 44a888270a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

9
bot.py
View File

@ -111,9 +111,7 @@ class Bot:
async def message_cb(self, room, event):
# Figure out the command
body = event.body
if len(body) == 0:
return
if body[0] != '!':
if not self.starts_with_command(body):
return
command = body.split().pop(0)
@ -140,6 +138,11 @@ 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):
"""Checks if body starts with ! and has one or more letters after it"""
return re.match(r"^!\w.*", body) is not None
async def invite_cb(self, room, event):
room: MatrixRoom
event: InviteEvent