Implement sorting relay output by custom keys

This commit is contained in:
Mark Veidemanis 2019-10-05 18:20:51 +01:00
parent 5eda50af13
commit f0fff7c958
1 changed files with 18 additions and 14 deletions

View File

@ -7,6 +7,10 @@ from core.relay import sendRelayNotification
from modules import userinfo from modules import userinfo
from utils.dedup import dedup from utils.dedup import dedup
order = ["type", "net", "num", "channel", "msg", "nick",
"ident", "host", "mtype", "user", "modes", "modeargs"
"realname", "server", "status"]
def testNetTarget(name, target): def testNetTarget(name, target):
called = False called = False
for i in main.monitor.keys(): for i in main.monitor.keys():
@ -63,29 +67,29 @@ def event(numName, c): # yes I'm using a short variable because otherwise it goe
# need to check if this was received from a relay # need to check if this was received from a relay
# in which case, do not do this # in which case, do not do this
if c["type"] in ["msg", "notice", "action", "topic", "mode"]: if c["type"] in ["msg", "notice", "action", "topic", "mode"]:
userinfo.editUser(c["name"], c["muser"]) userinfo.editUser(c["net"], c["muser"])
elif c["type"] == "nick": elif c["type"] == "nick":
userinfo.renameUser(c["name"], c["nick"], c["muser"], c["user"], c["user"]+"!"+c["ident"]+"@"+c["host"]) userinfo.renameUser(c["net"], c["nick"], c["muser"], c["user"], c["user"]+"!"+c["ident"]+"@"+c["host"])
elif c["type"] == "kick": elif c["type"] == "kick":
userinfo.editUser(c["name"], c["muser"]) userinfo.editUser(c["net"], c["muser"])
userinfo.delUserByNick(c["name"], c["channel"], c["user"]) userinfo.delUserByNick(c["net"], c["channel"], c["user"])
elif c["type"] == "quit": elif c["type"] == "quit":
userinfo.delUserByNetwork(c["name"], c["nick"], c["muser"]) userinfo.delUserByNetwork(c["net"], c["nick"], c["muser"])
elif c["type"] == "join": elif c["type"] == "join":
userinfo.addUser(c["name"], c["channel"], c["nick"], c["muser"]) userinfo.addUser(c["net"], c["channel"], c["nick"], c["muser"])
elif c["type"] == "part": elif c["type"] == "part":
userinfo.delUser(c["name"], c["channel"], c["nick"], c["muser"]) userinfo.delUser(c["net"], c["channel"], c["nick"], c["muser"])
if "mtype" in c.keys(): if "mtype" in c.keys():
if c["mtype"] == "nick": if c["mtype"] == "nick":
userinfo.renameUser(c["name"], c["nick"], c["muser"], c["user"], c["user"]+"!"+c["ident"]+"@"+c["host"]) userinfo.renameUser(c["net"], c["nick"], c["muser"], c["user"], c["user"]+"!"+c["ident"]+"@"+c["host"])
if "muser" in c.keys(): if "muser" in c.keys():
del c["muser"] del c["muser"]
sendRelayNotification(c) sendRelayNotification({k: c[k] for k in order if k in c}) # Sort dict keys according to order
# only monitors below # only monitors below
monitorGroups = testNetTarget(c["name"], c["channel"]) monitorGroups = testNetTarget(c["net"], c["channel"])
if monitorGroups == False: if monitorGroups == False:
return return
for monitorGroup in monitorGroups: for monitorGroup in monitorGroups:
@ -95,11 +99,11 @@ def event(numName, c): # yes I'm using a short variable because otherwise it goe
if "send" in main.monitor[monitorGroup].keys(): if "send" in main.monitor[monitorGroup].keys():
for i in main.monitor[monitorGroup]["send"].keys(): for i in main.monitor[monitorGroup]["send"].keys():
if isinstance(main.monitor[monitorGroup]["send"][i], bool): if isinstance(main.monitor[monitorGroup]["send"][i], bool):
sendRelayNotification({"type": "err", "name": name, "channel": channel, "message": c, "reason": "errdeliv"}) sendRelayNotification({"type": "err", "net": net, "channel": channel, "message": c, "reason": "errdeliv"})
continue continue
if not i in main.pool.keys(): if not i in main.pool.keys():
sendRelayNotification({"type": "err", "name": name, "channel": channel, "message": c, "reason": "noname"}) sendRelayNotification({"type": "err", "net": net, "channel": channel, "message": c, "reason": "noname"})
if not i in main.IRCPool.keys(): if not i in main.IRCPool.keys():
sendRelayNotification({"type": "err", "name": name, "channel": channel, "message": c, "reason": "noinstance"}) sendRelayNotification({"type": "err", "net": net, "channel": channel, "message": c, "reason": "noinstance"})
for x in main.monitor[monitorGroup]["send"][i]: for x in main.monitor[monitorGroup]["send"][i]:
main.IRCPool[i].msg(x, "monitor [%s] (%s) %s" % (monitorGroup, c["name"], c)) main.IRCPool[i].msg(x, "monitor [%s] (%s) %s" % (monitorGroup, c["net"], c))