diff --git a/commands/all.py b/commands/all.py index 10ec381..a6c377f 100644 --- a/commands/all.py +++ b/commands/all.py @@ -1,20 +1,21 @@ import main from core.bot import deliverRelayCommands -class All: +class AllCommand: def __init__(self, *args): self.all(*args) def all(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length > 2: - for i in main.pool.keys(): - relay = main.pool[i]["relay"] - network = main.pool[i]["network"] - alias = main.pool[i]["alias"] - commands = {spl[1]: [" ".join(spl[2:])]} - success("Sending commands to relay %s as user %s" % (relay, alias+"/"+network)) - deliverRelayCommands(relay, commands, user=alias+"/"+network) + for i in main.network.keys(): + for x in main.network[i].relays.keys(): + num = main.network[i].relays[x]["id"] + net = main.network[i].relays[x]["net"] + alias = main.network[i].aliases[x]["nick"] + commands = {spl[1]: [" ".join(spl[2:])]} + success("Sending commands to relay %s as user %s" % (num, alias+"/"+net)) + deliverRelayCommands(num, commands, user=alias+"/"+net) return else: incUsage("all") diff --git a/commands/allc.py b/commands/allc.py index 9e662fe..41b1a48 100644 --- a/commands/allc.py +++ b/commands/allc.py @@ -1,7 +1,7 @@ import main from core.bot import deliverRelayCommands -class Allc: +class AllcCommand: def __init__(self, *args): self.allc(*args) @@ -10,21 +10,14 @@ class Allc: if length > 4: targets = [] if spl[1] == "network": - if spl[2] in main.network.keys(): - for i in main.pool.keys(): - if main.pool[i]["network"] == spl[2]: - targets.append(i) - else: - failure("No such network: %s" % spl[2]) - return + for i in main.network.keys(): + for x in main.network[i].relays.keys(): + if main.network[i].relays[x]["net"] == spl[2]: + targets.append((i, x)) elif spl[1] == "alias": - if spl[2] in main.alias.keys(): - for i in main.pool.keys(): - if main.pool[i]["alias"] == spl[2]: - targets.append(i) - else: - failure("No such alias: %s" % spl[2]) - return + for i in main.network.keys(): + [targets.append((i, x)) for x in main.network[i].aliases.keys() if + main.network[i].aliases[x]["nick"] == spl[2]] else: incUsage("allc") return @@ -32,12 +25,12 @@ class Allc: failure("No matches found: %s" % spl[2]) return for i in targets: - relay = main.pool[i]["relay"] - network = main.pool[i]["network"] - alias = main.pool[i]["alias"] + net = i[0] + num = i[1] + alias = main.network[net].aliases[num]["nick"] commands = {spl[3]: [" ".join(spl[4:])]} - success("Sending commands to relay %s as user %s" % (relay, alias+"/"+network)) - deliverRelayCommands(relay, commands, user=alias+"/"+network) + success("Sending commands to relay %i as user %s" % (num, alias+"/"+net)) + deliverRelayCommands(num, commands, user=alias+"/"+net) return else: incUsage("allc") diff --git a/commands/auto.py b/commands/auto.py index 05e8d6c..90a2839 100644 --- a/commands/auto.py +++ b/commands/auto.py @@ -12,7 +12,7 @@ class AutoCommand: failure("No such network: %s" % spl[1]) return if not spl[2].isdigit(): - failure("Must be integer, not %s" % spl[2]) + failure("Must be a number, not %s" % spl[2]) return relayNum = int(spl[2]) id, alias = main.network[spl[1]].add_relay(relayNum) @@ -21,6 +21,16 @@ class AutoCommand: rtrn = provision.provisionRelay(relayNum, spl[1]) success("Started provisioning network %s on relay %s for alias %s" % (spl[1], spl[2], rtrn)) return + elif length == 2: + if not spl[1] in main.network.keys(): + failure("No such network: %s" % spl[1]) + return + num, alias = main.network[spl[1]].add_relay() + success("Successfully created relay %s on network %s with alias %s" % (str(num), spl[1], alias)) + main.saveConf("network") + rtrn = provision.provisionRelay(num, spl[1]) + success("Started provisioning network %s on relay %s for alias %s" % (spl[1], num, rtrn)) + return else: incUsage("auto") diff --git a/commands/cmd.py b/commands/cmd.py index 858dc15..466b197 100644 --- a/commands/cmd.py +++ b/commands/cmd.py @@ -9,7 +9,7 @@ class CmdCommand: if authed: if length > 4: if not spl[1].isdigit(): - failure("Must be integer, not %s" % spl[1]) + failure("Must be a number, not %s" % spl[1]) return commands = {spl[3]: [" ".join(spl[4:])]} success("Sending commands to relay %s as user %s" % (spl[2], spl[3])) diff --git a/commands/disable.py b/commands/disable.py index 7abfec0..2da50f3 100644 --- a/commands/disable.py +++ b/commands/disable.py @@ -12,7 +12,7 @@ class DisableCommand: failure("No such network: %s" % spl[1]) return if not spl[2].isdigit(): - failure("Must be integer, not %s" % spl[2]) + failure("Must be a number, not %s" % spl[2]) return relayNum = int(spl[2]) name = spl[1]+spl[2] diff --git a/commands/network.py b/commands/network.py index b9cfbfd..33d404c 100644 --- a/commands/network.py +++ b/commands/network.py @@ -1,6 +1,7 @@ import main from yaml import dump from modules.network import Network +from string import digits class NetworkCommand: def __init__(self, *args): @@ -19,6 +20,9 @@ class NetworkCommand: if not spl[5].lower() in ["ssl", "plain"]: failure("Security must be ssl or plain, not %s" % spl[5]) return + if set(spl[2]).intersection(set(digits)): + failure("Network name cannot contain numbers") + return if not spl[6].lower() in ["sasl", "ns", "none"]: failure("Auth must be sasl, ns or none, not %s" % spl[5]) return diff --git a/core/bot.py b/core/bot.py index 466a2a4..952293e 100644 --- a/core/bot.py +++ b/core/bot.py @@ -469,11 +469,11 @@ class IRCBotFactory(ReconnectingClientFactory): self.relayCommands, self.user, self.stage2 = relayCommands, user, stage2 def buildProtocol(self, addr): - if self.relay == None: - entry = IRCRelay(self.num, self.relayCommands, self.user, self.stage2) - else: + if self.relay == False: entry = IRCBot(self.net, self.num) main.IRCPool[self.name] = entry + else: + entry = IRCRelay(self.num, self.relayCommands, self.user, self.stage2) self.client = entry return entry diff --git a/modules/network.py b/modules/network.py index b6f0cfc..094a0a5 100644 --- a/modules/network.py +++ b/modules/network.py @@ -25,11 +25,13 @@ class Network: self.last += 1 num = self.last self.relays[num] = { - "enabled": False, + "enabled": main.config["ConnectOnCreate"], "net": self.net, "id": num } self.aliases[num] = alias.generate_alias() + if main.config["ConnectOnCreate"]: + self.start_bot(num) return num, self.aliases[num]["nick"] def delete_relay(self, id):