Merge branch 'master' of github.com:vranki/hemppa

This commit is contained in:
Frank Becker 2020-02-16 16:45:26 +01:00
commit 238b32fbe0
2 changed files with 15 additions and 8 deletions

13
bot.py
View File

@ -133,9 +133,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)
@ -159,8 +157,15 @@ class Bot:
traceback.print_exc(file=sys.stderr)
else:
self.logger.error(f"Unknown command: {command}")
await self.send_text(room, f"Sorry. I don't know what to do. Execute !help to get a list of available commands.")
# TODO Make this configurable
# 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

View File

@ -41,7 +41,10 @@ class MatrixModule(BotModule):
await self.disable_module(bot, room, event, args[2])
else:
await bot.send_text(room, 'Unknown command, sorry.')
pass
# TODO: Make this configurable. By default don't say anything.
# await bot.send_text(room, 'Unknown command, sorry.')
async def leave(self, bot, room, event):
bot.must_be_admin(room, event)
@ -121,9 +124,8 @@ class MatrixModule(BotModule):
async def show_modules(self, bot, room):
await bot.send_text(room, "Modules:\n")
for modulename, module in collections.OrderedDict(sorted(bot.modules.items())).items():
module_message = f"Name: {modulename}\n"\
f"Enabled: {module.enabled} (Can be disabled: {module.can_be_disabled})\n"\
f"Description: {module.help()}\n"
state = 'Enabled' if module.enabled else 'Disabled'
module_message = f"{state}: {modulename} - {module.help()}"
await bot.send_text(room, module_message)
def help(self):