parent
40b54076e0
commit
dbfc1b5082
1 changed files with 18 additions and 2 deletions
|
@ -3,6 +3,8 @@ import requests
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import pnutpy
|
import pnutpy
|
||||||
|
import textwrap
|
||||||
|
import time
|
||||||
|
|
||||||
from matrix_client.api import MatrixHttpApi
|
from matrix_client.api import MatrixHttpApi
|
||||||
from matrix_client.api import MatrixError, MatrixRequestError
|
from matrix_client.api import MatrixError, MatrixRequestError
|
||||||
|
@ -193,10 +195,24 @@ def new_message(event, user):
|
||||||
if user is not None:
|
if user is not None:
|
||||||
cctag = re.search('##$', text)
|
cctag = re.search('##$', text)
|
||||||
if cctag:
|
if cctag:
|
||||||
|
raw = []
|
||||||
cname = get_channel_settings(room.pnut_chan)['name']
|
cname = get_channel_settings(room.pnut_chan)['name']
|
||||||
text = text[:-2]
|
text = text[:-2]
|
||||||
text += '\n\n[' + cname + "](https://patter.chat/room.html?channel=" + str(room.pnut_chan) + ")"
|
ftext = '\n\n[' + cname + "](https://patter.chat/room.html?channel=" + str(room.pnut_chan) + ")"
|
||||||
r, meta = pnutpy.api.create_post(data={'text': text})
|
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:
|
except pnutpy.errors.PnutAuthAPIException:
|
||||||
logger.exception('-unable to post to pnut channel-')
|
logger.exception('-unable to post to pnut channel-')
|
||||||
|
|
Loading…
Reference in a new issue