Changes to config handling and retry rates

master
Thor 3 years ago
parent 2277142c45
commit 5e3f2deb75
  1. 20
      bot.py

@ -19,11 +19,11 @@ class BotClient:
def __init__(self, bot, config):
self.bot = bot
self.config = {**{
self.config = {
"base_url": "https://{}".format(config["name"]),
"client_file": "secret/{}.client".format(config["name"]),
"user_file": "secret/{}.user".format(config["name"]),
"state_file": "state/{}.state".format(config["name"])}, **config}
"state_file": "state/{}.state".format(config["name"]), **config}
self.load_state()
@ -90,7 +90,6 @@ class BotClient:
key = lambda status: status["created_at"]):
self.on_status(status)
self.state["min_status_id"] = status["id"]
time.sleep(self.config["rate_limit"])
@ -100,16 +99,14 @@ class BotClient:
except Exception as exc:
self.on_poll_exception(exc)
time.sleep(self.config["rate_limit"])
time.sleep(self.config["retry_rate"])
def load_state(self):
self.state = self.on_load_state()
self.on_state_loaded(self.state)
def save_state(self):
self.on_save_state(self.state)
self.on_state_saved(self.state)
state = self.state.copy()
self.on_save_state(state)
def on_start(self):
pass
@ -136,22 +133,17 @@ class BotClient:
return copy.deepcopy(self.DEFAULT_STATE)
def on_state_loaded(self, state):
pass
def on_save_state(self, state):
with open(self.config["state_file"], "w") as json_file:
json.dump(state, json_file, indent = 4)
def on_state_saved(self, state):
pass
class Bot:
DEFAULT_CONFIG = {
"name": "generic-bot",
"defaults": {
"app_name": "Generic Bot",
"rate_limit": 1,
"retry_rate": 60,
"poll_interval": 10
},
"clients": {

Loading…
Cancel
Save