fix media from event in pm
This commit is contained in:
parent
d1cc3f5949
commit
319ff22865
1 changed files with 11 additions and 4 deletions
|
@ -157,7 +157,10 @@ def new_message(event, user):
|
||||||
pnutpy.api.add_authorization_token(token)
|
pnutpy.api.add_authorization_token(token)
|
||||||
|
|
||||||
embed = [crosspost_raw(event)]
|
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:
|
try:
|
||||||
msg, meta = pnutpy.api.create_message(room.pnut_chan, data={'text': text, 'raw': embed})
|
msg, meta = pnutpy.api.create_message(room.pnut_chan, data={'text': text, 'raw': embed})
|
||||||
revent = Events(
|
revent = Events(
|
||||||
|
@ -203,6 +206,7 @@ def new_message(event, user):
|
||||||
|
|
||||||
def msg_from_event(event):
|
def msg_from_event(event):
|
||||||
text = None
|
text = None
|
||||||
|
raw = {}
|
||||||
if event['content']['msgtype'] == 'm.text' or event['content']['msgtype'] == 'm.notice':
|
if event['content']['msgtype'] == 'm.text' or event['content']['msgtype'] == 'm.notice':
|
||||||
text = event['content']['body']
|
text = event['content']['body']
|
||||||
|
|
||||||
|
@ -212,7 +216,7 @@ def msg_from_event(event):
|
||||||
elif event['content']['msgtype'] == 'm.image':
|
elif event['content']['msgtype'] == 'm.image':
|
||||||
text = event['content']['body'] + "\n"
|
text = event['content']['body'] + "\n"
|
||||||
text += app.config['MATRIX_URL'] + '/_matrix/media/r0/download/' + event['content']['url'][6:]
|
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':
|
elif event['content']['msgtype'] == 'm.video':
|
||||||
text = event['content']['body'] + "\n"
|
text = event['content']['body'] + "\n"
|
||||||
|
@ -230,7 +234,7 @@ def msg_from_event(event):
|
||||||
logger.debug('-unknown msg type- ' + event['content']['msgtype'])
|
logger.debug('-unknown msg type- ' + event['content']['msgtype'])
|
||||||
return
|
return
|
||||||
|
|
||||||
return text
|
return text, raw
|
||||||
|
|
||||||
def crosspost_raw(event):
|
def crosspost_raw(event):
|
||||||
cross_profile = {'username': event['user_id']}
|
cross_profile = {'username': event['user_id']}
|
||||||
|
@ -629,7 +633,10 @@ def on_direct_message(event, user, room):
|
||||||
pnutpy.api.add_authorization_token(token)
|
pnutpy.api.add_authorization_token(token)
|
||||||
|
|
||||||
embed = [crosspost_raw(event)]
|
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:
|
try:
|
||||||
msg, meta = pnutpy.api.create_message(room.pnut_chan, data={'text': text, 'raw': embed})
|
msg, meta = pnutpy.api.create_message(room.pnut_chan, data={'text': text, 'raw': embed})
|
||||||
revent = Events(
|
revent = Events(
|
||||||
|
|
Loading…
Reference in a new issue