use regex match to check if message starts with command
This commit is contained in:
parent
ed020229a0
commit
6d0d960eef
6
bot.py
6
bot.py
|
@ -113,7 +113,7 @@ class Bot:
|
||||||
body = event.body
|
body = event.body
|
||||||
if len(body) == 0:
|
if len(body) == 0:
|
||||||
return
|
return
|
||||||
if body[0] != '!':
|
if self.starts_with_command(body) is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
command = body.split().pop(0)
|
command = body.split().pop(0)
|
||||||
|
@ -140,6 +140,10 @@ 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):
|
||||||
|
return re.match(r"^!\w.*", body)
|
||||||
|
|
||||||
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