Reformat code with pre-commit

This commit is contained in:
2022-07-21 13:39:41 +01:00
parent 0777a55264
commit ff1ee63900
60 changed files with 547 additions and 278 deletions

28
main.py
View File

@@ -7,10 +7,7 @@ from os import urandom
from utils.logging.log import *
# List of errors ZNC can give us
ZNCErrors = ["Error:",
"Unable to load",
"does not exist",
"doesn't exist"]
ZNCErrors = ["Error:", "Unable to load", "does not exist", "doesn't exist"]
configPath = "conf/"
certPath = "cert/"
@@ -25,9 +22,8 @@ filemap = {
"alias": ["alias.json", "provisioned alias data", "json"],
"irc": ["irc.json", "IRC network definitions", "json"],
"blacklist": ["blacklist.json", "IRC channel blacklist", "json"],
# Binary (pickle) configs
"network": ["network.dat", "network list", "pickle"]
"network": ["network.dat", "network list", "pickle"],
}
# Connections to the plain-text interface
@@ -70,43 +66,45 @@ def liveNets():
networks.add("".join([x for x in i if not x in digits]))
return networks
def saveConf(var):
if filemap[var][2] == "json":
with open(configPath+filemap[var][0], "w") as f:
with open(configPath + filemap[var][0], "w") as f:
json.dump(globals()[var], f, indent=4)
elif filemap[var][2] == "pickle":
with open(configPath+filemap[var][0], "wb") as f:
with open(configPath + filemap[var][0], "wb") as f:
pickle.dump(globals()[var], f)
else:
raise Exception("invalid format")
def loadConf(var):
if filemap[var][2] == "json":
with open(configPath+filemap[var][0], "r") as f:
with open(configPath + filemap[var][0], "r") as f:
globals()[var] = json.load(f)
if var == "alias":
# This is a workaround to convert all the keys into integers since JSON
# turns them into strings...
# Dammit Jason!
global alias
alias = {int(x):y for x, y in alias.items()}
alias = {int(x): y for x, y in alias.items()}
elif filemap[var][2] == "pickle":
try:
with open(configPath+filemap[var][0], "rb") as f:
with open(configPath + filemap[var][0], "rb") as f:
globals()[var] = pickle.load(f)
except FileNotFoundError:
globals()[var] = {}
else:
raise Exception("invalid format")
def initConf():
for i in filemap.keys():
loadConf(i)
def initMain():
global r, g
initConf()
r = StrictRedis(unix_socket_path=config["RedisSocket"], db=0) # Ephemeral - flushed on quit
g = StrictRedis(unix_socket_path=config["RedisSocket"], db=1) # Persistent
r = StrictRedis(unix_socket_path=config["RedisSocket"], db=0) # Ephemeral - flushed on quit
g = StrictRedis(unix_socket_path=config["RedisSocket"], db=1) # Persistent