Add support for private message #1 #70

Merged
thrrgilag merged 6 commits from pnut_pm into main 2021-03-20 13:26:34 +00:00
Showing only changes of commit 319ff22865 - Show all commits

View file

@ -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(