monolith/legacy/commands/disable.py

49 lines
2.0 KiB
Python
Raw Permalink Normal View History

import main
2022-07-21 12:40:05 +00:00
from utils.deliver_relay_commands import deliverRelayCommands
2022-07-21 12:39:41 +00:00
class DisableCommand:
def __init__(self, *args):
self.disable(*args)
2022-09-05 06:20:30 +00:00
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 spl[2].isdigit():
failure("Must be a number, not %s" % spl[2])
return
relayNum = int(spl[2])
2022-07-21 12:39:41 +00:00
name = spl[1] + spl[2]
if not spl[1] in main.IRCPool.keys():
info("Note - instance not running, proceeding anyway")
2022-07-21 12:40:05 +00:00
if relayNum not 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[relayNum]["enabled"] = False
user = main.alias[relayNum]["nick"]
network = spl[1]
2022-07-21 12:40:05 +00:00
# relay = main.network[spl[1]].relays[relayNum]
commands = {"status": ["Disconnect"]}
2022-07-21 12:39:41 +00:00
deliverRelayCommands(relayNum, commands, user=user + "/" + network)
main.saveConf("network")
if name in main.ReactorPool.keys():
if name in main.FactoryPool.keys():
main.FactoryPool[name].stopTrying()
main.ReactorPool[name].disconnect()
if name in main.IRCPool.keys():
del main.IRCPool[name]
del main.ReactorPool[name]
del main.FactoryPool[name]
success("Successfully disabled bot %s on network %s" % (spl[2], spl[1]))
return
else:
incUsage("disable")
return
else:
incUsage(None)