monolith/commands/alias.py

62 lines
2.3 KiB
Python

import main
from yaml import dump
import modules.alias as alias
class AliasCommand:
def __init__(self, *args):
self.alias(*args)
def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 8:
if spl[1] == "add":
if spl[2] in main.alias.keys():
failure("Alias already exists: %s" % spl[2])
return
else:
main.alias[spl[2]] = {"nick": spl[3],
"altnick": spl[4],
"ident": spl[5],
"realname": spl[6],
"password": spl[7]}
success("Successfully created alias: %s" % spl[2])
main.saveConf("alias")
return
else:
incUsage("alias")
return
elif length == 3:
if spl[1] == "del":
if spl[2] in main.alias.keys():
del main.alias[spl[2]]
success("Successfully removed alias: %s" % spl[2])
main.saveConf("alias")
return
else:
failure("No such alias: %s" % spl[2])
return
elif spl[1] == "add" and spl[2] == "auto":
newalias = alias.generate_alias()
while newalias["nick"] in main.alias.keys():
newalias = alias.generate_alias()
main.alias[newalias["nick"]] = newalias
success("Successfully created alias: %s" % newalias["nick"])
main.saveConf("alias")
return
else:
incUsage("alias")
return
elif length == 2:
if spl[1] == "list":
info(dump(main.alias))
return
else:
incUsage("alias")
return
else:
incUsage("alias")
return
else:
incUsage(None)