Dedup and improve identification.
authorCMDR furrycat <elite@furrycat.net>
Fri, 7 Oct 2016 14:26:13 +0000 (15:26 +0100)
committerCMDR furrycat <elite@furrycat.net>
Fri, 7 Oct 2016 14:26:13 +0000 (15:26 +0100)
bot.py

diff --git a/bot.py b/bot.py
index 2d2f071..662fd45 100755 (executable)
--- a/bot.py
+++ b/bot.py
@@ -371,8 +371,12 @@ def identify(destination, target):
           break
     else:
       for member in client.get_all_members():
-        if target and member.name != target:
-          continue
+        if target:
+          parts = target.lower().split('#')
+          if member.name.lower() != parts[0]:
+            continue
+          if len(parts) > 1 and member.discriminator != parts[1]:
+            continue
         results.append(member)
   if do & Identify.role.value:
     if role_id:
@@ -384,7 +388,7 @@ def identify(destination, target):
     else:
       for server in client.servers:
         for role in server.roles:
-          if target and role.name != target:
+          if target and role.name.lower() != target.lower():
             continue
           results.append(role)
   if do & Identify.channel.value:
@@ -394,11 +398,11 @@ def identify(destination, target):
         results.append(channel)
     else:
       for channel in client.get_all_channels():
-        if target and channel.name != target:
+        if target and channel.name.lower() != target.lower():
           continue
         results.append(channel)
 
-  yield from say_many(destination, ['{} {} {}'.format(Identify.string(result), result.id, result.name) for result in results])
+  yield from say_many(destination, ['{} {} {}'.format(Identify.string(result), result.id, result.name) for result in set(results)])
 
 @asyncio.coroutine
 def do_commands(message, command, raw, non_admin):