Handle user name when setting permissions.
authorCMDR furrycat <elite@furrycat.net>
Thu, 2 Mar 2017 11:46:36 +0000 (11:46 +0000)
committerCMDR furrycat <elite@furrycat.net>
Thu, 2 Mar 2017 11:46:36 +0000 (11:46 +0000)
bot.py
plugin/admin/admin.py

diff --git a/bot.py b/bot.py
index 090fe20..42712c4 100644 (file)
--- 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)
index 6fb9fc3..e36aadf 100644 (file)
@@ -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)