From 72277818f1608994c3cbe2c0407549843acfe362 Mon Sep 17 00:00:00 2001 From: William Kray Date: Thu, 15 Aug 2024 20:23:55 -0700 Subject: [PATCH] add roomid command and fix workflow file --- .github/workflows/build.yml | 2 +- README.md | 7 +++++++ community/bot.py | 21 +++++++++++++++++++++ maubot.yaml | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ee14efb..bb975d6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,4 +26,4 @@ jobs: with: files: | *.mbp - LICENSE + LICENSE* diff --git a/README.md b/README.md index 6e29c24..209a403 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,13 @@ will attempt to sanitize the room name and assign a room alias automatically. th power level (1000) and set an admin power level (100) to plugin administrators. this ensures that the bot is still able to manage room admins. the bot will also invite other users to these new rooms as configured. +## get room ID + +sometimes you need to know a rooms identifier, but if the room has an alias associated with it not all clients make it +easy (or possible) to find. this subcommand (`!community roomid`) can be used to return the room id that a room alias +points to. with no argument passed, it will return the current room's ID, or you can pass it an alias (e.g. `!community +roomid #whatisthisroom:myserver.tld`). + # installation install this like any other maubot plugin: zip the contents of this repo into a file and upload via the web interface, diff --git a/community/bot.py b/community/bot.py index 896710b..b96f366 100644 --- a/community/bot.py +++ b/community/bot.py @@ -488,6 +488,27 @@ class CommunityBot(Plugin): except Exception as e: await evt.respond(f"something went wrong: {e}") + @community.subcommand("roomid", help="return the matrix room ID of this, or a given, room") + @command.argument("room", required=False) + async def get_roomid(self, evt: MessageEvent, room: str) -> None: + room_id = None + if room: + if room.startswith('#'): + try: + thatroom_id = await self.client.resolve_room_alias(room) + room_id = thatroom_id["room_id"] + except: + evt.reply("i don't recognize that room, sorry") + return + else: + room_id = room + else: + room_id = evt.room_id + try: + await evt.reply(f"Room ID is: {room_id}") + except Exception as e: + await evt.respond(f"something went wrong: {e}") + @classmethod def get_db_upgrade_table(cls) -> None: diff --git a/maubot.yaml b/maubot.yaml index c54d19b..0ab8d10 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.1.0 id: org.jobmachine.communitybot -version: 0.1.0 +version: 0.1.1 license: MIT modules: - community