Skip to content

Commit aed77bc

Browse files
committed
matrix: Added a command to set the current admin room to work also as control room
1 parent 9d35e5a commit aed77bc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Diff for: teslabot/matrix.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .state import State, StateElement
1616
from . import log
1717
from .env import Env
18+
from . import commands, parser
1819

1920
logger = log.getLogger(__name__)
2021

@@ -81,6 +82,17 @@ def __init__(self, env: Env) -> None:
8182
admin_room_id = None
8283
self._admin_room_id = admin_room_id
8384

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+
8496
async def setup(self) -> None:
8597
mx_config = self._config["matrix"] if self._config.has_section("matrix") else None
8698
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:
137149
self._admin_room_id = room.room_id
138150
await self._state.save()
139151
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.")
141153
elif self._room_id is None:
142154
logger.debug(f"invite callback to {room} event {event}: joining to control room")
143155
await self._client.join(room.room_id)
144156
self._room_id = room.room_id
145157
await self._state.save()
146158
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.")
148160
else:
149161
logger.debug(f"invite callback to {room} event {event}: not joining, we are already in {self._room_id}")
150162

0 commit comments

Comments
 (0)