parent
dbfc1b5082
commit
25ac47d049
1 changed files with 23 additions and 7 deletions
|
@ -140,16 +140,34 @@ def new_message(event, user):
|
||||||
logger.debug('-unknown message type-')
|
logger.debug('-unknown message type-')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
cross_profile = {'username': event['user_id']}
|
||||||
|
matrix_profile = get_profile(event['user_id'])
|
||||||
|
if "avatar_url" in matrix_profile:
|
||||||
|
cross_profile['avatar_image'] = app.config['MATRIX_URL'] + '/_matrix/media/r0/download/' + matrix_profile['avatar_url'][6:]
|
||||||
|
|
||||||
if user is not None:
|
if user is not None:
|
||||||
token = user.pnut_user_token
|
token = user.pnut_user_token
|
||||||
prefix = ""
|
prefix = ""
|
||||||
else:
|
else:
|
||||||
token = app.config['MATRIX_PNUT_TOKEN']
|
token = app.config['MATRIX_PNUT_TOKEN']
|
||||||
prefix = "[" + get_displayname(event['user_id']) + "] (" + event['user_id'] + ")\n"
|
if "displayname" in matrix_profile:
|
||||||
|
prefix = "[" + matrix_profile['displayname'] + "] (" + event['user_id'] + ")\n"
|
||||||
|
else:
|
||||||
|
prefix = "(" + event['user_id'] + ")\n"
|
||||||
|
|
||||||
pnutpy.api.add_authorization_token(token)
|
pnutpy.api.add_authorization_token(token)
|
||||||
text = None
|
text = None
|
||||||
embed = None
|
embed = [{
|
||||||
|
'type': "io.pnut.core.crosspost",
|
||||||
|
'value': {
|
||||||
|
'canonical_url': "https://matrix.to/#/" + event['room_id'] + "/" + event['event_id'] + ":" + app.config['MATRIX_DOMAIN'],
|
||||||
|
'source': {
|
||||||
|
'name': "matrix",
|
||||||
|
'url': "https://matrix.org"
|
||||||
|
},
|
||||||
|
'user': cross_profile
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
|
||||||
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']
|
||||||
|
@ -160,7 +178,7 @@ def new_message(event, user):
|
||||||
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 = [raw_from_event(event)]
|
embed.append(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"
|
||||||
|
@ -295,13 +313,11 @@ def delete_message(event, user):
|
||||||
except pnutpy.errors.PnutPermissionDenied as e:
|
except pnutpy.errors.PnutPermissionDenied as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_displayname(userid):
|
def get_profile(userid):
|
||||||
url = app.config['MATRIX_HOST'] + "/_matrix/client/r0/profile/" + userid
|
url = app.config['MATRIX_HOST'] + "/_matrix/client/r0/profile/" + userid
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
data = json.loads(r.text)
|
return json.loads(r.text)
|
||||||
if 'displayname' in data:
|
|
||||||
return data["displayname"]
|
|
||||||
return userid
|
return userid
|
||||||
|
|
||||||
def get_channel_settings(channel_id):
|
def get_channel_settings(channel_id):
|
||||||
|
|
Loading…
Reference in a new issue