tweak the displayname for the guest user to pnut

This commit is contained in:
Morgan McMillian 2017-04-24 18:55:44 -07:00
parent 722224807a
commit ebc5b4abd6

View file

@ -32,14 +32,14 @@ def on_receive_events(transaction):
text = event['content']['body'] text = event['content']['body']
else: else:
token = app.config['MATRIX_PNUT_TOKEN'] token = app.config['MATRIX_PNUT_TOKEN']
text = "<" + event["user_id"] + "> " + event['content']['body'] text = "" + get_displayname(event["user_id"]) + " : " + event['content']['body']
elif event['content']['msgtype'] == 'm.emote': elif event['content']['msgtype'] == 'm.emote':
if user: if user:
token = user.pnut_token token = user.pnut_token
text = "* " + user.pnut_id + " " + event['content']['body'] text = "* " + user.pnut_id + " " + event['content']['body']
else: else:
token = app.config['MATRIX_PNUT_TOKEN'] token = app.config['MATRIX_PNUT_TOKEN']
text = "* " + event["user_id"] + " " + event['content']['body'] text = "* " + get_displayname(event["user_id"]) + " " + event['content']['body']
else: else:
text = None text = None
@ -137,3 +137,11 @@ def query_alias(alias):
def not_found(error): def not_found(error):
return jsonify({'errcode':'COM.MONKEYSTEW.PNUT_NOT_FOUND'}), 404 return jsonify({'errcode':'COM.MONKEYSTEW.PNUT_NOT_FOUND'}), 404
def get_displayname(userid):
url = "http://localhost:8008/_matrix/client/r0/profile/" + userid
r = requests.get(url)
if r.status_code == 200:
data = json.loads(r.text)
return data["displayname"]
else:
return userid