Discord-Raid-bot/cogs/mercy.py

117 lines
5.4 KiB
Python
Raw Normal View History

2025-08-26 17:35:54 +00:00
# -*- coding: utf-8 -*-
2025-08-23 09:23:47 +00:00
import discord
from discord.ext import commands
from config import AUTHORIZED_CHANNEL_ID
2025-08-25 16:09:37 +00:00
from utils.MercyManager_class import MercyManager
2025-08-25 16:21:50 +00:00
from utils.helpers import calc_chance_and_guarantee
2025-08-23 09:23:47 +00:00
2025-08-25 16:09:37 +00:00
VALID_SHARDS = ["ancient", "void", "sacred", "primal", "remnant"]
2025-08-23 09:23:47 +00:00
class Mercy(commands.Cog):
"""Cog for managing Mercy pulls"""
2025-08-26 17:35:54 +00:00
2025-08-23 09:23:47 +00:00
def __init__(self, bot):
self.bot = bot
2025-08-25 16:09:37 +00:00
self.mercy_manager = MercyManager()
2025-08-23 09:23:47 +00:00
@commands.command(name="mercy")
async def mercy(self, ctx, action: str = None, arg1: str = None, arg2: str = None):
if ctx.channel.id != AUTHORIZED_CHANNEL_ID:
return
user_id = str(ctx.author.id)
2025-08-26 17:35:54 +00:00
# ----- SHOW -----
2025-08-23 09:23:47 +00:00
if action == "show":
2025-08-25 16:09:37 +00:00
pulls_dict = self.mercy_manager.get_all_pulls(user_id)
if not pulls_dict:
2025-08-26 17:35:54 +00:00
await ctx.send(" You don't have any mercy data yet.")
2025-08-23 09:23:47 +00:00
return
2025-08-26 17:35:54 +00:00
embed = discord.Embed(
title=f"🎲 Mercy Status for {ctx.author.display_name}",
color=0x00bfff
)
2025-08-25 16:09:37 +00:00
for shard_type, pulls in pulls_dict.items():
if shard_type == "primal":
for sub_type in ["primal_legendary", "primal_mythical"]:
2025-08-26 17:35:54 +00:00
sub_pulls = pulls_dict.get(sub_type, 0)
chance, guaranteed_at, remaining = calc_chance_and_guarantee(sub_type, sub_pulls)
guaranteed_text = f" (Guaranteed at {guaranteed_at} pulls, {remaining} remaining)" if guaranteed_at else ""
2025-08-25 16:09:37 +00:00
embed.add_field(
name=sub_type.replace("_", " ").title(),
2025-08-26 17:35:54 +00:00
value=f"Pulled: **{sub_pulls}/{guaranteed_at} shards** → {chance:.1f}% chance{guaranteed_text}",
2025-08-25 16:09:37 +00:00
inline=False
)
else:
2025-08-26 17:35:54 +00:00
chance, guaranteed_at, remaining = calc_chance_and_guarantee(shard_type, pulls)
guaranteed_text = f" (Guaranteed at {guaranteed_at} pulls, {remaining} remaining)" if guaranteed_at else ""
2025-08-25 16:09:37 +00:00
embed.add_field(
name=shard_type.replace("_", " ").title(),
2025-08-26 17:35:54 +00:00
value=f"Pulled: **{pulls}/{guaranteed_at} shards** → {chance:.1f}% chance{guaranteed_text}",
2025-08-25 16:09:37 +00:00
inline=False
)
2025-08-23 09:23:47 +00:00
await ctx.send(embed=embed)
2025-08-26 17:35:54 +00:00
# ----- ADD -----
2025-08-23 09:23:47 +00:00
elif action == "add" and arg1 and arg2:
try:
2025-08-25 16:09:37 +00:00
pulls_to_add = int(arg1)
2025-08-23 09:23:47 +00:00
except ValueError:
2025-08-26 17:35:54 +00:00
await ctx.send("❌ Number of pulls must be an integer.")
2025-08-23 09:23:47 +00:00
return
shard_type = arg2.lower()
2025-08-25 16:09:37 +00:00
if shard_type not in VALID_SHARDS:
2025-08-26 17:35:54 +00:00
await ctx.send(f"❌ Invalid shard type. Available: {', '.join(VALID_SHARDS)}")
2025-08-23 09:23:47 +00:00
return
2025-08-26 17:35:54 +00:00
if shard_type == "primal":
messages = []
for sub_type in ["primal_legendary", "primal_mythical"]:
new_pulls = self.mercy_manager.add_pulls(user_id, sub_type, pulls_to_add)
chance, guaranteed_at, remaining = calc_chance_and_guarantee(sub_type, new_pulls)
messages.append(f"✅ Added {pulls_to_add} pulls to **{sub_type.replace('_', ' ').title()}**: {new_pulls}/{guaranteed_at}{chance:.1f}% ({remaining} remaining)")
await ctx.send("\n".join(messages))
else:
new_pulls = self.mercy_manager.add_pulls(user_id, shard_type, pulls_to_add)
chance, guaranteed_at, remaining = calc_chance_and_guarantee(shard_type, new_pulls)
await ctx.send(f"✅ Added {pulls_to_add} pulls to **{shard_type}** mercy. Now: **{new_pulls}/{guaranteed_at}** pulls → {chance:.1f}% chance ({remaining} remaining)")
2025-08-25 16:09:37 +00:00
2025-08-26 17:35:54 +00:00
# ----- RESET -----
2025-08-23 09:23:47 +00:00
elif action == "reset" and arg1:
shard_type = arg1.lower()
2025-08-26 17:35:54 +00:00
sub_type = arg2.lower() if arg2 else None
2025-08-23 09:23:47 +00:00
2025-08-26 17:35:54 +00:00
if shard_type == "primal":
if sub_type == "legendary":
self.mercy_manager.reset_pulls(user_id, "primal_legendary")
await ctx.send("🧾 Mercy for Primal Legendary has been reset.")
elif sub_type == "mythical":
self.mercy_manager.reset_pulls(user_id, "primal_mythical")
await ctx.send("🧾 Mercy for Primal Mythical has been reset.")
elif sub_type is None:
messages = []
for s in ["primal_legendary", "primal_mythical"]:
self.mercy_manager.reset_pulls(user_id, s)
messages.append(f"🧾 Mercy for {s.replace('_', ' ').title()} has been reset.")
await ctx.send("\n".join(messages))
else:
await ctx.send("❌ Invalid primal subtype. Use `legendary` or `mythical`.")
else:
if shard_type not in VALID_SHARDS:
await ctx.send(f"❌ Invalid shard type. Available: {', '.join(VALID_SHARDS)}")
return
self.mercy_manager.reset_pulls(user_id, shard_type)
await ctx.send(f"🧾 Mercy for **{shard_type}** has been reset.")
2025-08-23 09:23:47 +00:00
2025-08-26 17:35:54 +00:00
# ----- HELP -----
2025-08-23 09:23:47 +00:00
else:
2025-08-26 17:35:54 +00:00
await ctx.send(" Usage: `!mercy add <nb> <type>`, `!mercy reset <type> [subtype]`, `!mercy show`")
2025-08-23 09:23:47 +00:00
2025-08-25 16:09:37 +00:00
async def setup(bot):
await bot.add_cog(Mercy(bot))