import discord from discord import app_commands from discord.ext import commands import db from game.achievements import ACHIEVEMENTS class Profile(commands.Cog): @app_commands.command(name="查看", description="查看個人資訊") @app_commands.describe(類型="選擇查看資訊") @app_commands.choices(類型=[ app_commands.Choice(name="簽到次數", value="signin_count"), app_commands.Choice(name="代幣個數", value="coin_count"), app_commands.Choice(name="上次簽到", value="last_signin"), app_commands.Choice(name="經驗值", value="exp_count"), app_commands.Choice(name="成就", value="achievements"), ]) async def view(self, interaction: discord.Interaction, 類型: app_commands.Choice[str]): user = interaction.user row = db.get_user(user.id) if row is None or row["total_signin"] == 0: await interaction.response.send_message(f"# {user.mention} 沒有簽到過!!\n請先簽到") return match 類型.value: case "signin_count": msg = f"{user.mention} 簽到了 {row['total_signin']} 次" case "coin_count": msg = f"{user.mention} 擁有 {row['coin']} 枚代幣" case "exp_count": msg = f"{user.mention} 有 {row['exp']} 經驗值" case "last_signin": msg = f"{user.mention} 上次簽到日期為 {row['last_signin']}" case "achievements": got = db.get_achievements(user.id) lines = [f"🏆 **{name}** — {cond}" for k, (name, cond, _) in ACHIEVEMENTS.items() if k in got] msg = f"{user.mention} 已解鎖成就 {len(got)}/{len(ACHIEVEMENTS)}\n" + "\n".join(lines) await interaction.response.send_message(msg) async def setup(bot: commands.Bot): await bot.add_cog(Profile())