Add room unbridge command

This commit is contained in:
Tulir Asokan
2018-03-01 21:06:23 +02:00
parent 64b60559ee
commit 46cac040c7
6 changed files with 75 additions and 21 deletions
+8 -3
View File
@@ -484,19 +484,24 @@ class Portal:
return authenticated
@staticmethod
async def cleanup_room(intent, room_id, type="Portal"):
async def cleanup_room(intent, room_id, message="Portal deleted", puppets_only=False):
try:
members = await intent.get_room_members(room_id)
except MatrixRequestError:
members = []
for user in members:
if user != intent.mxid:
is_puppet = p.Puppet.get_id_from_mxid(user)
if user != intent.mxid and (not puppets_only or is_puppet):
try:
await intent.kick(room_id, user, f"{type} deleted.")
await intent.kick(room_id, user, message)
except (MatrixRequestError, IntentError):
pass
await intent.leave_room(room_id)
async def unbridge(self):
await self.cleanup_room(self.main_intent, self.mxid, "Room unbridged", puppets_only=True)
self.delete()
async def cleanup_and_delete(self):
await self.cleanup_room(self.main_intent, self.mxid)
self.delete()