Implement Ctrl-C handling and fix a large number of small bugs

This commit is contained in:
2019-09-28 19:46:10 +01:00
parent 006f8db6f6
commit 15ca45e5df
12 changed files with 88 additions and 61 deletions

View File

@@ -14,11 +14,11 @@ class AutoCommand:
if not spl[2].isdigit():
failure("Must be integer, not %s" % spl[2])
return
id, alias = main.network[spl[1]].add_relay(int(spl[2]))
relayNum = int(spl[2])
id, alias = main.network[spl[1]].add_relay(relayNum)
success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[1], alias))
main.saveConf("network")
rtrn = provision.provisionRelay(int(spl[2]), spl[1])
rtrn = provision.provisionRelay(relayNum, spl[1])
success("Started provisioning network %s on relay %s for alias %s" % (spl[1], spl[2], rtrn))
return

View File

@@ -10,19 +10,23 @@ class DelCommand:
if not spl[1] in main.network.keys():
failure("No such network: %s" % spl[1])
return
if not spl[2].isdigit():
failure("Must be integer, not %s" % spl[2])
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]].delete_relay(int(spl[2]))
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]+spl[2] 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]]
name = spl[1]+spl[2]
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 removed bot: %s" % spl[1])
main.saveConf("network")
return

View File

@@ -11,25 +11,31 @@ class DisableCommand:
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():
if not spl[2].isdigit():
failure("Must be integer, not %s" % spl[2])
return
relayNum = int(spl[2])
name = spl[1]+spl[2]
if not spl[1] in main.IRCPool.keys():
info("Note - instance not running, proceeding anyway")
if not relayNum 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])]
main.network[spl[1]].relays[relayNum]["enabled"] = False
user = main.network[spl[1]].aliases[relayNum]["nick"]
network = spl[1]
relay = main.network[spl[1]].relays[int(spl[2])]
relay = main.network[spl[1]].relays[relayNum]
commands = {"status": ["Disconnect"]}
deliverRelayCommands(relay, commands, user=user+"/"+network)
deliverRelayCommands(relayNum, 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 name in main.ReactorPool.keys():
if name in main.FactoryPool.keys():
main.FactoryPool[name].stopTrying()
main.ReactorPool[name].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]]
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:

View File

@@ -17,7 +17,7 @@ class StatsCommand:
numChannels += len(main.IRCPool[i].channels)
numWhoEntries += userinfo.getNumTotalWhoEntries()
stats.append("Registered servers:")
stats.append(" Total: %s" % len(main.network.keys()))
stats.append(" Unique: %s" % len(main.network.keys()))
stats.append("Online servers:")
stats.append(" Total: %s" % len(main.IRCPool.keys()))
stats.append(" Unique: %s" % len(main.liveNets()))

View File

@@ -11,18 +11,21 @@ class SwhoCommand:
failure("Network does not exist: %s" % spl[1])
return
for i in main.IRCPool.keys():
if spl[1] in i:
if spl[1] == main.IRCPool[i].net:
for x in main.IRCPool[i].channels:
main.IRCPool[i].who(x)
success("Sent WHO to all channels on all networks on %s" % spl[1])
success("Sent WHO to all channels on all networks for %s" % spl[1])
return
elif length == 3:
if not spl[1] in main.network.keys():
failure("Network does not exist: %s" % spl[1])
return
matches = []
# This loop gets all networks where the core network matches spl[1]
# where there is also a currently joined channel matching spl[2]
for i in main.IRCPool.keys():
if spl[1] in i:
if spl[1] == main.IRCPool[i].net:
for x in main.IRCPool[i].channels:
if x == spl[2]:
main.IRCPool[i].who(x)