Add !disconnect to admin.py

This commit is contained in:
jesopo 2018-11-20 14:27:24 +00:00
parent 80dd3bb5e1
commit 45c7ce6da5

View file

@ -50,6 +50,7 @@ class Module(ModuleManager.BaseModule):
"""
:help: Connect to a network
:usage: <server id>
:permission: connect
"""
id = event["args_split"][0]
if not id.isdigit():
@ -66,3 +67,23 @@ class Module(ModuleManager.BaseModule):
server = self.bot.add_server(id)
event["stdout"].write("Connecting to %s" % str(server))
@utils.hook("received.command.disconnect")
def disconnect(self, event):
"""
:help: Disconnect from a server
:usage: [server id]
:permission: disconnect
"""
id = event["server"].id
if event["args"]:
id = event["args_split"][0]
if not id.isdigit():
raise utils.EventError("Please provide a numeric server ID")
id = int(id)
if not self.bot.database.servers.get(id):
raise utils.EventError("Unknown server ID")
server = self.bot.get_server(id)
server.disconnect()
self.bot.disconnect(server)