All checks were successful
Ruff Lint / lint (pull_request) Successful in 12s
- Rename helpers/evolution_notifs.py -> helpers/refractor_notifs.py - Rename tests/test_evolution_notifications.py -> tests/test_refractor_notifs.py - Delete utilities/evolution_notifications.py (replaced by helpers/refractor_notifs.py) - Update TIER_NAMES to canonical names: Base Card, Base Chrome, Refractor, Gold Refractor, Superfractor - Update T4 embed title from "FULLY EVOLVED!" to "SUPERFRACTOR!" - Update FOOTER_TEXT from "Paper Dynasty Evolution" to "Paper Dynasty Refractor" - Update non-max tier embed title from "Evolution Tier Up!" to "Refractor Tier Up!" - Add discord.abc.Messageable type annotation to notify_tier_completion channel param - Update all test assertions to match new tier names and strings Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
109 lines
2.9 KiB
Python
109 lines
2.9 KiB
Python
"""
|
|
Refractor Tier Completion Notifications
|
|
|
|
Builds and sends Discord embeds when a player completes a refractor tier
|
|
during post-game evaluation. Each tier-up event gets its own embed.
|
|
|
|
Notification failures are non-fatal: the send is wrapped in try/except so
|
|
a Discord API hiccup never disrupts game flow.
|
|
"""
|
|
|
|
import logging
|
|
|
|
import discord
|
|
|
|
logger = logging.getLogger("discord_app")
|
|
|
|
# Human-readable display names for each tier number.
|
|
TIER_NAMES = {
|
|
0: "Base Card",
|
|
1: "Base Chrome",
|
|
2: "Refractor",
|
|
3: "Gold Refractor",
|
|
4: "Superfractor",
|
|
}
|
|
|
|
# Tier-specific embed colors.
|
|
TIER_COLORS = {
|
|
1: 0x2ECC71, # green
|
|
2: 0xF1C40F, # gold
|
|
3: 0x9B59B6, # purple
|
|
4: 0x1ABC9C, # teal (superfractor)
|
|
}
|
|
|
|
FOOTER_TEXT = "Paper Dynasty Refractor"
|
|
|
|
|
|
def build_tier_up_embed(tier_up: dict) -> discord.Embed:
|
|
"""Build a Discord embed for a tier-up event.
|
|
|
|
Parameters
|
|
----------
|
|
tier_up:
|
|
Dict with keys: player_name, old_tier, new_tier, current_value, track_name.
|
|
|
|
Returns
|
|
-------
|
|
discord.Embed
|
|
A fully configured embed ready to send to a channel.
|
|
"""
|
|
player_name: str = tier_up["player_name"]
|
|
new_tier: int = tier_up["new_tier"]
|
|
track_name: str = tier_up["track_name"]
|
|
|
|
tier_name = TIER_NAMES.get(new_tier, f"Tier {new_tier}")
|
|
color = TIER_COLORS.get(new_tier, 0x2ECC71)
|
|
|
|
if new_tier >= 4:
|
|
# Superfractor — special title and description.
|
|
embed = discord.Embed(
|
|
title="SUPERFRACTOR!",
|
|
description=(
|
|
f"**{player_name}** has reached maximum refractor tier on the **{track_name}** track"
|
|
),
|
|
color=color,
|
|
)
|
|
embed.add_field(
|
|
name="Rating Boosts",
|
|
value="Rating boosts coming in a future update!",
|
|
inline=False,
|
|
)
|
|
else:
|
|
embed = discord.Embed(
|
|
title="Refractor Tier Up!",
|
|
description=(
|
|
f"**{player_name}** reached **Tier {new_tier} ({tier_name})** on the **{track_name}** track"
|
|
),
|
|
color=color,
|
|
)
|
|
|
|
embed.set_footer(text=FOOTER_TEXT)
|
|
return embed
|
|
|
|
|
|
async def notify_tier_completion(
|
|
channel: discord.abc.Messageable, tier_up: dict
|
|
) -> None:
|
|
"""Send a tier-up notification embed to the given channel.
|
|
|
|
Non-fatal: any exception during send is caught and logged so that a
|
|
Discord API failure never interrupts game evaluation.
|
|
|
|
Parameters
|
|
----------
|
|
channel:
|
|
A discord.abc.Messageable (e.g. discord.TextChannel).
|
|
tier_up:
|
|
Dict with keys: player_name, old_tier, new_tier, current_value, track_name.
|
|
"""
|
|
try:
|
|
embed = build_tier_up_embed(tier_up)
|
|
await channel.send(embed=embed)
|
|
except Exception as exc:
|
|
logger.error(
|
|
"Failed to send tier-up notification for %s (tier %s): %s",
|
|
tier_up.get("player_name", "unknown"),
|
|
tier_up.get("new_tier"),
|
|
exc,
|
|
)
|