diff --git a/appservice.py b/appservice.py index 6ed189a..fb90285 100644 --- a/appservice.py +++ b/appservice.py @@ -409,22 +409,23 @@ def cmd_admin_unlink(id): else: room = Rooms.query.filter(Rooms.pnut_chan == id).one_or_none() - if room.portal: - alias = "#" + app.config['MATRIX_PNUT_PREFIX'] - alias += str(room.pnut_chan) + ":" - alias += app.config['MATRIX_DOMAIN'] - matrix_api.remove_room_alias(alias) + if hasattr(room, 'portal'): + if room.portal: + alias = "#" + app.config['MATRIX_PNUT_PREFIX'] + alias += str(room.pnut_chan) + ":" + alias += app.config['MATRIX_DOMAIN'] + matrix_api.remove_room_alias(alias) - # Kicking users needs at least moderator privs - members = matrix_api.get_room_members(room.room_id) - reason = "Portal room has been unlinked by administrator" - for m in members['chunk']: - if m['membership'] == 'join' and m['sender'] != app.config['MATRIX_AS_ID']: - if room.portal: - matrix_api.kick_user(room.room_id, m['sender'], reason=reason) - else: - if m['sender'].startswith("@" + app.config['MATRIX_PNUT_PREFIX']): + # Kicking users needs at least moderator privs + members = matrix_api.get_room_members(room.room_id) + reason = "Portal room has been unlinked by administrator" + for m in members['chunk']: + if m['content']['membership'] == 'join' and m['sender'] != app.config['MATRIX_AS_ID']: + if room.portal: matrix_api.kick_user(room.room_id, m['sender'], reason=reason) + else: + if m['sender'].startswith("@" + app.config['MATRIX_PNUT_PREFIX']): + matrix_api.kick_user(room.room_id, m['sender'], reason=reason) try: channel, meta = pnutpy.api.unsubscribe_channel(room.pnut_chan)