moved weathers to an external config

This commit is contained in:
Sakimori 2020-12-27 17:27:30 -05:00
parent 8ba7a4ff45
commit b76a3fb3c0
3 changed files with 22 additions and 2 deletions

1
.gitignore vendored
View File

@ -342,6 +342,7 @@ healthchecksdb
# Personal config file, contains bot token
config.json
games_config.json
weather_config.json
ids
# database

View File

@ -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."

View File

@ -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()