Add !help [modulename]

This commit is contained in:
gammafn 2021-03-29 15:46:59 -05:00
parent b6774f15a4
commit 77d30c6a82
2 changed files with 35 additions and 10 deletions

View File

@ -75,7 +75,18 @@ class BotModule(ABC):
@abstractmethod
def help(self):
"""Return one-liner help text"""
pass
return 'A cool hemppa module'
def long_help(self, bot=None, room=None, event=None, args=[]):
"""Return longer help text
Used by help module as !help modulename [args ...]
bot, room, and event are passed to allow a module
to give contextual help
If not defined, falls back to short help
"""
return self.help()
def get_settings(self):
"""Must return a dict object that can be converted to JSON and sent to server

View File

@ -4,6 +4,20 @@ from modules.common.module import BotModule
class MatrixModule(BotModule):
async def matrix_message(self, bot, room, event):
args = event.body.split()[1:]
if len(args) > 0:
msg = ''
modulename = args.pop(0)
moduleobject = bot.modules.get(modulename)
if not moduleobject.enabled:
msg += f'{modulename} is disabled\n'
try:
msg += moduleobject.long_help(bot=bot, room=room, event=event, args=args)
except AttributeError:
msg += f'{modulename} has no help'
else:
msg = f'This is Hemppa {bot.version}, a generic Matrix bot. Known commands:\n\n'
for modulename, moduleobject in bot.modules.items():