2022-07-21 12:40:01 +00:00
|
|
|
from copy import deepcopy
|
2022-07-21 12:40:09 +00:00
|
|
|
from datetime import datetime
|
2022-07-21 12:40:01 +00:00
|
|
|
from json import dumps
|
2022-07-21 12:40:09 +00:00
|
|
|
|
2019-08-15 20:20:49 +00:00
|
|
|
import main
|
2022-09-05 06:20:30 +00:00
|
|
|
from siphashc import siphash
|
2019-08-15 20:20:49 +00:00
|
|
|
from utils.logging.debug import debug
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2020-06-02 20:34:15 +00:00
|
|
|
def dedup(numName, b):
|
|
|
|
c = deepcopy(b)
|
2022-07-21 12:39:54 +00:00
|
|
|
if "ts" in c.keys():
|
|
|
|
del c["ts"]
|
2022-09-05 06:20:30 +00:00
|
|
|
c["approxtime"] = str(datetime.utcnow().timestamp())[
|
|
|
|
: main.config["Tweaks"]["DedupPrecision"]
|
|
|
|
]
|
2022-08-18 06:20:30 +00:00
|
|
|
castHash = siphash(main.hashKey, dumps(c, sort_keys=True))
|
2019-08-15 20:20:49 +00:00
|
|
|
del c["approxtime"]
|
2022-09-05 06:20:30 +00:00
|
|
|
isDuplicate = any(
|
|
|
|
castHash in main.lastEvents[x]
|
|
|
|
for x in main.lastEvents.keys()
|
|
|
|
if not x == numName
|
|
|
|
)
|
2019-08-15 20:20:49 +00:00
|
|
|
if isDuplicate:
|
|
|
|
debug("Duplicate: %s" % (c))
|
|
|
|
return True
|
|
|
|
if numName in main.lastEvents.keys():
|
|
|
|
main.lastEvents[numName].insert(0, castHash)
|
2022-09-05 06:20:30 +00:00
|
|
|
main.lastEvents[numName] = main.lastEvents[numName][
|
|
|
|
0 : main.config["Tweaks"]["MaxHash"]
|
|
|
|
] # noqa
|
2019-08-15 20:20:49 +00:00
|
|
|
else:
|
|
|
|
main.lastEvents[numName] = [castHash]
|
|
|
|
return False
|