monolith/commands/disable.py

40 lines
1.7 KiB
Python
Raw Normal View History

import main
from core.bot import deliverRelayCommands
class DisableCommand:
def __init__(self, *args):
self.disable(*args)
def disable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 3:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
if not int(spl[2]) in main.network[spl[1]].relays.keys():
failure("No such relay: %s in network %s" % (spl[2], spl[1]))
return
main.network[spl[1]].relays[int(spl[2])]["enabled"] = False
user = main.network[spl[1]].aliases[int(spl[2])]
network = spl[1]
relay = main.network[spl[1]].relays[int(spl[2])]
commands = {"status": ["Disconnect"]}
deliverRelayCommands(relay, commands, user=user+"/"+network)
main.saveConf("network")
if spl[1]+spl[2] in main.ReactorPool.keys():
if spl[1]+spl[2] in main.FactoryPool.keys():
main.FactoryPool[spl[1]+spl[2]].stopTrying()
main.ReactorPool[spl[1]+spl[2]].disconnect()
if spl[1] in main.IRCPool.keys():
del main.IRCPool[spl[1]+spl[2]]
del main.ReactorPool[spl[1]+spl[2]]
del main.FactoryPool[spl[1]+spl[2]]
success("Successfully disabled bot %s on network %s" % (spl[2], spl[1]))
return
else:
incUsage("disable")
return
else:
incUsage(None)