added folder setup to pokemon extension

This commit is contained in:
phixxy 2024-01-20 18:16:20 -08:00
parent 2b0ec090c4
commit f19e996560
2 changed files with 14 additions and 8 deletions

View file

@ -6,9 +6,8 @@ import os
import json import json
import math import math
import time import time
import aiohttp
class Pokemon(commands.Cog): class PokemonGame(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@ -16,9 +15,17 @@ class Pokemon(commands.Cog):
self.data_dir = "data/pokemon/" self.data_dir = "data/pokemon/"
self.folder_setup() self.folder_setup()
def folder_setup(self):
try:
if not os.path.exists(self.working_dir):
os.mkdir(self.working_dir)
if not os.path.exists(self.data_dir):
os.mkdir(self.data_dir)
except:
print("PokemonGame failed to make directories")
async def get_json(self, url): async def get_json(self, url):
http_session = aiohttp.ClientSession() async with self.bot.http_session.get(url) as resp:
async with http_session.get(url) as resp:
json_data = await resp.json() json_data = await resp.json()
return json_data return json_data
@ -275,4 +282,4 @@ class Pokemon(commands.Cog):
await ctx.channel.send(message) await ctx.channel.send(message)
async def setup(bot): async def setup(bot):
bot.add_cog(Pokemon) await bot.add_cog(PokemonGame(bot))

View file

@ -30,11 +30,10 @@ ftp_public_html = os.getenv('ftp_public_html')
#discord setup START #discord setup START
intents = discord.Intents.default() intents = discord.Intents.default()
intents.message_content = True intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents) bot = commands.Bot(command_prefix='?', intents=intents)
#discord setup END #discord setup END
async def handle_error(error): async def handle_error(error):
print(error) print(error)
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
@ -243,7 +242,7 @@ async def on_message(ctx):
await react_to_msg(ctx, channel_vars["react_to_msgs"]) #emoji reactions await react_to_msg(ctx, channel_vars["react_to_msgs"]) #emoji reactions
if channel_vars["commands_enabled"] or (ctx.author.id == 242018983241318410 and ctx.content[0] == "!"): if channel_vars["commands_enabled"] or (ctx.author.id == 242018983241318410 and ctx.content[0] == "?"):
await bot.process_commands(ctx) await bot.process_commands(ctx)
if not channel_vars["commands_enabled"]: if not channel_vars["commands_enabled"]:
await ctx.channel.send("This command only ran because you set it to allow to run even when commands are disabled") await ctx.channel.send("This command only ran because you set it to allow to run even when commands are disabled")