diff --git a/appservice.py b/appservice.py index 7c4219c..93c8431 100644 --- a/appservice.py +++ b/appservice.py @@ -71,12 +71,6 @@ def on_receive_events(transaction): else: text = None - # chan = MatrixRoom.query.filter_by(room_id=event['room_id']).first() - # if chan: - # chan_id = chan.pnut_chan - # else: - # return jsonify({}) - if user == None and not chan.pnut_write: txId += 1 url = app.config['MATRIX_HOST'] @@ -112,6 +106,25 @@ def on_receive_events(transaction): r = Pnut(token).delete_channel_post(r_event.pnut_chan, r_event.pnut_msgid) + elif event['type'] == 'm.room.member': + + if event['content']['membership'] == 'invite' and event['content']['is_direct'] == True: + logging.info('>> GOT INVITE') + txId += 1 + url = app.config['MATRIX_HOST'] + url += '/_matrix/client/r0/join/' + event['room_id'] + url += "?access_token=" + app.config['MATRIX_AS_TOKEN'] + r = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps({})) + + elif event['membership'] == 'leave': + logging.info('>> GOT LEAVE') + txId += 1 + url = app.config['MATRIX_HOST'] + url += '/_matrix/client/r0/rooms/' + event['room_id'] + "/leave" + url += "?access_token=" + app.config['MATRIX_AS_TOKEN'] + r = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps({})) + + return jsonify({}) @app.route("/rooms/")