Use user avatar if no URL is provided for bling.
authorCMDR furrycat <elite@furrycat.net>
Mon, 26 Sep 2016 13:24:57 +0000 (14:24 +0100)
committerCMDR furrycat <elite@furrycat.net>
Mon, 26 Sep 2016 13:24:57 +0000 (14:24 +0100)
bot.py

diff --git a/bot.py b/bot.py
index 603b6bf..d4eed44 100755 (executable)
--- a/bot.py
+++ b/bot.py
@@ -120,7 +120,7 @@ def delta_avatar(url):
   if not bg or not fg:
     log.warning("Can't open Delta foreground and/or background image!")
     return None
-  cutoff = bg.width / 2
+  cutoff = float(bg.width) / 1.5
 
   # Get provided image.
   fd = open_url(url)
@@ -152,13 +152,13 @@ def delta_avatar(url):
   if image.height > cutoff:
     image.thumbnail((cutoff, cutoff))
   elif image.height < cutoff:
-    width = image.width * 2
-    height = image.height * 2
+    width = math.floor(image.width * (float(fg.width) / cutoff))
+    height = math.floor(image.height * (float(fg.height) / cutoff))
     bg.thumbnail((width, height))
     fg.thumbnail((width, height))
 
   # Pad with blank pixels.
-  padded = Image.new(image.mode, fg.size)
+  padded = Image.new(bg.mode, fg.size)
   left = math.floor((padded.width - image.width) / 2)
   top = math.floor((padded.height - image.height) / 2)
   padded.paste(image, (left, top, left + image.width, top + image.height))
@@ -207,6 +207,9 @@ def do_commands(message, command, raw, non_admin):
       url = m.group(1)
     elif len(message.attachments):
       url = message.attachments[0]['url']
+    else:
+      log.info('Using avatar URL {}'.format(url))
+      url = message.author.avatar_url
     if url is None:
       log.debug('No URL for avatar to Deltaify')
       yield from say(message.channel, 'zzz')
@@ -217,6 +220,7 @@ def do_commands(message, command, raw, non_admin):
       yield from say(message.channel, 'yelp!')
       return
     yield from client.send_file(message.channel, data, filename = message.author.name + '.png', content = message.author.mention if not message.channel.is_private else 'purr')
+    return
 
   elif command == 'debug':
     # debug