diff --git a/bot.py b/bot.py index beab2e4..0ed54e1 100644 --- a/bot.py +++ b/bot.py @@ -19,12 +19,8 @@ def get_status(): status["timestamp"] = parse_time(status['timestamp']) return status -def get_status_text(src=get_status): - if get_status()["doorstate"]: - text = "fs WIAI is open :)" - else: - text = "fs WIAI is closed :(" - return text +def get_status_text(config, src=get_status): + return config["texts"][str(get_status()["doorstate"])] def post(chats, text, token): url = "https://api.telegram.org/bot{token}/sendMessage".format(token=token) @@ -35,7 +31,7 @@ def post(chats, text, token): def main(args={"config": "settings.json"}): log.info("run once") config = json.load(open(args['config'])) - text = get_status_text() + text = get_status_text(config) post(config['groups'], text, config['token']) post_plot(config) @@ -62,7 +58,7 @@ def do_loop(config): changed = True if changed: last_state = new_state - text = get_status_text(lambda: last_state) + text = get_status_text(config, lambda: last_state) post(config["groups"], text, config["token"]) log.info("run pending tasks") schedule.run_pending() diff --git a/settings.sample.json b/settings.sample.json index d57280e..beed094 100644 --- a/settings.sample.json +++ b/settings.sample.json @@ -9,5 +9,10 @@ "WIAIdoorTest": -234502, "name": -1333, "fswiai main": -1001 + }, + "texts":{ + "-1": "fs WIAI is undefined ¯\_(ツ)_/¯", + "0": "fs WIAI is closed :(", + "1": "fs WIAI is open :)" } }