From ebc5b4abd6f8b19fc77c608429831167cc6317bf Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Mon, 24 Apr 2017 18:55:44 -0700 Subject: [PATCH] tweak the displayname for the guest user to pnut --- appservice.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/appservice.py b/appservice.py index e6a0a46..66d2e5f 100644 --- a/appservice.py +++ b/appservice.py @@ -32,14 +32,14 @@ def on_receive_events(transaction): text = event['content']['body'] else: 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': if user: token = user.pnut_token text = "* " + user.pnut_id + " " + event['content']['body'] else: token = app.config['MATRIX_PNUT_TOKEN'] - text = "* " + event["user_id"] + " " + event['content']['body'] + text = "* " + get_displayname(event["user_id"]) + " " + event['content']['body'] else: text = None @@ -137,3 +137,11 @@ def query_alias(alias): def not_found(error): 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 \ No newline at end of file