Role and announcement fixes.
authorCMDR furrycat <elite@furrycat.net>
Thu, 6 Oct 2016 15:55:59 +0000 (16:55 +0100)
committerCMDR furrycat <elite@furrycat.net>
Thu, 6 Oct 2016 15:55:59 +0000 (16:55 +0100)
bot.py

diff --git a/bot.py b/bot.py
index d681463..10f8289 100755 (executable)
--- a/bot.py
+++ b/bot.py
@@ -34,6 +34,8 @@ class Identify(Enum):
     elif type(instance) == discord.role.Role:
       return 'Role'
     elif type(instance) == discord.channel.Channel:
+      if instance.type == discord.ChannelType.voice:
+        return 'Voice Channel ({}bps)'.format(instance.bitrate)
       return 'Channel'
 
 dryrun = os.getenv('DRYRUN') is not None
@@ -213,7 +215,7 @@ def say_many(channel, lines, n = 25):
 def highest_role(roles):
   highest = None
   for role in roles:
-    if highest is None or role > highest:
+    if highest is None or role.position > highest.position:
       highest = role
   return highest
 
@@ -750,11 +752,11 @@ def can_manage_announcements(member, channel, command, **args):
         announcer = server.get_member(announcement['member_id'])
         announcer_role = highest_role(announcer.roles)
         member_role = highest_role(member.roles)
-        if member_role > announcer_role:
+        if member_role.position > announcer_role.position:
           log.debug('Member {} on server {} can edit announcements from lower role.'.format(member.name, server.name))
           return announcement
-        elif member_role == announcer_role:
-          if member_role == highest_role(server.roles):
+        elif member_role.position == announcer_role.position:
+          if member_role.position == highest_role(server.roles).position:
             log.debug('Member {} with role {} on server {} can edit announcements.'.format(member.name, member_role.name, server.name))
             return announcement
 
@@ -767,7 +769,7 @@ def can_manage_announcements(member, channel, command, **args):
     bot = server.get_member(client.user.id)
     member_role = highest_role(member.roles)
     bot_role = highest_role(bot.roles)
-    if member_role > bot_role:
+    if member_role.position > bot_role.position:
       log.debug('Member {} with role {} on server {} can create announcements.'.format(member.name, member_role.name, server.name))
       return announcement
 
@@ -1064,7 +1066,7 @@ def schedule_announcement(message, id, **args):
 def manage_announcements(message, command, raw):
   log.debug('Command: {}'.format(raw))
 
-  m = re.match(r'announce(?:ment)?\s+(.+)', raw.lower())
+  m = re.match(r'announce(?:ment)?\s+(.+)', raw, re.IGNORECASE)
   if m is None:
     yield from list_announcements(message)
     return
@@ -1225,12 +1227,12 @@ client = discord.Client()
 def process_module(message, command, raw):
   for module, params in modules.items():
     if command in params['commands']:
-      log.info('Recognised command "{}" from "{}" module'.format(command, module))
+      log.info('Recognised command "{}" from {} in "{}" module'.format(command, message.author.name, module))
       fn = params['fn']
       args = params['args']
       yield from fn(message, command, raw, *args)
       return
-  log.debug('Unrecognised command!')
+  log.debug('Unrecognised command from {}!'.format(message.author.name))
   if status() == discord.Status.idle:
     yield from maybe_say(message.channel, 'zzz', wake = False)
   else: