From 76e1c15b6995a5c93ef3c61d67ee5c20ca42a565 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Fri, 2 Jun 2017 06:55:14 -0700 Subject: [PATCH] fix keyerror when thumbnail isn't available --- appservice.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/appservice.py b/appservice.py index cf967f2..d881b5f 100644 --- a/appservice.py +++ b/appservice.py @@ -56,15 +56,21 @@ def on_receive_events(transaction): text = "* " + get_displayname(event["user_id"]) + " " + event['content']['body'] elif event['content']['msgtype'] == 'm.image': imgurl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['url'][6:] - thmburl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['info']['thumbnail_url'][6:] + value = {"type": "photo", "version": "1.0"} value["title"] = event['content']['body'] value["url"] = imgurl value["width"] = event['content']['info']['w'] value["height"] = event['content']['info']['h'] - value["thumbnail_width"] = event['content']['info']['thumbnail_info']['w'] - value["thumbnail_height"] = event['content']['info']['thumbnail_info']['h'] - value["thumbnail_url"] = thmburl + if 'thumbnail_info' in event['content']['info']: + thmburl = app.config['MATRIX_HOST'] + '/_matrix/media/r0/download/' + event['content']['info']['thumbnail_url'][6:] + value["thumbnail_width"] = event['content']['info']['thumbnail_info']['w'] + value["thumbnail_height"] = event['content']['info']['thumbnail_info']['h'] + value["thumbnail_url"] = thmburl + else: + value["thumbnail_width"] = event['content']['info']['w'] + value["thumbnail_height"] = event['content']['info']['h'] + value["thumbnail_url"] = imgurl rawitem = {"type": "io.pnut.core.oembed", "value": value} embed = [rawitem] if user: