monolith/legacy/commands/allc.py

50 lines
1.8 KiB
Python
Raw Normal View History

import main
2022-07-21 12:40:05 +00:00
from utils.deliver_relay_commands import deliverRelayCommands
2022-07-21 12:39:41 +00:00
class AllcCommand:
def __init__(self, *args):
self.allc(*args)
2022-09-05 06:20:30 +00:00
def allc(
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
):
if authed:
if length > 4:
targets = []
if spl[1] == "network":
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":
for i in main.network.keys():
2022-07-21 12:39:41 +00:00
[
targets.append((i, x))
for x in main.alias.keys()
2022-09-05 06:20:30 +00:00
if main.alias[x]["nick"] == spl[2]
and x in main.network[i].aliases.keys()
2022-07-21 12:39:41 +00:00
]
else:
incUsage("allc")
return
if len(targets) == 0:
failure("No matches found: %s" % spl[2])
return
for i in targets:
net = i[0]
num = i[1]
alias = main.alias[num]["nick"]
commands = {spl[3]: [" ".join(spl[4:])]}
2022-09-05 06:20:30 +00:00
success(
"Sending commands to relay %i as user %s"
% (num, alias + "/" + net)
)
2022-07-21 12:39:41 +00:00
deliverRelayCommands(num, commands, user=alias + "/" + net)
return
else:
incUsage("allc")
return
else:
incUsage(None)