monolith/modules/monitor.py

84 lines
2.3 KiB
Python
Raw Normal View History

from copy import deepcopy
2019-03-20 20:22:46 +00:00
from json import dumps
import main
from core.relay import sendRelayNotification
2021-06-06 10:16:04 +00:00
from core.logstash import sendLogstashNotification
from modules import userinfo
from modules import regproc
from utils.dedup import dedup
2022-07-21 12:39:41 +00:00
order = [
"type",
"net",
"num",
"channel",
"msg",
"nick",
"ident",
"host",
"mtype",
"user",
"mode",
"modearg",
"realname",
"server",
"status",
"time",
]
def parsemeta(numName, c):
if not "channel" in c.keys():
c["channel"] = None
# metadata scraping
# need to check if this was received from a relay
# in which case, do not do this
if c["type"] in ["msg", "notice", "action", "topic", "mode"]:
if "muser" in c.keys():
userinfo.editUser(c["net"], c["muser"])
2022-07-21 12:39:41 +00:00
# if c["type"] == "mode":
# userinfo.updateMode(c)
elif c["type"] == "nick":
2022-07-21 12:39:41 +00:00
userinfo.renameUser(
c["net"],
c["nick"],
c["muser"],
c["user"],
c["user"] + "!" + c["ident"] + "@" + c["host"],
)
elif c["type"] == "kick":
userinfo.editUser(c["net"], c["muser"])
userinfo.delUserByNick(c["net"], c["channel"], c["user"])
elif c["type"] == "quit":
userinfo.delUserByNetwork(c["net"], c["nick"], c["muser"])
elif c["type"] == "join":
userinfo.addUser(c["net"], c["channel"], c["nick"], c["muser"])
elif c["type"] == "part":
userinfo.delUser(c["net"], c["channel"], c["nick"], c["muser"])
if "mtype" in c.keys():
if c["mtype"] == "nick":
2022-07-21 12:39:41 +00:00
userinfo.renameUser(
c["net"],
c["nick"],
c["muser"],
c["user"],
c["user"] + "!" + c["ident"] + "@" + c["host"],
)
2022-07-21 12:39:41 +00:00
def event(numName, c): # yes I'm using a short variable because otherwise it goes off the screen
if dedup(numName, c):
return
# make a copy of the object with dict() to prevent sending notifications with channel of None
parsemeta(numName, dict(c))
if "muser" in c.keys():
del c["muser"]
2022-07-21 12:39:41 +00:00
sortedKeys = {k: c[k] for k in order if k in c} # Sort dict keys according to order
2021-06-06 10:16:04 +00:00
sortedKeys["src"] = "irc"
sendLogstashNotification(sortedKeys)
sendRelayNotification(sortedKeys)