2023-04-19 06:11:28 +00:00
|
|
|
from nio.events.room_events import RoomMessageText
|
2023-04-25 11:25:53 +00:00
|
|
|
from nio import RoomCreateError, RoomInviteError
|
2023-04-19 06:11:28 +00:00
|
|
|
from nio.rooms import MatrixRoom
|
|
|
|
|
2023-04-23 13:26:46 +00:00
|
|
|
|
2023-04-25 11:25:53 +00:00
|
|
|
async def command_newroom(room: MatrixRoom, event: RoomMessageText, bot):
|
2023-04-23 13:26:46 +00:00
|
|
|
room_name = " ".join(event.body.split()[
|
|
|
|
2:]) or context["default_room_name"]
|
2023-04-19 06:11:28 +00:00
|
|
|
|
2023-04-25 11:25:53 +00:00
|
|
|
bot.logger.log("Creating new room...")
|
|
|
|
new_room = await bot.matrix_client.room_create(name=room_name)
|
|
|
|
|
|
|
|
if isinstance(new_room, RoomCreateError):
|
|
|
|
bot.logger.log(f"Failed to create room: {new_room.message}")
|
|
|
|
await bot.send_message(room, f"Sorry, I was unable to create a new room. Please try again later, or create a room manually.", True)
|
|
|
|
return
|
|
|
|
|
|
|
|
bot.logger.log(f"Inviting {event.sender} to new room...")
|
|
|
|
invite = await bot.matrix_client.room_invite(new_room.room_id, event.sender)
|
|
|
|
|
|
|
|
if isinstance(invite, RoomInviteError):
|
|
|
|
bot.logger.log(f"Failed to invite user: {invite.message}")
|
|
|
|
await bot.send_message(room, f"Sorry, I was unable to invite you to the new room. Please try again later, or create a room manually.", True)
|
|
|
|
return
|
2023-04-19 06:11:28 +00:00
|
|
|
|
2023-04-28 10:01:27 +00:00
|
|
|
await bot.matrix_client.room_put_state(
|
2023-04-19 06:11:28 +00:00
|
|
|
new_room.room_id, "m.room.power_levels", {"users": {event.sender: 100}})
|
|
|
|
|
2023-04-25 11:25:53 +00:00
|
|
|
await bot.matrix_client.joined_rooms()
|
|
|
|
await bot.send_message(room, f"Alright, I've created a new room called '{room_name}' and invited you to it. You can find it at {new_room.room_id}", True)
|
2023-05-01 16:47:01 +00:00
|
|
|
await bot.send_message(new_room, f"Welcome to the new room! What can I do for you?")
|