From: CMDR furrycat Date: Thu, 2 Mar 2017 11:46:36 +0000 (+0000) Subject: Handle user name when setting permissions. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=94761348313c40ce609dd559eb4971f864ce4373;p=furrycat%2Fcatbot.git Handle user name when setting permissions. --- diff --git a/bot.py b/bot.py index 090fe20..42712c4 100644 --- a/bot.py +++ b/bot.py @@ -330,6 +330,17 @@ def parse_mention(text, *, author = None): log.warning("Can't parse {}!".format(text)) return None +async def parse_user(text, *, author = None): + if not re.match(r'^[\d@&<]', text): + text = '@' + text + parsed = parse_mention(text, author = author) + if parsed is None: + return None + if not re.match(r'^\d+$', parsed): + return None + user = await client.get_user_info(parsed) + return user + def format_mention(mention): if mention in ['everyone', 'here']: return '@{}'.format(mention) diff --git a/plugin/admin/admin.py b/plugin/admin/admin.py index 6fb9fc3..e36aadf 100644 --- a/plugin/admin/admin.py +++ b/plugin/admin/admin.py @@ -169,6 +169,10 @@ class Admin(object): parsed = bot.parse_mention(who, author = message.author) if parsed is None: + user = await bot.parse_user(who, author = message.author) + if user is not None: + parsed = user.id + if parsed is None: await bot.say(message.channel, '{}?'.format(who)) return if parsed[0] == '#': @@ -213,7 +217,7 @@ class Admin(object): if parsed[0] == '&': await client.edit_role(server, target, permissions = permissions) else: - await bot.say('Need channel to update member permissions!') + await bot.say(message.channel, 'Need channel to update member permissions!') return await cat.purr(message.channel)