Start implementing relay abstractions for smarter network handling and minor cosmetic changes
This commit is contained in:
50
commands/alias.py
Normal file
50
commands/alias.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import main
|
||||
from yaml import dump
|
||||
|
||||
class Alias:
|
||||
def __init__(self, register):
|
||||
register("alias", self.alias)
|
||||
|
||||
def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 6:
|
||||
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],
|
||||
"ident": spl[4],
|
||||
"realname": spl[5]}
|
||||
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
|
||||
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)
|
||||
@@ -16,6 +16,9 @@ class Load:
|
||||
main.loadConf(i)
|
||||
success("Loaded %s from %s" % (i, main.filemap[i][0]))
|
||||
return
|
||||
elif spl[1] == "list":
|
||||
info(", ".join(main.filemap.keys()))
|
||||
return
|
||||
else:
|
||||
incUsage("load")
|
||||
return
|
||||
|
||||
54
commands/relay.py
Normal file
54
commands/relay.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import main
|
||||
from yaml import dump
|
||||
|
||||
class Relay:
|
||||
def __init__(self, register):
|
||||
register("relay", self.relay)
|
||||
|
||||
def relay(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
if length == 7:
|
||||
if spl[1] == "add":
|
||||
if spl[2] in main.relay.keys():
|
||||
failure("Relay already exists: %s" % spl[2])
|
||||
return
|
||||
else:
|
||||
if not spl[4].isdigit():
|
||||
failure("Port must be an integer, not %s" % spl[4])
|
||||
return
|
||||
main.relay[spl[2]] = {"host": spl[3],
|
||||
"port": spl[4],
|
||||
"user": spl[5],
|
||||
"password": spl[6]}
|
||||
success("Successfully created relay: %s" % spl[2])
|
||||
main.saveConf("relay")
|
||||
return
|
||||
else:
|
||||
incUsage("relay")
|
||||
return
|
||||
|
||||
elif length == 3:
|
||||
if spl[1] == "del":
|
||||
if spl[2] in main.relay.keys():
|
||||
del main.relay[spl[2]]
|
||||
success("Successfully removed relay: %s" % spl[2])
|
||||
main.saveConf("relay")
|
||||
return
|
||||
else:
|
||||
failure("No such relay: %s" % spl[2])
|
||||
return
|
||||
else:
|
||||
incUsage("relay")
|
||||
return
|
||||
elif length == 2:
|
||||
if spl[1] == "list":
|
||||
info(dump(main.relay))
|
||||
return
|
||||
else:
|
||||
incUsage("relay")
|
||||
return
|
||||
else:
|
||||
incUsage("relay")
|
||||
return
|
||||
else:
|
||||
incUsage(None)
|
||||
@@ -16,6 +16,8 @@ class Save:
|
||||
main.saveConf(i)
|
||||
success("Saved %s to %s" % (i, main.filemap[i][0]))
|
||||
return
|
||||
elif spl[1] == "list":
|
||||
info(", ".join(main.filemap.keys()))
|
||||
else:
|
||||
incUsage("save")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user