Change alias definitions to be global, so aliases can be reused across different networks
This commit is contained in:
12
commands/alias.py
Normal file
12
commands/alias.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import main
|
||||
from yaml import dump
|
||||
|
||||
class AliasCommand:
|
||||
def __init__(self, *args):
|
||||
self.alias(*args)
|
||||
|
||||
def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
info(dump(main.alias))
|
||||
else:
|
||||
incUsage(None)
|
||||
@@ -12,7 +12,7 @@ class AllCommand:
|
||||
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"]
|
||||
alias = main.alias[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)
|
||||
|
||||
@@ -16,8 +16,9 @@ class AllcCommand:
|
||||
targets.append((i, x))
|
||||
elif spl[1] == "alias":
|
||||
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]]
|
||||
[targets.append((i, x)) for x in main.alias.keys() if
|
||||
main.alias[x]["nick"] == spl[2] and
|
||||
x in main.network[i].aliases.keys()]
|
||||
else:
|
||||
incUsage("allc")
|
||||
return
|
||||
@@ -27,7 +28,7 @@ class AllcCommand:
|
||||
for i in targets:
|
||||
net = i[0]
|
||||
num = i[1]
|
||||
alias = main.network[net].aliases[num]["nick"]
|
||||
alias = main.alias[num]["nick"]
|
||||
commands = {spl[3]: [" ".join(spl[4:])]}
|
||||
success("Sending commands to relay %i as user %s" % (num, alias+"/"+net))
|
||||
deliverRelayCommands(num, commands, user=alias+"/"+net)
|
||||
|
||||
@@ -15,8 +15,8 @@ class AutoCommand:
|
||||
failure("Must be a number, not %s" % spl[2])
|
||||
return
|
||||
relayNum = int(spl[2])
|
||||
id, alias = main.network[spl[1]].add_relay(relayNum)
|
||||
success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[1], alias))
|
||||
num, alias = main.network[spl[1]].add_relay(relayNum)
|
||||
success("Successfully created relay %i on network %s with alias %s" % (num, spl[1], alias))
|
||||
main.saveConf("network")
|
||||
rtrn = provision.provisionRelay(relayNum, spl[1])
|
||||
success("Started provisioning network %s on relay %s for alias %s" % (spl[1], spl[2], rtrn))
|
||||
@@ -26,7 +26,7 @@ class AutoCommand:
|
||||
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))
|
||||
success("Successfully created relay %i on network %s with alias %s" % (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))
|
||||
|
||||
@@ -22,7 +22,7 @@ class DisableCommand:
|
||||
failure("No such relay: %s in network %s" % (spl[2], spl[1]))
|
||||
return
|
||||
main.network[spl[1]].relays[relayNum]["enabled"] = False
|
||||
user = main.network[spl[1]].aliases[relayNum]["nick"]
|
||||
user = main.alias[relayNum]["nick"]
|
||||
network = spl[1]
|
||||
relay = main.network[spl[1]].relays[relayNum]
|
||||
commands = {"status": ["Disconnect"]}
|
||||
|
||||
@@ -19,7 +19,7 @@ class EnableCommand:
|
||||
return
|
||||
|
||||
main.network[spl[1]].relays[int(spl[2])]["enabled"] = True
|
||||
user = main.network[spl[1]].aliases[int(spl[2])]["nick"]
|
||||
user = main.alias[int(spl[2])]["nick"]
|
||||
network = spl[1]
|
||||
commands = {"status": ["Connect"]}
|
||||
deliverRelayCommands(int(spl[2]), commands, user=user+"/"+network)
|
||||
|
||||
@@ -22,21 +22,24 @@ class ModCommand:
|
||||
main.saveConf("network")
|
||||
success("Successfully set key %s to %s on %s" % (spl[2], spl[3], spl[1]))
|
||||
return
|
||||
# Find a better way to do this
|
||||
#elif length == 6:
|
||||
# if not spl[1] in main.network.keys():
|
||||
# failure("Network does not exist: %s" % spl[1])
|
||||
# return
|
||||
# if not spl[3].isdigit():
|
||||
# failure("Must be a number, not %s" % spl[3])
|
||||
# return
|
||||
# if not int(spl[3]) in main.network[spl[1]].relays.keys():
|
||||
# failure("Relay/alias does not exist: %s" % spl[3])
|
||||
# return
|
||||
|
||||
elif length == 6:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("Network does not exist: %s" % spl[1])
|
||||
return
|
||||
if not int(spl[3]) in main.network[spl[1]].relays.keys():
|
||||
failure("Relay/alias does not exist: %s" % spl[3])
|
||||
return
|
||||
|
||||
try:
|
||||
x = getattr(main.network[spl[1]], spl[2])
|
||||
x[spl[3]] = spl[4]
|
||||
except e:
|
||||
failure("Something went wrong.")
|
||||
return
|
||||
# try:
|
||||
# x = getattr(main.network[spl[1]], spl[2])
|
||||
# x[spl[3]] = spl[4]
|
||||
# except Exception as err:
|
||||
# failure("Error: %s" % err)
|
||||
# return
|
||||
|
||||
else:
|
||||
incUsage("mod")
|
||||
|
||||
Reference in New Issue
Block a user