def load_config(guild): from Bot.TheRealGearBot import handle_exception global SERVER_CONFIGS try: config = Utils.fetch_from_disk(f'config/{guild}') except JSONDecodeError as e: GearbotLogging.error(f"Failed to deserialize config! {e}") asyncio.create_task(handle_exception("loading config", BOT, e)) config = Utils.fetch_from_disk("template") if len(config.keys()) != 0 and "VERSION" not in config and len( config) < 15: GearbotLogging.info( f"The config for {guild} is to old to migrate, resetting") config = dict() elif len(config.keys()) != 0: if "VERSION" not in config: config["VERSION"] = 0 SERVER_CONFIGS[guild] = update_config(guild, config) if len(config.keys()) == 0: GearbotLogging.info( f"No config available for {guild}, creating a blank one.") SERVER_CONFIGS[guild] = Utils.fetch_from_disk("template") save(guild) validate_config(guild) Features.check_server(guild)
def save(id): global SERVER_CONFIGS with open(f'config/{id}.json', 'w') as jsonfile: jsonfile.write((json.dumps(SERVER_CONFIGS[id], indent=4, skipkeys=True, sort_keys=True))) Features.check_server(id)
def load_config(guild): global SERVER_CONFIGS config = Utils.fetch_from_disk(f'config/{guild}') if "VERSION" not in config and len(config) < 15: GearbotLogging.info(f"The config for {guild} is to old to migrate, resetting") config = dict() else: if "VERSION" not in config: config["VERSION"] = 0 SERVER_CONFIGS[guild] = update_config(guild, config) if len(config) is 0: GearbotLogging.info(f"No config available for {guild}, creating a blank one.") SERVER_CONFIGS[guild] = Utils.fetch_from_disk("config/template") save(guild) Features.check_server(guild)
def set_cat(id, cat, value): SERVER_CONFIGS[id][cat] = value save(id) Features.check_server(id)
def set_var(id, cat, key, value): SERVER_CONFIGS[id].get(cat, dict())[key] = value save(id) Features.check_server(id)
def set_var(id, key, value): SERVER_CONFIGS[id][key] = value save(id) Features.check_server(id)