clean up main.py and

facilitate the calling of member destructors so cleanup actually works!
i hate python's gc this is actual trash when i delete an object the
destructor isn't called this is insane if you're not writing "pythonic" codethe secret police comes in the night and takes your right to function away
master
BuildTools 3 years ago
parent 77464883b1
commit 9dc14f69b7
  1. 8
      client.py
  2. 9
      main.py

@ -5,12 +5,14 @@ from grim_logger import glog, glog_level
from plugin_manager import plugin_manager from plugin_manager import plugin_manager
class client(): class client():
def __init__(self, config_path = "config.json"): def __init__(self, config_path = None):
self.logger = glog(level = glog_level.TRACE) self.logger = glog(level = glog_level.TRACE)
self.ws = None self.ws = None
self.last_sequence = None self.last_sequence = None
self.session_id = None self.session_id = None
self.user = None self.user = None
if not config_path: # this really really really simplifies things even if it is technically messier than a default param itself
config_path = "config.json"
self.logger.write(f"loading config from {config_path}") self.logger.write(f"loading config from {config_path}")
with open(config_path, "r") as conf_fd: with open(config_path, "r") as conf_fd:
self.config = json.loads(conf_fd.read()) self.config = json.loads(conf_fd.read())
@ -58,3 +60,7 @@ class client():
headers = {"Authorization": "Bot {0}".format(self.config["token"]), "User-Agent": "mbdf (cynic.moe, v1)", "Content-Type": "application/json"} headers = {"Authorization": "Bot {0}".format(self.config["token"]), "User-Agent": "mbdf (cynic.moe, v1)", "Content-Type": "application/json"}
res = requests.post(endpoint, headers = headers, data = json.dumps({"content": message})) res = requests.post(endpoint, headers = headers, data = json.dumps({"content": message}))
self.logger.write(headers) self.logger.write(headers)
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
pass # this should destruct all members probably maybe

@ -1,9 +1,6 @@
from client import client from client import client
from sys import argv, exit from sys import argv, exit
olive = None path = None
if len(argv) < 2: with client(config_path = None if (len(argv) < 2) else argv[1]) as c:
olive = client() # is this clean? who knows! c.run()
else:
olive = client(config_path = argv[1])
olive.run()

Loading…
Cancel
Save