From 1daa4217ec4b1293273042a7f63ef870360c3c4d Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 21 May 2019 10:16:20 +0100 Subject: [PATCH] Add !addserver command --- modules/admin.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/modules/admin.py b/modules/admin.py index 8d72a12b..22c03314 100644 --- a/modules/admin.py +++ b/modules/admin.py @@ -100,3 +100,34 @@ class Module(ModuleManager.BaseModule): server.disconnect() self.bot.disconnect(server) return shutdown + + @utils.hook("received.command.addserver", min_args=3) + def add_server(self, event): + """ + :help: Add a new server + :usage: :[+] ![@] + :permission: addserver + """ + alias = event["args_split"][0] + hostname, sep, port = event["args_split"][1].partition(":") + tls = port.startswith("+") + + if not hostname or not port or not port.isdigit(): + raise utils.EventError("Please provide :[+]") + port = int(port) + + hostmask = utils.irc.seperate_hostmask(event["args_split"][2]) + nickname = hostmask.nickname + username = hostmask.usernaame or nickname + realname = nickname + bindhost = hostmask.hostname or None + + try: + server_id = self.bot.database.servers.add(alias, hostname, port, "", + tls, bindhost, nickname, username, realname) + except Exception as e: + event["stderr"].write("Failed to add server") + self.log.error("failed to add server \"%s\"", [alias], + exc_info=True) + return + event["stdout"].write("Added server '%s'" % alias)