parent
40b54076e0
commit
dbfc1b5082
1 changed files with 18 additions and 2 deletions
|
@ -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-')
|
||||
|
|
Loading…
Reference in a new issue