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
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"]
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" % (relay, alias+"/"+network))
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
else:
incUsage("all")

View File

@ -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")

View File

@ -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")

View File

@ -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]))

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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):