fix functions breaking on clients without clid

This commit is contained in:
Lukas Mahler
2021-09-30 08:48:30 +02:00
parent 35c64cea14
commit 55776e31cd
3 changed files with 110 additions and 65 deletions
+3
View File
@@ -7,6 +7,9 @@ sid = 1
user = "exampleuser"
pwd = "password"
[Allowed]
sgids = ["1"]
[Misc]
nickname = "myTS3-Bot"
whitelisted = false
+27 -8
View File
@@ -4,7 +4,7 @@ TBD
__author__ = "Lukas Mahler"
__version__ = "0.0.0"
__date__ = "27.09.2021"
__date__ = "30.09.2021"
__email__ = "m@hler.eu"
__status__ = "Development"
@@ -14,6 +14,8 @@ import sys
import shutil
import os.path
import logging
import time
from datetime import timedelta
from logging.handlers import RotatingFileHandler
# Custom
@@ -32,18 +34,18 @@ def unhandledException(exc_type, exc_value, exc_traceback):
log.critical("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
def getconf(fname):
def getConf(fname):
"""
"""
if fname.endswith(".toml"):
if os.path.isfile(fname):
try:
data = toml.load(fname)
return data
config = toml.load(fname)
checkConf(config)
return config
except ValueError as e:
log.critical(e)
# log.critical("The provided '.toml' seems to be invalid.")
log.critical(f"The provided '.toml' is probably invalid, returned error:\n{e}")
exit(1)
else:
log.critical(f"Couldn't locate the '.toml' file [{fname}].")
@@ -51,12 +53,29 @@ def getconf(fname):
shutil.copy("src/template.toml", fname)
exit(1)
else:
log.critical("The provided config file is not a '.toml' file.")
log.critical(f"The provided config file [{fname}] is not a '.toml' file.")
log.info("Creating a new '.toml' file from template, please edit and restart.")
shutil.copy("src/template.toml", "prod.toml")
exit(1)
def getRuntime(started):
"""
"""
elapsed = time.time() - started
runtime = str(timedelta(seconds=elapsed))
return runtime
def checkConf(config):
"""
TODO check if keys exist
"""
pass
def setupLogger(logpath, lvl="DEBUG"):
"""
Create a rotating log in a log folder
@@ -66,7 +85,7 @@ def setupLogger(logpath, lvl="DEBUG"):
log = logging.getLogger()
if not os.path.exists(logpath):
os.makedirs(logpath)
handler = RotatingFileHandler(logpath + r"/myTS3.log", encoding='utf-8', maxBytes=5*1024*1024, backupCount=10)
handler = RotatingFileHandler(logpath + r"/myTS3.log", encoding='utf-8', maxBytes=1*1024*1024, backupCount=10)
logformat = logging.Formatter("%(asctime)s %(levelname)8s %(message)s", "%Y-%m-%d %H:%M:%S")
handler.setFormatter(logformat)
log.addHandler(handler)