From af97b2e569ed6e735dd1e2450e7f8b2245d35fcb Mon Sep 17 00:00:00 2001 From: Kozejin <2613841+dkoz@users.noreply.github.com> Date: Thu, 26 Sep 2024 01:22:45 -0400 Subject: [PATCH] Paldex, Setup Update --- cogs/palgame/battle.py | 11 ++++++- cogs/palgame/game.py | 12 +++++++- cogs/palgame/paldex.py | 65 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 cogs/palgame/paldex.py diff --git a/cogs/palgame/battle.py b/cogs/palgame/battle.py index 21d879b..61398d0 100644 --- a/cogs/palgame/battle.py +++ b/cogs/palgame/battle.py @@ -145,4 +145,13 @@ async def on_autocomplete_pal(self, interaction: nextcord.Interaction, current: await self.pal_autocomplete(interaction, current) def setup(bot): - bot.add_cog(BattleCog(bot)) + cog = BattleCog(bot) + bot.add_cog(cog) + + if not hasattr(bot, "all_slash_commands"): + bot.all_slash_commands = [] + bot.all_slash_commands.extend( + [ + cog.battle, + ] + ) diff --git a/cogs/palgame/game.py b/cogs/palgame/game.py index 9058453..9253c59 100644 --- a/cogs/palgame/game.py +++ b/cogs/palgame/game.py @@ -124,4 +124,14 @@ async def mypals(self, interaction: Interaction): await interaction.response.send_message(embed=embed) def setup(bot): - bot.add_cog(PalGameCog(bot)) + cog = PalGameCog(bot) + bot.add_cog(cog) + + if not hasattr(bot, "all_slash_commands"): + bot.all_slash_commands = [] + bot.all_slash_commands.extend( + [ + cog.catch, + cog.mypals, + ] + ) diff --git a/cogs/palgame/paldex.py b/cogs/palgame/paldex.py new file mode 100644 index 0000000..ba48b65 --- /dev/null +++ b/cogs/palgame/paldex.py @@ -0,0 +1,65 @@ +import json +import os +import nextcord +from nextcord.ext import commands + +class PaldexCog(commands.Cog): + def __init__(self, bot): + self.bot = bot + self.load_game_data() + + def load_game_data(self): + game_data_path = os.path.join("gamedata", "game.json") + with open(game_data_path, "r", encoding="utf-8") as game_data_file: + self.game_data = json.load(game_data_file) + + async def autocomplete_pal(self, interaction: nextcord.Interaction, current: str): + choices = [ + pal["Name"] for pal in self.game_data if current.lower() in pal["Name"].lower() + ][:10] + await interaction.response.send_autocomplete(choices) + + @nextcord.slash_command(description="Search for a Pal in the Paldex") + async def paldex( + self, + interaction: nextcord.Interaction, + name: str = nextcord.SlashOption( + description="The name of the Pal.", autocomplete=True), + ): + await interaction.response.defer() + + # Do not edit this if you don't know what you are doing... + pal = next((pal for pal in self.game_data if pal["Name"] == name), None) + if pal: + embed = nextcord.Embed( + title=pal['Name'], color=nextcord.Color.blue()) + embed.description = pal["Description"] + embed.set_thumbnail(url=pal["WikiImage"]) + stats = pal['Stats'] + embed.add_field(name="Stats", value=f"HP: {stats['HP']}\nDefense: {stats['Defense']}\nStamina: {stats['Stamina']}", inline=True) + embed.add_field(name="Attack", value=f"Melee: {stats['Attack']['Melee']}\nRanged: {stats['Attack']['Ranged']}", inline=True) + embed.add_field(name="Rarity", value=pal["Rarity"], inline=True) + + skills = "\n".join([f"**{skill['Name']}**: {skill['Description']}" for skill in pal["Skills"]]) + embed.add_field(name="Skills", value=skills, inline=False) + + await interaction.followup.send(embed=embed) + else: + await interaction.followup.send("Pal not found.") + + @paldex.on_autocomplete("name") + async def autocomplete_pal_name( + self, interaction: nextcord.Interaction, current: str + ): + await self.autocomplete_pal(interaction, current) + +def setup(bot): + cog = PaldexCog(bot) + bot.add_cog(cog) + if not hasattr(bot, "all_slash_commands"): + bot.all_slash_commands = [] + bot.all_slash_commands.extend( + [ + cog.paldex, + ] + )