2018-07-28 20:33:50 +00:00
|
|
|
from copy import deepcopy
|
2019-03-20 20:22:46 +00:00
|
|
|
from json import dumps
|
2018-07-27 21:58:37 +00:00
|
|
|
|
2019-08-05 21:51:16 +00:00
|
|
|
import main
|
|
|
|
from core.relay import sendRelayNotification
|
2021-06-06 10:16:04 +00:00
|
|
|
from core.logstash import sendLogstashNotification
|
2019-08-12 20:03:47 +00:00
|
|
|
from modules import userinfo
|
2020-05-31 20:52:56 +00:00
|
|
|
from modules import regproc
|
2019-08-15 20:20:49 +00:00
|
|
|
from utils.dedup import dedup
|
2019-08-05 21:51:16 +00:00
|
|
|
|
2019-10-05 17:20:51 +00:00
|
|
|
order = ["type", "net", "num", "channel", "msg", "nick",
|
2020-06-02 20:34:15 +00:00
|
|
|
"ident", "host", "mtype", "user", "mode", "modearg",
|
|
|
|
"realname", "server", "status", "time"]
|
2019-10-05 17:20:51 +00:00
|
|
|
|
2020-06-07 16:26:53 +00:00
|
|
|
def parsemeta(numName, c):
|
2019-10-04 23:51:00 +00:00
|
|
|
if not "channel" in c.keys():
|
|
|
|
c["channel"] = None
|
2019-08-12 20:03:47 +00:00
|
|
|
# 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"]:
|
2020-11-01 19:03:56 +00:00
|
|
|
if "muser" in c.keys():
|
|
|
|
userinfo.editUser(c["net"], c["muser"])
|
2020-10-28 22:26:41 +00:00
|
|
|
#if c["type"] == "mode":
|
|
|
|
# userinfo.updateMode(c)
|
2019-08-12 20:03:47 +00:00
|
|
|
elif c["type"] == "nick":
|
2019-10-05 17:20:51 +00:00
|
|
|
userinfo.renameUser(c["net"], c["nick"], c["muser"], c["user"], c["user"]+"!"+c["ident"]+"@"+c["host"])
|
2019-08-12 20:03:47 +00:00
|
|
|
elif c["type"] == "kick":
|
2019-10-05 17:20:51 +00:00
|
|
|
userinfo.editUser(c["net"], c["muser"])
|
|
|
|
userinfo.delUserByNick(c["net"], c["channel"], c["user"])
|
2019-08-12 20:03:47 +00:00
|
|
|
elif c["type"] == "quit":
|
2019-10-05 17:20:51 +00:00
|
|
|
userinfo.delUserByNetwork(c["net"], c["nick"], c["muser"])
|
2019-08-12 20:03:47 +00:00
|
|
|
elif c["type"] == "join":
|
2019-10-05 17:20:51 +00:00
|
|
|
userinfo.addUser(c["net"], c["channel"], c["nick"], c["muser"])
|
2019-08-12 20:03:47 +00:00
|
|
|
elif c["type"] == "part":
|
2019-10-05 17:20:51 +00:00
|
|
|
userinfo.delUser(c["net"], c["channel"], c["nick"], c["muser"])
|
2019-08-12 20:03:47 +00:00
|
|
|
|
|
|
|
if "mtype" in c.keys():
|
|
|
|
if c["mtype"] == "nick":
|
2019-10-05 17:20:51 +00:00
|
|
|
userinfo.renameUser(c["net"], c["nick"], c["muser"], c["user"], c["user"]+"!"+c["ident"]+"@"+c["host"])
|
2019-08-05 21:51:16 +00:00
|
|
|
|
2020-06-07 16:26:53 +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))
|
|
|
|
|
2019-08-12 20:03:47 +00:00
|
|
|
if "muser" in c.keys():
|
|
|
|
del c["muser"]
|
2021-06-06 10:16:04 +00:00
|
|
|
sortedKeys = {k: c[k] for k in order if k in c} # Sort dict keys according to order
|
|
|
|
sortedKeys["src"] = "irc"
|
|
|
|
sendLogstashNotification(sortedKeys)
|
|
|
|
sendRelayNotification(sortedKeys)
|