From 890c893ddf723cc0f68558b65daa43c230e863d3 Mon Sep 17 00:00:00 2001 From: jesopo Date: Fri, 28 Jun 2019 18:36:43 +0100 Subject: [PATCH] Add ircv3.py - for IRCv3-related stats --- modules/ircv3.py | 31 +++++++++++++++++++++++++++++++ modules/stats.py | 8 -------- 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 modules/ircv3.py diff --git a/modules/ircv3.py b/modules/ircv3.py new file mode 100644 index 00000000..8b3c388f --- /dev/null +++ b/modules/ircv3.py @@ -0,0 +1,31 @@ +from src import ModuleManager, utils + +class Module(ModuleManager.BaseModule): + _name = "IRCv3" + + @utils.hook("received.command.specsup", min_args=1) + @utils.kwarg("help", "List servers supporting a given IRCv3 capability") + @utils.kwarg("usage", "") + def specsup(self, event): + spec = event["args_split"][0].lower() + supporting_servers = [] + + for server in self.bot.servers.values(): + if not server.connection_params.hostname == "localhost": + if spec in server.server_capabilities: + port = str(server.connection_params.port) + if server.connection_params.tls: + port = "+%s" % port + supporting_servers.append("%s:%s" % ( + server.connection_params.hostname, port)) + if supporting_servers: + event["stdout"].write("%s: %s" % (spec, + ", ".join(supporting_servers))) + else: + event["stderr"].write("No supporting servers found for %s" % spec) + + @utils.hook("received.command.caps") + @utils.kwarg("help", "List negotiated IRCv3 capabilities") + def capabilities(self, event): + event["stdout"].write("IRCv3 capabilities: %s" % + ", ".join(event["server"].agreed_capabilities)) diff --git a/modules/stats.py b/modules/stats.py index 4481a724..7828e0cc 100644 --- a/modules/stats.py +++ b/modules/stats.py @@ -123,11 +123,3 @@ class Module(ModuleManager.BaseModule): @utils.hook("api.get.modules") def modules_api(self, event): return list(self.bot.modules.modules.keys()) - - @utils.hook("received.command.caps") - def capabilities(self, event): - """ - :help: List negotiated IRCv3 capabilities - """ - event["stdout"].write("IRCv3 capabilities: %s" % - ", ".join(event["server"].agreed_capabilities))