Merge pull request #164 from xPMo/master

!sethelp info and more
This commit is contained in:
Ville Ranki 2021-08-02 20:19:03 +03:00 committed by GitHub
commit 20539782e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 12 deletions

View File

@ -10,12 +10,14 @@ class MatrixModule(BotModule):
def get_settings(self): def get_settings(self):
data = super().get_settings() data = super().get_settings()
data['msg_users'] = self.msg_users data['msg_users'] = self.msg_users
data['info'] = self.info
return data return data
def set_settings(self, data): def set_settings(self, data):
super().set_settings(data) super().set_settings(data)
if data.get('msg_users'): if data.get('msg_users'):
self.msg_users = data['msg_users'] self.msg_users = data['msg_users']
self.info = data.get('info') or "\nMore information at https://github.com/vranki/hemppa"
def matrix_start(self, bot): def matrix_start(self, bot):
super().matrix_start(bot) super().matrix_start(bot)
@ -23,26 +25,27 @@ class MatrixModule(BotModule):
async def matrix_message(self, bot, room, event): async def matrix_message(self, bot, room, event):
args = event.body.split() args = event.body.split(None, 2)
cmd = args.pop(0) cmd = args.pop(0)
if cmd == '!sethelp': if cmd == '!sethelp':
bot.must_be_owner(event) bot.must_be_owner(event)
if len(args) != 2:
await bot.send_text(room, f'{cmd} requires two arguments')
return
if args[0].lower() in ['msg_users', 'msg-users', 'msg']: if args[0].lower() in ['msg_users', 'msg-users', 'msg']:
if args[1].lower() in ['true', '1', 'yes', 'y']: if args[1].lower() in ['true', '1', 'yes', 'y']:
self.msg_users = True self.msg_users = True
await bot.send_text(room, '!help will now message users instead of posting to the room') msg = '!help will now message users instead of posting to the room'
else: else:
self.msg_users = False self.msg_users = False
bot.send_text(room, '!help will now post to the room instead of messaging users') msg = '!help will now post to the room instead of messaging users'
bot.save_settings()
elif args[0].lower() in ['info']:
self.info = args[1] or "More information at https://github.com/vranki/hemppa"
msg = '!help info string set'
bot.save_settings() bot.save_settings()
else: else:
await bot.send_text(room, f'Not a !help setting: {args[0]}') await bot.send_text(room, f'Not a !help setting: {args[0]}')
return
elif len(args) == 1:
if len(args) == 1:
msg = '' msg = ''
modulename = args.pop(0) modulename = args.pop(0)
moduleobject = bot.modules.get(modulename) moduleobject = bot.modules.get(modulename)
@ -54,16 +57,16 @@ class MatrixModule(BotModule):
msg += f'{modulename} has no help' msg += f'{modulename} has no help'
else: else:
msg = f'This is Hemppa {bot.version}, a generic Matrix bot. Known commands:\n\n' msg = f'This is Hemppa {bot.version}, a generic Matrix bot. Known commands:\n'
for modulename, moduleobject in bot.modules.items(): for modulename, moduleobject in bot.modules.items():
if moduleobject.enabled: if moduleobject.enabled:
msg = msg + '!' + modulename msg = msg + '- !' + modulename
try: try:
msg = msg + ' - ' + moduleobject.help() + '\n' msg = msg + ': ' + moduleobject.help() + '\n'
except AttributeError: except AttributeError:
pass pass
msg = msg + "\nMore information at https://github.com/vranki/hemppa" msg = msg + '\n' + self.info
if self.msg_users: if self.msg_users:
await bot.send_msg(event.sender, f'Chat with {bot.matrix_user}', msg) await bot.send_msg(event.sender, f'Chat with {bot.matrix_user}', msg)
else: else: