gacha-bot / cogs /progression.py
Amit
Clean Cloud Deployment
732ca45
Raw
History Blame Contribute Delete
4.06 kB
# cogs/progression.py
import discord
from discord import app_commands
from discord.ext import commands
import logging
from services.progression_service import ProgressionService
from utils.code_converter import decode_id
logger = logging.getLogger(__name__)
class ProgressionCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@app_commands.command(name="sufuse", description="Sacrifice a duplicate card to unlock a Constellation node (Max C6)")
@app_commands.describe(
target_code="The alphanumeric code of the card you want to UPGRADE",
sacrifice_code="The alphanumeric code of the duplicate you want to DESTROY"
)
async def fuse(self, interaction: discord.Interaction, target_code: str, sacrifice_code: str):
await interaction.response.defer(thinking=True)
try:
target_id = decode_id(target_code)
sacrifice_id = decode_id(sacrifice_code)
except ValueError:
return await interaction.followup.send("❌ Invalid card code format. Please check your codes.")
try:
char_name, new_constellation = await ProgressionService.fuse_character(
interaction.user.id, target_id, sacrifice_id
)
embed_color = discord.Color.purple() if new_constellation < 6 else discord.Color.gold()
embed = discord.Embed(
title="✨ Constellation Unlocked!",
description=f"You successfully sacrificed `{sacrifice_code}` to empower `{target_code}`.",
color=embed_color
)
if new_constellation == 6:
embed.add_field(name=f"🌟 {char_name} is now AWAKENED!", value="**Constellation 6 Reached.** Maximum power achieved.", inline=False)
else:
embed.add_field(name=char_name, value=f"⭐ Constellation {new_constellation} Unlocked!", inline=False)
await interaction.followup.send(embed=embed)
except ValueError as e:
await interaction.followup.send(f"❌ {str(e)}")
except Exception as e:
logger.error(f"Fusion Error: {e}", exc_info=True)
await interaction.followup.send("❌ An unexpected database error occurred.")
@app_commands.command(name="suascend", description="Spend economy resources to level up a Vanguard character (Max Lvl. 100)")
@app_commands.describe(
card_code="The alphanumeric code of the card you want to level up",
levels="How many levels you want to add (Default is 1)"
)
async def ascend(self, interaction: discord.Interaction, card_code: str, levels: int = 1):
await interaction.response.defer(thinking=True)
try:
instance_id = decode_id(card_code)
except ValueError:
return await interaction.followup.send("❌ Invalid card code format.")
try:
char_name, new_level, cost_coins, cost_dust = await ProgressionService.ascend_character(
interaction.user.id, instance_id, levels
)
dust_str = f" and **{cost_dust:,} Dust**" if cost_dust > 0 else ""
embed = discord.Embed(
title="⬆️ Vanguard Ascended!",
description=f"**{char_name}** (`{card_code}`) has been leveled up!\n\nThey are now **Level {new_level}**.",
color=discord.Color.green()
)
embed.set_footer(text=f"Resources Burned: {cost_coins:,} Coins{dust_str}")
await interaction.followup.send(embed=embed)
except ValueError as e:
await interaction.followup.send(f"❌ {str(e)}")
except Exception as e:
logger.error(f"Ascension Error: {e}", exc_info=True)
await interaction.followup.send("❌ An unexpected database error occurred.")
async def setup(bot):
await bot.add_cog(ProgressionCog(bot))