From eef622400719bfa64a88c6ffc52c243fd3661c4d Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Tue, 9 Jan 2018 16:28:53 -0800 Subject: [PATCH] bypass deleted messages (or rather messages without content) --- pnut-bridge.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/pnut-bridge.py b/pnut-bridge.py index 6a81c09..b593da0 100644 --- a/pnut-bridge.py +++ b/pnut-bridge.py @@ -129,28 +129,29 @@ class ChannelMonitor(threading.Thread): if msg.source.id == app.config['PNUTCLIENT_ID']: continue - user = self.generate_matrix_id(msg.user.username) - text = msg.content.text + "\n" - # dt = datetime.datetime.strptime(msg.created_at, "%Y-%m-%dT%H:%M:%SZ") - dt = msg.created_at - ts = time.mktime(dt.timetuple()) + if 'content' in msg: + user = self.generate_matrix_id(msg.user.username) + text = msg.content.text + "\n" + # dt = datetime.datetime.strptime(msg.created_at, "%Y-%m-%dT%H:%M:%SZ") + dt = msg.created_at + ts = time.mktime(dt.timetuple()) - for lnk in msg.content.entities.links: - text += "\n" - if 'title' in lnk: - text += lnk.title + "\n" - if 'link' in lnk: - text += lnk.link + "\n" + for lnk in msg.content.entities.links: + text += "\n" + if 'title' in lnk: + text += lnk.title + "\n" + if 'link' in lnk: + text += lnk.link + "\n" - for raw in msg.raw: - if raw.type == 'io.pnut.core.oembed': - if 'title' in raw.value: - text += raw.value.title + "\n" - if 'url' in raw.value: - text += raw.value.url + "\n" + for raw in msg.raw: + if raw.type == 'io.pnut.core.oembed': + if 'title' in raw.value: + text += raw.value.title + "\n" + if 'url' in raw.value: + text += raw.value.url + "\n" - # queue the message in reverse order (because of how pnut returns the messages) - pqueue.insert(0, {'user':user,'text':text,'ts':ts,'msgid':msg.id,'puser':msg.user.username,'chan':room.pnut_chan}) + # queue the message in reverse order (because of how pnut returns the messages) + pqueue.insert(0, {'user':user,'text':text,'ts':ts,'msgid':msg.id,'puser':msg.user.username,'chan':room.pnut_chan}) # update the last message id if len(messages) > 0: