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

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

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