Rework data structures, storing all front-end network data in Network objects
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
import main
|
||||
from yaml import dump
|
||||
import modules.alias as alias
|
||||
|
||||
class AliasCommand:
|
||||
def __init__(self, *args):
|
||||
self.alias(*args)
|
||||
|
||||
def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 8:
|
||||
if spl[1] == "add":
|
||||
if spl[2] in main.alias.keys():
|
||||
failure("Alias already exists: %s" % spl[2])
|
||||
return
|
||||
else:
|
||||
main.alias[spl[2]] = {"nick": spl[3],
|
||||
"altnick": spl[4],
|
||||
"ident": spl[5],
|
||||
"realname": spl[6],
|
||||
"password": spl[7]}
|
||||
success("Successfully created alias: %s" % spl[2])
|
||||
main.saveConf("alias")
|
||||
return
|
||||
else:
|
||||
incUsage("alias")
|
||||
return
|
||||
|
||||
elif length == 3:
|
||||
if spl[1] == "del":
|
||||
if spl[2] in main.alias.keys():
|
||||
del main.alias[spl[2]]
|
||||
success("Successfully removed alias: %s" % spl[2])
|
||||
main.saveConf("alias")
|
||||
return
|
||||
else:
|
||||
failure("No such alias: %s" % spl[2])
|
||||
return
|
||||
elif spl[1] == "add" and spl[2] == "auto":
|
||||
newalias = alias.generate_alias()
|
||||
while newalias["nick"] in main.alias.keys():
|
||||
newalias = alias.generate_alias()
|
||||
main.alias[newalias["nick"]] = newalias
|
||||
success("Successfully created alias: %s" % newalias["nick"])
|
||||
main.saveConf("alias")
|
||||
return
|
||||
else:
|
||||
incUsage("alias")
|
||||
return
|
||||
elif length == 2:
|
||||
if spl[1] == "list":
|
||||
info(dump(main.alias))
|
||||
return
|
||||
else:
|
||||
incUsage("alias")
|
||||
return
|
||||
else:
|
||||
incUsage("alias")
|
||||
return
|
||||
else:
|
||||
incUsage(None)
|
||||
@@ -8,14 +8,16 @@ class CmdCommand:
|
||||
def cmd(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length > 4:
|
||||
if not spl[1] in main.relay.keys():
|
||||
failure("No such relay: %s" % spl[1])
|
||||
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 on network: %s" % (spl[2], spl[1]))
|
||||
return
|
||||
|
||||
commands = {spl[3]: [" ".join(spl[4:])]}
|
||||
print(" ".join(spl[4:]))
|
||||
success("Sending commands to relay %s as user %s" % (spl[1], spl[2]))
|
||||
deliverRelayCommands(spl[1], commands, user=spl[2])
|
||||
commands = {spl[4]: [" ".join(spl[5:])]}
|
||||
success("Sending commands to relay %s as user %s" % (spl[2], spl[3]))
|
||||
deliverRelayCommands(main.network[spl[1]].relays[spl[2]], commands, user=spl[3]+"/"+spl[1])
|
||||
return
|
||||
else:
|
||||
incUsage("cmd")
|
||||
|
||||
@@ -6,21 +6,25 @@ class DelCommand:
|
||||
|
||||
def delete(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 2:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
if length == 3:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("No such network: %s" % spl[1])
|
||||
return
|
||||
del main.pool[spl[1]]
|
||||
if spl[1] in main.ReactorPool.keys():
|
||||
if spl[1] in main.FactoryPool.keys():
|
||||
main.FactoryPool[spl[1]].stopTrying()
|
||||
main.ReactorPool[spl[1]].disconnect()
|
||||
if spl[1] in main.IRCPool.keys():
|
||||
del main.IRCPool[spl[1]]
|
||||
del main.ReactorPool[spl[1]]
|
||||
del main.FactoryPool[spl[1]]
|
||||
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]]
|
||||
success("Successfully removed bot: %s" % spl[1])
|
||||
main.saveConf("pool")
|
||||
main.saveConf("network")
|
||||
return
|
||||
else:
|
||||
incUsage("del")
|
||||
|
||||
@@ -7,26 +7,30 @@ class DisableCommand:
|
||||
|
||||
def disable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 2:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
if length == 3:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("No such network: %s" % spl[1])
|
||||
return
|
||||
main.pool[spl[1]]["enabled"] = False
|
||||
user = main.pool[spl[1]]["alias"]
|
||||
network = main.pool[spl[1]]["network"]
|
||||
relay = main.pool[spl[1]]["relay"]
|
||||
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("pool")
|
||||
if spl[1] in main.ReactorPool.keys():
|
||||
if spl[1] in main.FactoryPool.keys():
|
||||
main.FactoryPool[spl[1]].stopTrying()
|
||||
main.ReactorPool[spl[1]].disconnect()
|
||||
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]]
|
||||
del main.ReactorPool[spl[1]]
|
||||
del main.FactoryPool[spl[1]]
|
||||
success("Successfully disabled bot %s" % spl[1])
|
||||
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")
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import main
|
||||
from core.helper import startBot
|
||||
from core.bot import deliverRelayCommands
|
||||
|
||||
class EnableCommand:
|
||||
@@ -8,22 +7,26 @@ class EnableCommand:
|
||||
|
||||
def enable(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 2:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
if length == 3:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("No such network: %s" % spl[1])
|
||||
return
|
||||
main.pool[spl[1]]["enabled"] = True
|
||||
user = main.pool[spl[1]]["alias"]
|
||||
network = main.pool[spl[1]]["network"]
|
||||
relay = main.pool[spl[1]]["relay"]
|
||||
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"] = True
|
||||
user = main.network[spl[1]].aliases[int(spl[2])]
|
||||
network = spl[1]
|
||||
relay = main.network[spl[1]].relays[int(spl[2])]
|
||||
commands = {"status": ["Connect"]}
|
||||
deliverRelayCommands(relay, commands, user=user+"/"+network)
|
||||
main.saveConf("pool")
|
||||
if not spl[1] in main.IRCPool.keys():
|
||||
startBot(spl[1])
|
||||
main.saveConf("network")
|
||||
if not spl[1]+spl[2] in main.IRCPool.keys():
|
||||
main.network[spl[1]].start_bot(int(spl[2]))
|
||||
else:
|
||||
pass
|
||||
success("Successfully enabled bot %s" % spl[1])
|
||||
success("Successfully enabled bot %s on network %s" % (spl[2], spl[1]))
|
||||
return
|
||||
else:
|
||||
incUsage("enable")
|
||||
|
||||
@@ -6,25 +6,31 @@ class JoinCommand:
|
||||
|
||||
def join(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 3:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
if length == 4:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("Network does not exist: %s" % spl[1])
|
||||
return
|
||||
if not spl[1] in main.IRCPool.keys():
|
||||
if not int(spl[2]) in main.network[spl[1]].relays.keys():
|
||||
failure("Relay % does not exist on network %", (spl[2], spl[1]))
|
||||
return
|
||||
if not spl[1]+spl[2] in main.IRCPool.keys():
|
||||
failure("Name has no instance: %s" % spl[1])
|
||||
return
|
||||
main.IRCPool[spl[1]].join(spl[2])
|
||||
success("Joined %s" % spl[2])
|
||||
main.IRCPool[spl[1]+spl[2]].join(spl[3])
|
||||
success("Joined %s" % spl[3])
|
||||
return
|
||||
elif length == 4:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
elif length == 5:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("Network does not exist: %s" % spl[1])
|
||||
return
|
||||
if not spl[1] in main.IRCPool.keys():
|
||||
if not int(spl[2]) in main.network[spl[1]].relays.keys():
|
||||
failure("Relay % does not exist on network %", (spl[2], spl[1]))
|
||||
return
|
||||
if not spl[1]+spl[2] in main.IRCPool.keys():
|
||||
failure("Name has no instance: %s" % spl[1])
|
||||
return
|
||||
main.IRCPool[spl[1]].join(spl[2], spl[3])
|
||||
success("Joined %s with key %s" % (spl[2], spl[3]))
|
||||
main.IRCPool[spl[1]+spl[2]].join(spl[3], spl[4])
|
||||
success("Joined %s with key %s" % (spl[3], spl[4]))
|
||||
return
|
||||
else:
|
||||
incUsage("join")
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import main
|
||||
from yaml import dump
|
||||
|
||||
class ListCommand:
|
||||
def __init__(self, *args):
|
||||
self.list(*args)
|
||||
|
||||
def list(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
info(dump(main.pool))
|
||||
return
|
||||
else:
|
||||
incUsage(None)
|
||||
@@ -2,49 +2,42 @@ import main
|
||||
from yaml import dump
|
||||
|
||||
class ModCommand:
|
||||
# This could be greatly improved, but not really important right now
|
||||
def __init__(self, *args):
|
||||
self.mod(*args)
|
||||
|
||||
def mod(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 2:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
return
|
||||
info(dump({spl[1]: main.pool[spl[1]]}))
|
||||
return
|
||||
|
||||
elif length == 3:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
return
|
||||
if not spl[2] in main.pool[spl[1]].keys():
|
||||
failure("No such key: %s" % spl[2])
|
||||
return
|
||||
info("%s: %s" % (spl[2], main.pool[spl[1]][spl[2]]))
|
||||
return
|
||||
|
||||
elif length == 4:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
return
|
||||
if not spl[2] in main.pool[spl[1]].keys():
|
||||
failure("No such key: %s" % spl[2])
|
||||
if length == 4:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("Network does not exist: %s" % spl[1])
|
||||
return
|
||||
|
||||
if spl[3] == main.pool[spl[1]][spl[2]]:
|
||||
failure("Value already exists: %s" % spl[3])
|
||||
try:
|
||||
setattr(main.network[spl[1]], spl[2], spl[3])
|
||||
except e:
|
||||
failure("Something went wrong.")
|
||||
return
|
||||
|
||||
if spl[2] == "enabled":
|
||||
failure("Use the enable and disable commands to manage this")
|
||||
return
|
||||
|
||||
main.pool[spl[1]][spl[2]] = spl[3]
|
||||
main.saveConf("pool")
|
||||
main.saveConf("network")
|
||||
success("Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1]))
|
||||
return
|
||||
|
||||
elif length == 6:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("Network does not exist: %s" % spl[1])
|
||||
return
|
||||
if not int(spl[3]) in main.network[spl[1]].relays.keys():
|
||||
failure("Relay/alias does not exist: %s" % spl[3])
|
||||
return
|
||||
|
||||
try:
|
||||
x = getattr(main.network[spl[1]], spl[2])
|
||||
x[spl[3]] = spl[4]
|
||||
except e:
|
||||
failure("Something went wrong.")
|
||||
return
|
||||
|
||||
else:
|
||||
incUsage("mod")
|
||||
return
|
||||
|
||||
@@ -6,17 +6,20 @@ class MsgCommand:
|
||||
|
||||
def msg(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length >= 4:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
if length >= 5:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("Network does not exist: %s" % spl[1])
|
||||
return
|
||||
if not spl[1] in main.IRCPool.keys():
|
||||
if not int(spl[2]) in main.network[spl[1]].relays.keys():
|
||||
failure("Relay % does not exist on network %" % (spl[2], spl[1]))
|
||||
return
|
||||
if not spl[1]+spl[2] in main.IRCPool.keys():
|
||||
failure("Name has no instance: %s" % spl[1])
|
||||
return
|
||||
if not spl[2] in main.IRCPool[spl[1]].channels:
|
||||
info("Bot not on channel: %s" % spl[2])
|
||||
main.IRCPool[spl[1]].msg(spl[2], " ".join(spl[3:]))
|
||||
success("Sent %s to %s on %s" % (" ".join(spl[3:]), spl[2], spl[1]))
|
||||
if not spl[3] in main.IRCPool[spl[1]+spl[2]].channels:
|
||||
info("Bot not on channel: %s" % spl[3])
|
||||
main.IRCPool[spl[1]+spl[2]].msg(spl[3], " ".join(spl[4:]))
|
||||
success("Sent %s to %s on relay %s on network %s" % (" ".join(spl[4:]), spl[3], spl[2], spl[1]))
|
||||
return
|
||||
else:
|
||||
incUsage("msg")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import main
|
||||
from yaml import dump
|
||||
from modules.network import Network
|
||||
|
||||
class NetworkCommand:
|
||||
def __init__(self, *args):
|
||||
@@ -22,10 +23,7 @@ class NetworkCommand:
|
||||
failure("Auth must be sasl, ns or none, not %s" % spl[5])
|
||||
return
|
||||
else:
|
||||
main.network[spl[2]] = {"host": spl[3],
|
||||
"port": spl[4],
|
||||
"security": spl[5].lower(),
|
||||
"auth": spl[6].lower()}
|
||||
main.network[spl[2]] = Network(spl[2], spl[3], spl[4], spl[5].lower(), spl[6].lower())
|
||||
success("Successfully created network: %s" % spl[2])
|
||||
main.saveConf("network")
|
||||
return
|
||||
|
||||
@@ -6,15 +6,18 @@ class PartCommand:
|
||||
|
||||
def part(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 3:
|
||||
if not spl[1] in main.pool.keys():
|
||||
failure("Name does not exist: %s" % spl[1])
|
||||
if length == 4:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("Network does not exist: %s" % spl[1])
|
||||
return
|
||||
if not spl[1] in main.IRCPool.keys():
|
||||
failure("Name has no instance: %s" % spl[1])
|
||||
if not int(spl[2]) in main.network[spl[1]].relays.keys():
|
||||
failure("Relay % does not exist on network %", (spl[2], spl[1]))
|
||||
return
|
||||
main.IRCPool[spl[1]].part(spl[2])
|
||||
success("Left %s" % spl[2])
|
||||
if not spl[1]+spl[2] in main.IRCPool.keys():
|
||||
failure("Name has no instance: %s" % spl[1]+spl[2])
|
||||
return
|
||||
main.IRCPool[spl[1]+spl[2]].part(spl[3])
|
||||
success("Left %s" % spl[3])
|
||||
return
|
||||
else:
|
||||
incUsage("part")
|
||||
|
||||
@@ -9,40 +9,42 @@ class RelayCommand:
|
||||
if authed:
|
||||
if length == 7:
|
||||
if spl[1] == "add":
|
||||
if spl[2] in main.relay.keys():
|
||||
failure("Relay already exists: %s" % spl[2])
|
||||
if spl[2] not in main.network.keys():
|
||||
failure("No such network: %s" % spl[2])
|
||||
return
|
||||
if not spl[4].isdigit():
|
||||
failure("Port must be an integer, not %s" % spl[4])
|
||||
return
|
||||
else:
|
||||
main.relay[spl[2]] = {"host": spl[3],
|
||||
"port": spl[4],
|
||||
"user": spl[5],
|
||||
"password": spl[6]}
|
||||
success("Successfully created relay: %s" % spl[2])
|
||||
main.saveConf("relay")
|
||||
id, alias = main.network[spl[2]].add_relay(spl[3], spl[4], spl[5], spl[6])
|
||||
success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias))
|
||||
main.saveConf("network")
|
||||
return
|
||||
else:
|
||||
incUsage("relay")
|
||||
return
|
||||
|
||||
elif length == 3:
|
||||
elif length == 4:
|
||||
if spl[1] == "del":
|
||||
if spl[2] in main.relay.keys():
|
||||
del main.relay[spl[2]]
|
||||
success("Successfully removed relay: %s" % spl[2])
|
||||
main.saveConf("relay")
|
||||
if spl[2] not in main.network.keys():
|
||||
failure("No such network: %s" % spl[2])
|
||||
return
|
||||
else:
|
||||
failure("No such relay: %s" % spl[2])
|
||||
if int(spl[3]) not in main.network[spl[2]].relays.keys():
|
||||
failure("No such relay: %s on network %s" % (spl[3], spl[2]))
|
||||
return
|
||||
main.network[spl[2]].delete_relay(int(spl[3]))
|
||||
success("Successfully deleted relay %s on network %s" % (spl[3], spl[2]))
|
||||
main.saveConf("network")
|
||||
return
|
||||
else:
|
||||
incUsage("relay")
|
||||
return
|
||||
elif length == 2:
|
||||
elif length == 3:
|
||||
if spl[1] == "list":
|
||||
info(dump(main.relay))
|
||||
if spl[2] not in main.network.keys():
|
||||
failure("No such network: %s" % spl[2])
|
||||
return
|
||||
info(dump(main.network[spl[2]].relays))
|
||||
return
|
||||
else:
|
||||
incUsage("relay")
|
||||
|
||||
@@ -17,8 +17,7 @@ class StatsCommand:
|
||||
numChannels += len(main.IRCPool[i].channels)
|
||||
numWhoEntries += userinfo.getNumTotalWhoEntries()
|
||||
stats.append("Registered servers:")
|
||||
stats.append(" Total: %s" % len(main.pool.keys()))
|
||||
stats.append(" Unique: %s" % len(main.nets()))
|
||||
stats.append(" Total: %s" % len(main.network.keys()))
|
||||
stats.append("Online servers:")
|
||||
stats.append(" Total: %s" % len(main.IRCPool.keys()))
|
||||
stats.append(" Unique: %s" % len(main.liveNets()))
|
||||
|
||||
Reference in New Issue
Block a user