Merge pull request #45 from ancho/feature/handle-command
use regex match to check if message starts with command
This commit is contained in:
commit
44a888270a
9
bot.py
9
bot.py
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue