From f5933792ebe73ad77422644004d4f07c02d12241 Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Tue, 14 Jul 2020 17:44:36 +0100 Subject: [PATCH] Add ability to query a single homeserver. --- README.md | 1 + maubot.yaml | 2 +- shameotron.py | 34 +++++++++++++++++++--------------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 09cbcfc..e2aa393 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,4 @@ A simple [maubot](https://github.com/maubot/maubot) that displays everyone's hom ## Usage * `!shame` - Reply with a list of homeservers and their respective running versions. +* `!shame server.example.com` - Reply with the version for the homeserver provided, server.example.com. diff --git a/maubot.yaml b/maubot.yaml index 1d7b3d6..64d2986 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.1.0 id: sh.wallace.matrix.shameotron -version: 0.0.2 +version: 0.0.3 license: MIT modules: - shameotron diff --git a/shameotron.py b/shameotron.py index 51d5c2d..490c4a7 100644 --- a/shameotron.py +++ b/shameotron.py @@ -99,28 +99,32 @@ class ShameOTron(Plugin): @command.new('shame', help='Show versions of all homeservers in the room') - async def shame_handler(self, evt: MessageEvent) -> None: + @command.argument("candidate", pass_raw=True, required=False) + async def shame_handler(self, evt: MessageEvent, candidate: str = None) -> None: """ Class method to handle the `!shame` command """ event_id = await evt.reply('Loading member list...') - member_servers = await self._load_members(evt.room_id) + if candidate: + member_servers = [candidate] + else: + member_servers = await self._load_members(evt.room_id) - # Filter out the "dead servers" - dead_servers = self.config['dead_servers'] - if dead_servers: - # Return a unique list - member_servers = sorted( - list( - set(member_servers.keys() - set(dead_servers)) + # Filter out the "dead servers" + dead_servers = self.config['dead_servers'] + if dead_servers: + # Return a unique list + member_servers = sorted( + list( + set(member_servers.keys() - set(dead_servers)) + ) ) - ) - await self._edit( - evt.room_id, - event_id, - 'Member list loaded, fetching versions... please wait...' - ) + await self._edit( + evt.room_id, + event_id, + 'Member list loaded, fetching versions... please wait...' + ) versions = [] for host in member_servers: