From 319ff228655c585f3c8c3bdaf463123251fea3c3 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 6 Mar 2021 14:41:38 -0800 Subject: [PATCH] fix media from event in pm --- appservice.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/appservice.py b/appservice.py index b673a05..a0d4ca2 100644 --- a/appservice.py +++ b/appservice.py @@ -157,7 +157,10 @@ def new_message(event, user): pnutpy.api.add_authorization_token(token) embed = [crosspost_raw(event)] - text = prefix + msg_from_event(event) + evtext, evraw = msg_from_event(event) + text = prefix + evtext + if len(evraw) > 0: + embed.append(evraw) try: msg, meta = pnutpy.api.create_message(room.pnut_chan, data={'text': text, 'raw': embed}) revent = Events( @@ -203,6 +206,7 @@ def new_message(event, user): def msg_from_event(event): text = None + raw = {} if event['content']['msgtype'] == 'm.text' or event['content']['msgtype'] == 'm.notice': text = event['content']['body'] @@ -212,7 +216,7 @@ def msg_from_event(event): elif event['content']['msgtype'] == 'm.image': text = event['content']['body'] + "\n" text += app.config['MATRIX_URL'] + '/_matrix/media/r0/download/' + event['content']['url'][6:] - embed.append(raw_from_event(event)) + raw = raw_from_event(event) elif event['content']['msgtype'] == 'm.video': text = event['content']['body'] + "\n" @@ -230,7 +234,7 @@ def msg_from_event(event): logger.debug('-unknown msg type- ' + event['content']['msgtype']) return - return text + return text, raw def crosspost_raw(event): cross_profile = {'username': event['user_id']} @@ -629,7 +633,10 @@ def on_direct_message(event, user, room): pnutpy.api.add_authorization_token(token) embed = [crosspost_raw(event)] - text = prefix + msg_from_event(event) + evtext, evraw = msg_from_event(event) + text = prefix + evtext + if len(evraw) > 0: + embed.append(evraw) try: msg, meta = pnutpy.api.create_message(room.pnut_chan, data={'text': text, 'raw': embed}) revent = Events(