diff --git a/.gitignore b/.gitignore index 16243cc..3ce9b2f 100644 --- a/.gitignore +++ b/.gitignore @@ -342,6 +342,7 @@ healthchecksdb # Personal config file, contains bot token config.json games_config.json +weather_config.json ids # database diff --git a/games.py b/games.py index 055d588..6533d24 100644 --- a/games.py +++ b/games.py @@ -23,6 +23,25 @@ def config(): with open("games_config.json") as config_file: return json.load(config_file) +def all_weathers(): + if not os.path.exists("weather_config.json"): + #generate default config + super_weather_json = jsonpickle.encode(weather("Supernova", "🌟")) + mid_weather_json = jsonpickle.encode(weather("Midnight", "🕶")) + config_dic = { + "Supernova" : super_weather_json, + "Midnight": mid_weather_json + } + with open("weather_config.json", "w") as config_file: + json.dump(config_dic, config_file, indent=4) + with open("weather_config.json") as config_file: + weather_dic = {} + for weather_json in json.load(config_file).values(): + this_weather = jsonpickle.decode(weather_json, classes=weather) + weather_dic[this_weather.name] = this_weather + return weather_dic + + class appearance_outcomes(Enum): strikeoutlooking = "strikes out looking." strikeoutswinging = "strikes out swinging." diff --git a/the_prestige.py b/the_prestige.py index cd892b8..d577b11 100644 --- a/the_prestige.py +++ b/the_prestige.py @@ -501,8 +501,8 @@ async def watch_game(channel, newgame, user = None): top_of_inning = True victory_lap = False - weathers = [games.weather("Supernova", "🌟"), games.weather("Midnight", "🕶")] - newgame.weather = random.choice(weathers) + weathers = games.all_weathers() + newgame.weather = weathers[random.choice(list(weathers.keys()))] while not newgame.over or newgame.top_of_inning != top_of_inning: state = newgame.gamestate_display_full()