add rooms mcommand

This commit is contained in:
Nexus 2024-09-14 14:46:18 +01:00
parent 4764d8cd2a
commit 7a49169428

View file

@ -220,3 +220,22 @@ class EvalModule(niobot.Module):
await ctx.respond(f"Result of runas: `{result!r}`") await ctx.respond(f"Result of runas: `{result!r}`")
except Exception as e: except Exception as e:
await ctx.respond(f"Error in runas process: `{e!r}`") await ctx.respond(f"Error in runas process: `{e!r}`")
@niobot.command()
@niobot.is_owner()
async def rooms(self, ctx: niobot.Context, operation: str, room: str = None):
"""room management"""
match operation.casefold():
case "join":
result = await self.bot.join(room)
return await ctx.respond(repr(result))
case "leave":
if room.startswith("#"):
resolved = await self.bot.room_resolve_alias(room)
if not isinstance(resolved, niobot.RoomResolveAliasResponse):
return await ctx.respond("Failed to resolve room ID for: %r", room)
room = resolved.room_id
response = await self.bot.room_leave(room)
return await ctx.respond(repr(response))
case _:
return await ctx.respond("Unknown operation.")