add error condition when matrix bot isn't permitted to write

This commit is contained in:
Morgan McMillian 2017-05-25 06:59:55 -07:00
parent 43973232ab
commit 0ee1ca2e9b

View file

@ -97,6 +97,17 @@ def on_receive_events(transaction):
el = MatrixMsgEvents(event['event_id'], event['room_id'], msgid, puser, chan_id) el = MatrixMsgEvents(event['event_id'], event['room_id'], msgid, puser, chan_id)
db.session.add(el) db.session.add(el)
db.session.commit() 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': elif event['type'] == 'm.room.redaction':
r_event = MatrixMsgEvents.query.filter_by(event_id=event['redacts'],room_id=event['room_id']).first() r_event = MatrixMsgEvents.query.filter_by(event_id=event['redacts'],room_id=event['room_id']).first()