Reformat project

This commit is contained in:
2022-07-21 13:39:59 +01:00
parent 4669096fcb
commit da678617d8
57 changed files with 523 additions and 218 deletions

View File

@@ -1,8 +1,10 @@
import main
import sys
from twisted.internet import reactor
import main
from utils.logging.debug import debug
from utils.logging.log import *
import sys
def handler(sig, frame):

View File

@@ -1,7 +1,9 @@
from datetime import datetime
from csiphash import siphash24
from copy import deepcopy
from datetime import datetime
from json import dumps
from csiphash import siphash24
import main
from utils.logging.debug import debug
@@ -10,16 +12,24 @@ def dedup(numName, b):
c = deepcopy(b)
if "ts" in c.keys():
del c["ts"]
c["approxtime"] = str(datetime.utcnow().timestamp())[: main.config["Tweaks"]["DedupPrecision"]]
c["approxtime"] = str(datetime.utcnow().timestamp())[
: main.config["Tweaks"]["DedupPrecision"]
]
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)
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"]]
main.lastEvents[numName] = main.lastEvents[numName][
0 : main.config["Tweaks"]["MaxHash"]
]
else:
main.lastEvents[numName] = [castHash]
return False

View File

@@ -1,10 +1,9 @@
from os import listdir
import commands
from main import CommandMap
from utils.logging.debug import debug
from utils.logging.log import *
import commands
from main import CommandMap
def loadCommands(allowDup=False):
@@ -15,11 +14,15 @@ def loadCommands(allowDup=False):
try:
module = __import__("commands.%s" % commandName)
if not commandName in CommandMap:
CommandMap[commandName] = getattr(getattr(module, commandName), className)
CommandMap[commandName] = getattr(
getattr(module, commandName), className
)
debug("Registered command: %s" % commandName)
else:
if allowDup:
CommandMap[commandName] = getattr(getattr(module, commandName), className)
CommandMap[commandName] = getattr(
getattr(module, commandName), className
)
debug("Registered command: %s" % commandName)
error("Duplicate command: %s" % (commandName))

View File

@@ -1,12 +1,11 @@
from os import listdir
from importlib import reload
import sys
from importlib import reload
from os import listdir
import commands
from main import CommandMap
from utils.logging.debug import debug
from utils.logging.log import *
import commands
from main import CommandMap
def loadSingle(commandName):
@@ -15,7 +14,9 @@ def loadSingle(commandName):
try:
if commandName in CommandMap.keys():
reload(sys.modules["commands." + commandName])
CommandMap[commandName] = getattr(sys.modules["commands." + commandName], className)
CommandMap[commandName] = getattr(
sys.modules["commands." + commandName], className
)
debug("Reloaded command: %s" % commandName)
return "RELOAD"
module = __import__("commands.%s" % commandName)

View File

@@ -1,5 +1,6 @@
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):