move some commands to standard (#1256)
This commit is contained in:
@@ -490,6 +490,19 @@ class BlacklistCheckFailure(app_commands.CheckFailure):
|
||||
pass
|
||||
|
||||
|
||||
class TierGateFailure(app_commands.CheckFailure):
|
||||
"""Raised when a guild's tier is below what a command requires.
|
||||
|
||||
The minimum required tier is carried on ``required_tier`` so
|
||||
``permission_fail`` can render the matching localized embed.
|
||||
"""
|
||||
|
||||
def __init__(self, required_tier: str, current_tier: Optional[str] = None):
|
||||
super().__init__(f"This command requires the '{required_tier}' tier or higher.")
|
||||
self.required_tier = required_tier
|
||||
self.current_tier = current_tier
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# PERMISSION DECORATORS
|
||||
# ============================================================================
|
||||
@@ -551,6 +564,27 @@ def is_blacklisted():
|
||||
return app_commands.check(predicate)
|
||||
|
||||
|
||||
def gate_entitle(required_tier: str):
|
||||
"""Return an app-command check that requires a minimum entitlement tier.
|
||||
|
||||
Accepts 'standard', 'pro', or 'max'. Guilds with no active entitlement, or
|
||||
with a tier strictly lower than ``required_tier``, are rejected with a
|
||||
``TierGateFailure`` carrying the required tier so the error handler can
|
||||
render the matching localized embed.
|
||||
"""
|
||||
if required_tier not in TIER_ORDER:
|
||||
raise ValueError(f"Unknown tier {required_tier!r}; expected one of {TIER_ORDER}")
|
||||
|
||||
async def predicate(interaction: discord.Interaction):
|
||||
if interaction.guild_id is None:
|
||||
raise TierGateFailure(required_tier, None)
|
||||
current = await get_guild_tier(interaction.guild_id)
|
||||
if _tier_rank(current) < _tier_rank(required_tier):
|
||||
raise TierGateFailure(required_tier, current)
|
||||
return True
|
||||
return app_commands.check(predicate)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# PERMISSION ERROR HANDLER
|
||||
# ============================================================================
|
||||
@@ -574,6 +608,13 @@ async def permission_fail(interaction: discord.Interaction, error):
|
||||
description=f"{error.args[0]}",
|
||||
color=discord.Color.orange()
|
||||
)
|
||||
elif isinstance(error, TierGateFailure):
|
||||
desc_key = f"permission.tier_gate_{error.required_tier}_desc"
|
||||
embed = discord.Embed(
|
||||
title=t(lang, "permission.tier_gate_title"),
|
||||
description=t(lang, desc_key),
|
||||
color=discord.Color.gold()
|
||||
)
|
||||
elif isinstance(error, app_commands.CheckFailure):
|
||||
embed = discord.Embed(
|
||||
title=t(lang, "permission.access_denied_title"),
|
||||
|
||||
Reference in New Issue
Block a user