Reformat legacy project

This commit is contained in:
2022-09-05 07:20:30 +01:00
parent 6b082adeb2
commit 8b9ad05089
59 changed files with 538 additions and 198 deletions

View File

@@ -1,6 +1,5 @@
from twisted.internet import reactor
import main
from twisted.internet import reactor
from utils.logging.debug import debug
from utils.logging.log import log

View File

@@ -2,9 +2,8 @@ from copy import deepcopy
from datetime import datetime
from json import dumps
from siphashc import siphash
import main
from siphashc import siphash
from utils.logging.debug import debug
@@ -12,16 +11,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 = siphash(main.hashKey, dumps(c, sort_keys=True))
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"]] # noqa
main.lastEvents[numName] = main.lastEvents[numName][
0 : main.config["Tweaks"]["MaxHash"]
] # noqa
else:
main.lastEvents[numName] = [castHash]
return False

View File

@@ -1,13 +1,12 @@
from datetime import datetime
from twisted.internet import reactor
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.internet.ssl import DefaultOpenSSLContextFactory
from twisted.words.protocols.irc import IRCClient
import main
from core.relay import sendRelayNotification
from modules import userinfo
from twisted.internet import reactor
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.internet.ssl import DefaultOpenSSLContextFactory
from twisted.words.protocols.irc import IRCClient
from utils.get import getRelay
from utils.logging.log import error, log
from utils.logging.send import sendAll
@@ -157,7 +156,11 @@ class IRCRelayFactory(ReconnectingClientFactory):
def deliverRelayCommands(num, relayCommands, user=None, stage2=None):
keyFN = main.certPath + main.config["Key"]
certFN = main.certPath + main.config["Certificate"]
contextFactory = DefaultOpenSSLContextFactory(keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace"))
bot = IRCRelayFactory(net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2)
contextFactory = DefaultOpenSSLContextFactory(
keyFN.encode("utf-8", "replace"), certFN.encode("utf-8", "replace")
)
bot = IRCRelayFactory(
net=None, num=num, relayCommands=relayCommands, user=user, stage2=stage2
)
host, port = getRelay(num)
reactor.connectSSL(host, port, bot, contextFactory)

View File

@@ -13,11 +13,15 @@ def loadCommands(allowDup=False):
# try:
module = __import__("commands.%s" % commandName)
if commandName not 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

@@ -12,7 +12,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)