Update files

This commit is contained in:
Astra 2026-06-30 15:53:08 +01:00
parent 73d8dd543f
commit a775afc177
5 changed files with 200 additions and 73 deletions

View file

@ -1,12 +1,9 @@
#!/usr/bin/env python3
import logging
import yaml
import threading
import sys
import os
import shelve
import getopt
from pickle import Unpickler
import yaml
from . import bot
@ -25,22 +22,13 @@ def usage():
print(" -q Quiet, set log level to WARNING")
print(" -c Location of config file (default: ./config.yaml)")
# well this is just dumb
class RenamingUnpickler(Unpickler):
def find_class(self, module, name):
if module in ("src.core", "supportbot.__main__", "__main__"):
module = "supportbot.bot"
return super().find_class(module, name)
def main(configpath, loglevel=logging.INFO):
with open(configpath, "r") as f:
config = yaml.safe_load(f)
logging.basicConfig(format="%(levelname)-7s [%(asctime)s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S", level=loglevel)
shelve.Unpickler = RenamingUnpickler
db = shelve.open(config["database"])
db = bot.JsonDb(config["database"])
bot.init(config, db)
try:
@ -48,8 +36,6 @@ def main(configpath, loglevel=logging.INFO):
start_new_thread(bot.run, join=True)
except KeyboardInterrupt:
logging.info("Interrupted, exiting")
db.close()
os._exit(1)
if __name__ == "__main__":
try:
@ -58,7 +44,6 @@ if __name__ == "__main__":
print(str(e))
exit(1)
# Process command line args
def readopt(name):
for e in opts:
if e[0] == name:
@ -73,5 +58,4 @@ if __name__ == "__main__":
if readopt("-c") is not None:
configpath = readopt("-c")
# Run the actual program
main(configpath, loglevel)