diff --git a/appservice.py b/appservice.py index b442ba9..c944a9f 100644 --- a/appservice.py +++ b/appservice.py @@ -110,9 +110,7 @@ def on_receive_events(transaction): if event['state_key'] == app.config['MATRIX_AS_ID']: - if event['content']['membership'] == 'invite' - and 'is_direct' in event['content'] - and event['content']['is_direct'] == True: + if event['content']['membership'] == 'invite' and 'is_direct' in event['content'] and event['content']['is_direct'] == True: logging.info('>> GOT INVITE') txId += 1 @@ -126,7 +124,9 @@ def on_receive_events(transaction): db.session.add(addadminrm) db.session.commit() - elif event['membership'] == 'leave': + elif event['membership'] == 'leave': + adminrm = MatrixAdminRooms.query.filter_by(room_id=event['room_id']).first() + if adminrm: logging.info('>> GOT LEAVE') txId += 1 url = app.config['MATRIX_HOST'] @@ -135,7 +135,6 @@ def on_receive_events(transaction): r = requests.post(url, headers={"Content-Type": "application/json"}, data=json.dumps({})) if r.status_code == 200: - adminrm = MatrixAdminRooms.query.filter_by(room_id=event['room_id']).first() db.session.delete(adminrm) db.session.commit()