From dbfc1b50829058b745c4bf450a9405eb094c0784 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Fri, 8 May 2020 08:36:03 -0700 Subject: [PATCH] support longposts for messages sent to global resovles issue #50 --- appservice.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/appservice.py b/appservice.py index 151daf9..23ad6b4 100644 --- a/appservice.py +++ b/appservice.py @@ -3,6 +3,8 @@ import requests import logging import re import pnutpy +import textwrap +import time from matrix_client.api import MatrixHttpApi from matrix_client.api import MatrixError, MatrixRequestError @@ -193,10 +195,24 @@ def new_message(event, user): if user is not None: cctag = re.search('##$', text) if cctag: + raw = [] cname = get_channel_settings(room.pnut_chan)['name'] text = text[:-2] - text += '\n\n[' + cname + "](https://patter.chat/room.html?channel=" + str(room.pnut_chan) + ")" - r, meta = pnutpy.api.create_post(data={'text': text}) + ftext = '\n\n[' + cname + "](https://patter.chat/room.html?channel=" + str(room.pnut_chan) + ")" + mtext = textwrap.wrap(text + ftext, 254) + if len(mtext) > 1: + longpost = { + 'title': "", + 'body': text, + 'tstamp': time.time() * 1000 + } + pretext = textwrap.wrap(text, 100) + text = pretext[0] + text += "... - https://longpo.st/p/{object_id} - #longpost" + raw.append({'type':"nl.chimpnut.blog.post", 'value': longpost}) + + text += ftext + r, meta = pnutpy.api.create_post(data={'text': text, 'raw': raw}) except pnutpy.errors.PnutAuthAPIException: logger.exception('-unable to post to pnut channel-')