moved the data to data/

This commit is contained in:
phixxy 2024-01-21 14:12:56 -08:00
parent 0606e8afde
commit 76a84204db

View file

@ -50,20 +50,15 @@ class PokemonGame(commands.Cog):
return not roll return not roll
async def save_pokemon(discord_id, pokemon_dict): async def save_pokemon(discord_id, pokemon_dict):
if not os.path.isdir("databases/pokemon/"): path = self.data_dir+str(discord_id)+".json"
os.makedirs("databases/pokemon/")
path = "databases/pokemon/"+str(discord_id)+".json"
pokemon_dict = json.dumps(pokemon_dict) pokemon_dict = json.dumps(pokemon_dict)
with open(path, 'w') as f: with open(path, 'w') as f:
f.writelines(pokemon_dict) f.writelines(pokemon_dict)
return True return True
async def load_pokemon(discord_id): async def load_pokemon(discord_id):
if not os.path.isdir("databases/pokemon/"): if os.path.isfile(self.data_dir+str(discord_id)+".json"):
os.makedirs("databases/pokemon/") with open(self.data_dir+str(discord_id)+".json", 'r') as f:
if os.path.isfile("databases/pokemon/"+str(discord_id)+".json"):
with open("databases/pokemon/"+str(discord_id)+".json", 'r') as f:
json_data = json.loads(f.readline()) json_data = json.loads(f.readline())
return json_data return json_data
else: else:
@ -141,9 +136,7 @@ class PokemonGame(commands.Cog):
return embed return embed
try: try:
if args[0]=='start': if args[0]=='start':
if not os.path.isdir("databases/pokemon/"): if not os.path.isfile(self.data_dir+str(ctx.author.id)+'.json'):
os.makedirs("databases/pokemon/")
if not os.path.isfile("databases/pokemon/"+str(ctx.author.id)+'.json'):
uniq_id = time.time() uniq_id = time.time()
starter_id = await generate_starter(ctx.author.id) starter_id = await generate_starter(ctx.author.id)
json_data = await get_pkmn_from_id(starter_id) json_data = await get_pkmn_from_id(starter_id)
@ -225,7 +218,7 @@ class PokemonGame(commands.Cog):
return return
async def pkmn_msg(self, discord_id): async def pkmn_msg(self, discord_id):
path = "databases/pokemon/"+str(discord_id)+'.json' path = self.data_dir+str(discord_id)+'.json'
if os.path.isfile(path): if os.path.isfile(path):
with open(path, 'r') as f: with open(path, 'r') as f:
json_data = json.loads(f.readline()) json_data = json.loads(f.readline())