Improvements to query and self event detection, implement all command and debug flags

This commit is contained in:
2019-08-15 21:20:49 +01:00
parent 1ec0e1f7e6
commit f34ddab6fc
13 changed files with 103 additions and 25 deletions

21
utils/dedup.py Normal file
View File

@@ -0,0 +1,21 @@
from datetime import datetime
from csiphash import siphash24
from json import dumps
import main
from utils.logging.debug import debug
def dedup(numName, c):
# deduplication
c["approxtime"] = int(datetime.utcnow().timestamp())
castHash = siphash24(main.hashKey, dumps(c, sort_keys=True).encode("utf-8"))
del c["approxtime"]
isDuplicate= any(castHash in main.lastEvents[x] for x in main.lastEvents.keys() if not x == numName)
if isDuplicate:
debug("Duplicate: %s" % (c))
return True
if numName in main.lastEvents.keys():
main.lastEvents[numName].insert(0, castHash)
main.lastEvents[numName] = main.lastEvents[numName][0:main.config["Tweaks"]["MaxHash"]]
else:
main.lastEvents[numName] = [castHash]
return False

View File

@@ -1,6 +1,6 @@
from os import listdir
from utils.logging.log import *
from utils.logging.debug import debug
import commands
from main import CommandMap

7
utils/logging/debug.py Normal file
View File

@@ -0,0 +1,7 @@
import main
# we need a seperate module to log.py, as log.py is imported by main.py, and we need to access main
# to read the setting
def debug(data):
if main.config["Debug"]:
print("[DEBUG]", data)

View File

@@ -1,9 +1,6 @@
def log(data):
print("[LOG]", data)
def debug(data):
print("[DEBUG]", data)
def warn(data):
print("[WARNING]", data)