Add !help [modulename]
This commit is contained in:
parent
b6774f15a4
commit
77d30c6a82
|
@ -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
|
||||
|
|
|
@ -4,16 +4,30 @@ from modules.common.module import BotModule
|
|||
class MatrixModule(BotModule):
|
||||
|
||||
async def matrix_message(self, bot, room, event):
|
||||
msg = f'This is Hemppa {bot.version}, a generic Matrix bot. Known commands:\n\n'
|
||||
|
||||
for modulename, moduleobject in bot.modules.items():
|
||||
if moduleobject.enabled:
|
||||
msg = msg + '!' + modulename
|
||||
try:
|
||||
msg = msg + ' - ' + moduleobject.help() + '\n'
|
||||
except AttributeError:
|
||||
pass
|
||||
msg = msg + "\nMore information at https://github.com/vranki/hemppa"
|
||||
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():
|
||||
if moduleobject.enabled:
|
||||
msg = msg + '!' + modulename
|
||||
try:
|
||||
msg = msg + ' - ' + moduleobject.help() + '\n'
|
||||
except AttributeError:
|
||||
pass
|
||||
msg = msg + "\nMore information at https://github.com/vranki/hemppa"
|
||||
await bot.send_text(room, msg)
|
||||
|
||||
def help(self):
|
||||
|
|
Loading…
Reference in New Issue