Fix the all and allc commands so they work with the new data format

This commit is contained in:
Mark Veidemanis 2019-09-29 14:57:36 +01:00
parent 15ca45e5df
commit 355a80b19b
8 changed files with 45 additions and 35 deletions

View File

@ -1,20 +1,21 @@
import main import main
from core.bot import deliverRelayCommands from core.bot import deliverRelayCommands
class All: class AllCommand:
def __init__(self, *args): def __init__(self, *args):
self.all(*args) self.all(*args)
def all(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): def all(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed: if authed:
if length > 2: if length > 2:
for i in main.pool.keys(): for i in main.network.keys():
relay = main.pool[i]["relay"] for x in main.network[i].relays.keys():
network = main.pool[i]["network"] num = main.network[i].relays[x]["id"]
alias = main.pool[i]["alias"] net = main.network[i].relays[x]["net"]
commands = {spl[1]: [" ".join(spl[2:])]} alias = main.network[i].aliases[x]["nick"]
success("Sending commands to relay %s as user %s" % (relay, alias+"/"+network)) commands = {spl[1]: [" ".join(spl[2:])]}
deliverRelayCommands(relay, commands, user=alias+"/"+network) success("Sending commands to relay %s as user %s" % (num, alias+"/"+net))
deliverRelayCommands(num, commands, user=alias+"/"+net)
return return
else: else:
incUsage("all") incUsage("all")

View File

@ -1,7 +1,7 @@
import main import main
from core.bot import deliverRelayCommands from core.bot import deliverRelayCommands
class Allc: class AllcCommand:
def __init__(self, *args): def __init__(self, *args):
self.allc(*args) self.allc(*args)
@ -10,21 +10,14 @@ class Allc:
if length > 4: if length > 4:
targets = [] targets = []
if spl[1] == "network": if spl[1] == "network":
if spl[2] in main.network.keys(): for i in main.network.keys():
for i in main.pool.keys(): for x in main.network[i].relays.keys():
if main.pool[i]["network"] == spl[2]: if main.network[i].relays[x]["net"] == spl[2]:
targets.append(i) targets.append((i, x))
else:
failure("No such network: %s" % spl[2])
return
elif spl[1] == "alias": elif spl[1] == "alias":
if spl[2] in main.alias.keys(): for i in main.network.keys():
for i in main.pool.keys(): [targets.append((i, x)) for x in main.network[i].aliases.keys() if
if main.pool[i]["alias"] == spl[2]: main.network[i].aliases[x]["nick"] == spl[2]]
targets.append(i)
else:
failure("No such alias: %s" % spl[2])
return
else: else:
incUsage("allc") incUsage("allc")
return return
@ -32,12 +25,12 @@ class Allc:
failure("No matches found: %s" % spl[2]) failure("No matches found: %s" % spl[2])
return return
for i in targets: for i in targets:
relay = main.pool[i]["relay"] net = i[0]
network = main.pool[i]["network"] num = i[1]
alias = main.pool[i]["alias"] alias = main.network[net].aliases[num]["nick"]
commands = {spl[3]: [" ".join(spl[4:])]} commands = {spl[3]: [" ".join(spl[4:])]}
success("Sending commands to relay %s as user %s" % (relay, alias+"/"+network)) success("Sending commands to relay %i as user %s" % (num, alias+"/"+net))
deliverRelayCommands(relay, commands, user=alias+"/"+network) deliverRelayCommands(num, commands, user=alias+"/"+net)
return return
else: else:
incUsage("allc") incUsage("allc")

View File

@ -12,7 +12,7 @@ class AutoCommand:
failure("No such network: %s" % spl[1]) failure("No such network: %s" % spl[1])
return return
if not spl[2].isdigit(): if not spl[2].isdigit():
failure("Must be integer, not %s" % spl[2]) failure("Must be a number, not %s" % spl[2])
return return
relayNum = int(spl[2]) relayNum = int(spl[2])
id, alias = main.network[spl[1]].add_relay(relayNum) id, alias = main.network[spl[1]].add_relay(relayNum)
@ -21,6 +21,16 @@ class AutoCommand:
rtrn = provision.provisionRelay(relayNum, spl[1]) rtrn = provision.provisionRelay(relayNum, spl[1])
success("Started provisioning network %s on relay %s for alias %s" % (spl[1], spl[2], rtrn)) success("Started provisioning network %s on relay %s for alias %s" % (spl[1], spl[2], rtrn))
return 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: else:
incUsage("auto") incUsage("auto")

View File

@ -9,7 +9,7 @@ class CmdCommand:
if authed: if authed:
if length > 4: if length > 4:
if not spl[1].isdigit(): if not spl[1].isdigit():
failure("Must be integer, not %s" % spl[1]) failure("Must be a number, not %s" % spl[1])
return return
commands = {spl[3]: [" ".join(spl[4:])]} commands = {spl[3]: [" ".join(spl[4:])]}
success("Sending commands to relay %s as user %s" % (spl[2], spl[3])) success("Sending commands to relay %s as user %s" % (spl[2], spl[3]))

View File

@ -12,7 +12,7 @@ class DisableCommand:
failure("No such network: %s" % spl[1]) failure("No such network: %s" % spl[1])
return return
if not spl[2].isdigit(): if not spl[2].isdigit():
failure("Must be integer, not %s" % spl[2]) failure("Must be a number, not %s" % spl[2])
return return
relayNum = int(spl[2]) relayNum = int(spl[2])
name = spl[1]+spl[2] name = spl[1]+spl[2]

View File

@ -1,6 +1,7 @@
import main import main
from yaml import dump from yaml import dump
from modules.network import Network from modules.network import Network
from string import digits
class NetworkCommand: class NetworkCommand:
def __init__(self, *args): def __init__(self, *args):
@ -19,6 +20,9 @@ class NetworkCommand:
if not spl[5].lower() in ["ssl", "plain"]: if not spl[5].lower() in ["ssl", "plain"]:
failure("Security must be ssl or plain, not %s" % spl[5]) failure("Security must be ssl or plain, not %s" % spl[5])
return return
if set(spl[2]).intersection(set(digits)):
failure("Network name cannot contain numbers")
return
if not spl[6].lower() in ["sasl", "ns", "none"]: if not spl[6].lower() in ["sasl", "ns", "none"]:
failure("Auth must be sasl, ns or none, not %s" % spl[5]) failure("Auth must be sasl, ns or none, not %s" % spl[5])
return return

View File

@ -469,11 +469,11 @@ class IRCBotFactory(ReconnectingClientFactory):
self.relayCommands, self.user, self.stage2 = relayCommands, user, stage2 self.relayCommands, self.user, self.stage2 = relayCommands, user, stage2
def buildProtocol(self, addr): def buildProtocol(self, addr):
if self.relay == None: if self.relay == False:
entry = IRCRelay(self.num, self.relayCommands, self.user, self.stage2)
else:
entry = IRCBot(self.net, self.num) entry = IRCBot(self.net, self.num)
main.IRCPool[self.name] = entry main.IRCPool[self.name] = entry
else:
entry = IRCRelay(self.num, self.relayCommands, self.user, self.stage2)
self.client = entry self.client = entry
return entry return entry

View File

@ -25,11 +25,13 @@ class Network:
self.last += 1 self.last += 1
num = self.last num = self.last
self.relays[num] = { self.relays[num] = {
"enabled": False, "enabled": main.config["ConnectOnCreate"],
"net": self.net, "net": self.net,
"id": num "id": num
} }
self.aliases[num] = alias.generate_alias() self.aliases[num] = alias.generate_alias()
if main.config["ConnectOnCreate"]:
self.start_bot(num)
return num, self.aliases[num]["nick"] return num, self.aliases[num]["nick"]
def delete_relay(self, id): def delete_relay(self, id):