2022-07-21 12:40:01 +00:00
|
|
|
from yaml import dump
|
2022-07-21 12:40:09 +00:00
|
|
|
|
|
|
|
import main
|
2019-10-02 19:26:05 +00:00
|
|
|
from modules import alias
|
2019-09-29 21:45:16 +00:00
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-09-29 21:45:16 +00:00
|
|
|
class AliasCommand:
|
|
|
|
def __init__(self, *args):
|
|
|
|
self.alias(*args)
|
|
|
|
|
2022-07-21 12:40:01 +00:00
|
|
|
def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
2019-09-29 21:45:16 +00:00
|
|
|
if authed:
|
2019-10-02 19:26:05 +00:00
|
|
|
if length == 1:
|
|
|
|
info(dump(main.alias))
|
|
|
|
return
|
|
|
|
elif length == 3:
|
|
|
|
if spl[1] == "add":
|
|
|
|
if not spl[2].isdigit():
|
|
|
|
failure("Must be a number, not %s" % spl[2])
|
|
|
|
return
|
|
|
|
num = int(spl[2])
|
|
|
|
for i in range(num):
|
2019-10-02 19:45:28 +00:00
|
|
|
if len(main.alias.keys()) == 0:
|
|
|
|
nextNum = 1
|
|
|
|
else:
|
2022-07-21 12:39:41 +00:00
|
|
|
nextNum = max(main.alias.keys()) + 1
|
2019-10-02 19:26:05 +00:00
|
|
|
main.alias[nextNum] = alias.generate_alias()
|
|
|
|
success("Generated new alias: %i" % nextNum)
|
|
|
|
main.saveConf("alias")
|
|
|
|
return
|
|
|
|
elif spl[1] == "del":
|
|
|
|
if not spl[2].isdigit():
|
|
|
|
failure("Must be a number, not %s" % spl[2])
|
|
|
|
return
|
|
|
|
num = int(spl[2])
|
2022-07-21 12:40:05 +00:00
|
|
|
if num not in main.alias.keys():
|
2019-10-02 19:45:28 +00:00
|
|
|
failure("No such alias: %i" % num)
|
|
|
|
return
|
2019-10-02 19:26:05 +00:00
|
|
|
failed = False
|
|
|
|
for i in main.network.keys():
|
|
|
|
if num in main.network[i].aliases.keys():
|
|
|
|
failure("Alias in use by %s" % i)
|
|
|
|
failed = True
|
|
|
|
if failed:
|
|
|
|
return
|
|
|
|
del main.alias[num]
|
|
|
|
success("Removed alias: %i" % num)
|
|
|
|
main.saveConf("alias")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage("alias")
|
|
|
|
return
|
2019-09-29 21:45:16 +00:00
|
|
|
else:
|
|
|
|
incUsage(None)
|