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):
|
async def message_cb(self, room, event):
|
||||||
# Figure out the command
|
# Figure out the command
|
||||||
body = event.body
|
body = event.body
|
||||||
if len(body) == 0:
|
if not self.starts_with_command(body):
|
||||||
return
|
|
||||||
if body[0] != '!':
|
|
||||||
return
|
return
|
||||||
|
|
||||||
command = body.split().pop(0)
|
command = body.split().pop(0)
|
||||||
|
@ -140,6 +138,11 @@ class Bot:
|
||||||
await self.send_text(room,
|
await self.send_text(room,
|
||||||
f"Sorry. I don't know what to do. Execute !help to get a list of available commands.")
|
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):
|
async def invite_cb(self, room, event):
|
||||||
room: MatrixRoom
|
room: MatrixRoom
|
||||||
event: InviteEvent
|
event: InviteEvent
|
||||||
|
|
Loading…
Reference in New Issue