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