Start implementing relay abstractions for smarter network handling and minor cosmetic changes

This commit is contained in:
Mark Veidemanis 2019-01-20 19:56:54 +00:00
parent e97792c460
commit 6046329a83
10 changed files with 128 additions and 7 deletions

2
.gitignore vendored
View File

@ -8,5 +8,7 @@ conf/keyword.json
conf/counters.json conf/counters.json
conf/masterbuf.json conf/masterbuf.json
conf/monitor.json conf/monitor.json
conf/alias.json
conf/relay.json
conf/dist.sh conf/dist.sh
env/ env/

50
commands/alias.py Normal file
View 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)

View File

@ -16,6 +16,9 @@ class Load:
main.loadConf(i) main.loadConf(i)
success("Loaded %s from %s" % (i, main.filemap[i][0])) success("Loaded %s from %s" % (i, main.filemap[i][0]))
return return
elif spl[1] == "list":
info(", ".join(main.filemap.keys()))
return
else: else:
incUsage("load") incUsage("load")
return return

54
commands/relay.py Normal file
View 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)

View File

@ -16,6 +16,8 @@ class Save:
main.saveConf(i) main.saveConf(i)
success("Saved %s to %s" % (i, main.filemap[i][0])) success("Saved %s to %s" % (i, main.filemap[i][0]))
return return
elif spl[1] == "list":
info(", ".join(main.filemap.keys()))
else: else:
incUsage("save") incUsage("save")
return return

1
conf/example/relay.json Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -14,12 +14,14 @@
"disable": "disable <name>", "disable": "disable <name>",
"list": "list", "list": "list",
"stats": "stats [<name>]", "stats": "stats [<name>]",
"save": "save <config|keyconf|pool|help|counters|masterbuf|monitor|all>", "save": "save <(file)|list|all>",
"load": "load <config|keyconf|pool|help|counters|masterbuf|monitor|all>", "load": "load <(file)|list|all>",
"dist": "dist", "dist": "dist",
"loadmod": "loadmod <module>", "loadmod": "loadmod <module>",
"msg": "msg <name> <target> <message...>", "msg": "msg <name> <target> <message...>",
"mon": "mon -h", "mon": "mon -h",
"chans": "chans <nick> [<nick> ...]", "chans": "chans <nick> [<nick> ...]",
"users": "users <channel> [<channel> ...]" "users": "users <channel> [<channel> ...]",
"alias": "alias <add|del|list> [<alias> <nickname> <ident> <realname>]",
"relay": "relay <add|del|list> [<relay> <host> <port> <user> <password>"
} }

View File

@ -12,10 +12,11 @@ filemap = {
"keyconf": ["keyword.json", "keyword lists"], "keyconf": ["keyword.json", "keyword lists"],
"pool": ["pool.json", "pool"], "pool": ["pool.json", "pool"],
"help": ["help.json", "command help"], "help": ["help.json", "command help"],
# "wholist": ["wholist.json", "WHO lists"],
"counters": ["counters.json", "counters file"], "counters": ["counters.json", "counters file"],
"masterbuf": ["masterbuf.json", "master buffer"], "masterbuf": ["masterbuf.json", "master buffer"],
"monitor": ["monitor.json", "monitoring database"], "monitor": ["monitor.json", "monitoring database"],
"alias": ["alias.json", "alias details"],
"relay": ["relay.json", "relay list"],
} }
connections = {} connections = {}

View File

@ -3,14 +3,20 @@ import main
def sendData(addr, data): def sendData(addr, data):
main.connections[addr].send(data) main.connections[addr].send(data)
def sendWithPrefix(addr, data, prefix):
toSend = ""
for i in data.split("\n"):
toSend += prefix + " " + i + "\n"
sendData(addr, toSend)
def sendSuccess(addr, data): def sendSuccess(addr, data):
sendData(addr, "[y] " + data) sendWithPrefix(addr, data, "[y]")
def sendFailure(addr, data): def sendFailure(addr, data):
sendData(addr, "[n] " + data) sendWithPrefix(addr, data, "[n]")
def sendInfo(addr, data): def sendInfo(addr, data):
sendData(addr, "[i] " + data) sendWithPrefix(addr, data, "[i]")
def sendAll(data): def sendAll(data):
for i in main.connections: for i in main.connections: