diff --git a/src/matrix_applicationbot/classes/bot.py b/src/matrix_applicationbot/classes/bot.py index af40fc2..669ae8c 100644 --- a/src/matrix_applicationbot/classes/bot.py +++ b/src/matrix_applicationbot/classes/bot.py @@ -198,18 +198,22 @@ class ApplicationBot: elif command == "!applicationbot list": return await self.list_tickets(room) elif command.startswith("!applicationbot monitor"): - return await self.add_monitored_room(command.split()[2]) + room_id = self.resolve_room_id(command.split()[2]) + return await self.add_monitored_room(room_id) elif command.startswith("!applicationbot unmonitor"): - return await self.remove_monitored_room(command.split()[2]) + room_id = self.resolve_room_id(command.split()[2]) + return await self.remove_monitored_room(room_id) elif command.startswith("!applicationbot monitored"): return await self.list_monitored_rooms(room) elif command.startswith("!applicationbot protect "): try: - return await self.add_protected_room(command.split()[2]) + room_id = await self.resolve_room_id(command.split()[2]) + return await self.add_protected_room(room_id) except IndexError: logging.error(f"No room ID specified for protect command: {command}") elif command.startswith("!applicationbot unprotect"): - return await self.remove_protected_room(command.split()[2]) + room_id = self.resolve_room_id(command.split()[2]) + return await self.remove_protected_room(room_id) elif command.startswith("!applicationbot protected"): return await self.list_protected_rooms(room) @@ -744,3 +748,21 @@ class ApplicationBot: "body": help_message, }, ) + + async def resolve_alias(self, alias): + response = await self.client.room_resolve_alias(alias) + if response: + return response.room_id + return None + + async def resolve_room_id(self, room_id): + if "/" in room_id: + room_id = room_id.split("/")[-1] + + if room_id.startswith("#"): + return await self.resolve_alias(room_id) + + if not room_id.startswith("!"): + return None + + return room_id \ No newline at end of file