|
15 | 15 | from .state import State, StateElement
|
16 | 16 | from . import log
|
17 | 17 | from .env import Env
|
| 18 | +from . import commands, parser |
18 | 19 |
|
19 | 20 | logger = log.getLogger(__name__)
|
20 | 21 |
|
@@ -81,6 +82,17 @@ def __init__(self, env: Env) -> None:
|
81 | 82 | admin_room_id = None
|
82 | 83 | self._admin_room_id = admin_room_id
|
83 | 84 |
|
| 85 | + self.local_commands.register(commands.Function("sameroom", "Assign control room to be the same as admin room", |
| 86 | + parser.Empty(), self._command_sameroom)) |
| 87 | + |
| 88 | + async def _command_sameroom(self, context: CommandContext, args: Tuple[()]) -> None: |
| 89 | + if context.admin_room: |
| 90 | + await self.send_message(context.to_message_context(), f"Setting room_id = self._admin_room_id (was {self._room_id})") |
| 91 | + self._room_id = self._admin_room_id |
| 92 | + await self._state.save() |
| 93 | + else: |
| 94 | + await self.send_message(context.to_message_context(), "This request must be sent to the admin room.") |
| 95 | + |
84 | 96 | async def setup(self) -> None:
|
85 | 97 | mx_config = self._config["matrix"] if self._config.has_section("matrix") else None
|
86 | 98 | mx_state = self._state.state["matrix"] if "matrix" in self._state.state else None
|
@@ -137,14 +149,14 @@ async def _invite_callback(self, room: MatrixRoom, event: Event) -> None:
|
137 | 149 | self._admin_room_id = room.room_id
|
138 | 150 | await self._state.save()
|
139 | 151 | logger.info(f"Room {room.name} is encrypted: {room.encrypted}")
|
140 |
| - await self.send_message(control.MessageContext(admin_room=True), "This is the admin room.") |
| 152 | + await self.send_message(control.MessageContext(admin_room=True), "This is the admin room. Invite to another room or use !sameroom to set this to be the control room as well.") |
141 | 153 | elif self._room_id is None:
|
142 | 154 | logger.debug(f"invite callback to {room} event {event}: joining to control room")
|
143 | 155 | await self._client.join(room.room_id)
|
144 | 156 | self._room_id = room.room_id
|
145 | 157 | await self._state.save()
|
146 | 158 | logger.info(f"Room {room.name} is encrypted: {room.encrypted}")
|
147 |
| - await self.send_message(control.MessageContext(admin_room=True), "This is the control room.") |
| 159 | + await self.send_message(control.MessageContext(admin_room=False), "This is the control room.") |
148 | 160 | else:
|
149 | 161 | logger.debug(f"invite callback to {room} event {event}: not joining, we are already in {self._room_id}")
|
150 | 162 |
|
|
0 commit comments