From 0ee1ca2e9bb8965dbe56559c2ffb4a25f1a9f3da Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Thu, 25 May 2017 06:59:55 -0700 Subject: [PATCH] add error condition when matrix bot isn't permitted to write --- appservice.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/appservice.py b/appservice.py index feaa0eb..3f3f352 100644 --- a/appservice.py +++ b/appservice.py @@ -97,6 +97,17 @@ def on_receive_events(transaction): el = MatrixMsgEvents(event['event_id'], event['room_id'], msgid, puser, chan_id) db.session.add(el) db.session.commit() + elif r.status_code == 401: + txId += 1 + err_notice = event["user_id"] + ": The pnut.io channel this room is connected with is restricted to valid " + err_notice += "pnut.io users only. Direct chat this bot to associate your account." + body = {'msgtype': 'm.notice', 'body': err_notice} + url = app.config['MATRIX_HOST'] + url += '/_matrix/client/r0/rooms/{0}/send/m.room.message/{1}'.format(event['room_id'], str(txId)) + url += "?access_token=" + app.config['MATRIX_AS_TOKEN'] + requests.put(url, headers={"Content-Type": "application/json"}, data=json.dumps(body)) + else: + logging.debug(r.text) elif event['type'] == 'm.room.redaction': r_event = MatrixMsgEvents.query.filter_by(event_id=event['redacts'],room_id=event['room_id']).first()