blacklist DSPL 💔 2 (#1294)
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
"no_data_title": "No Data",
|
"no_data_title": "No Data",
|
||||||
"access_denied_title": "Access Denied",
|
"access_denied_title": "Access Denied",
|
||||||
"access_denied_desc": "This server has been blacklisted.",
|
"access_denied_desc": "This server has been blacklisted.",
|
||||||
|
"server_blacklisted_reason": "This server has been blacklisted for reason: {reason}",
|
||||||
"no_players_selected": "No players selected. Please select at least one player.",
|
"no_players_selected": "No players selected. Please select at least one player.",
|
||||||
"must_use_in_server": "This command must be used in a server.",
|
"must_use_in_server": "This command must be used in a server.",
|
||||||
"could_not_resolve_channel": "Could not resolve the selected channel.",
|
"could_not_resolve_channel": "Could not resolve the selected channel.",
|
||||||
|
|||||||
+29
-10
@@ -34,7 +34,7 @@ from wcwidth import wcswidth
|
|||||||
# BOT/__init__.py has already put BOTS/SHARED on sys.path; re-export it
|
# BOT/__init__.py has already put BOTS/SHARED on sys.path; re-export it
|
||||||
# under a public name so peer modules can use it for asset paths.
|
# under a public name so peer modules can use it for asset paths.
|
||||||
from . import SHARED_DIR # noqa: F401 — re-exported for siblings
|
from . import SHARED_DIR # noqa: F401 — re-exported for siblings
|
||||||
from shared_store import check_user_blacklist, blacklisted_guilds
|
from shared_store import check_user_blacklist, check_guild_blacklist, blacklisted_guilds
|
||||||
from data_parser import (
|
from data_parser import (
|
||||||
LangTableReader,
|
LangTableReader,
|
||||||
UnitTags,
|
UnitTags,
|
||||||
@@ -471,8 +471,17 @@ class AdminCheckFailure(app_commands.CheckFailure):
|
|||||||
|
|
||||||
|
|
||||||
class BlacklistCheckFailure(app_commands.CheckFailure):
|
class BlacklistCheckFailure(app_commands.CheckFailure):
|
||||||
"""Raised when a blacklisted user or guild attempts to run a command."""
|
"""Raised when a blacklisted user or guild attempts to run a command.
|
||||||
pass
|
|
||||||
|
``reason`` carries the optional BLACKLIST.json reason; ``is_guild`` marks
|
||||||
|
whether the block came from the guild (vs the invoking user) so the error
|
||||||
|
handler can render a server-specific message.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, reason: Optional[str] = None, *, is_guild: bool = False):
|
||||||
|
super().__init__(reason or "")
|
||||||
|
self.reason = reason
|
||||||
|
self.is_guild = is_guild
|
||||||
|
|
||||||
|
|
||||||
class TierGateFailure(app_commands.CheckFailure):
|
class TierGateFailure(app_commands.CheckFailure):
|
||||||
@@ -536,8 +545,10 @@ def is_blacklisted():
|
|||||||
"""
|
"""
|
||||||
async def predicate(interaction: discord.Interaction):
|
async def predicate(interaction: discord.Interaction):
|
||||||
guild = interaction.guild
|
guild = interaction.guild
|
||||||
if guild is not None and guild.id in blacklisted_guilds():
|
if guild is not None:
|
||||||
raise BlacklistCheckFailure(t("en", "common.access_denied_desc"))
|
g_blocked, g_reason = check_guild_blacklist(guild.id)
|
||||||
|
if g_blocked:
|
||||||
|
raise BlacklistCheckFailure(g_reason, is_guild=True)
|
||||||
|
|
||||||
blocked, reason = check_user_blacklist(interaction.user.id)
|
blocked, reason = check_user_blacklist(interaction.user.id)
|
||||||
if blocked:
|
if blocked:
|
||||||
@@ -575,17 +586,25 @@ async def permission_fail(interaction: discord.Interaction, error):
|
|||||||
"""Handle permission-related errors with appropriate embeds."""
|
"""Handle permission-related errors with appropriate embeds."""
|
||||||
lang = await guild_lang(interaction.guild_id) if interaction.guild_id else "en"
|
lang = await guild_lang(interaction.guild_id) if interaction.guild_id else "en"
|
||||||
if isinstance(error, BlacklistCheckFailure):
|
if isinstance(error, BlacklistCheckFailure):
|
||||||
reason = error.args[0] if error.args else None
|
reason = getattr(error, "reason", None)
|
||||||
|
is_guild = getattr(error, "is_guild", False)
|
||||||
logging.warning(
|
logging.warning(
|
||||||
"Blacklisted command attempt blocked: user_id=%s guild_id=%s command=%s reason=%r",
|
"Blacklisted command attempt blocked: user_id=%s guild_id=%s command=%s is_guild=%s reason=%r",
|
||||||
getattr(interaction.user, "id", None),
|
getattr(interaction.user, "id", None),
|
||||||
interaction.guild_id,
|
interaction.guild_id,
|
||||||
interaction.command.qualified_name if interaction.command else None,
|
interaction.command.qualified_name if interaction.command else None,
|
||||||
|
is_guild,
|
||||||
reason,
|
reason,
|
||||||
)
|
)
|
||||||
desc = t(lang, "permission.blacklisted_desc")
|
if is_guild:
|
||||||
if reason:
|
if reason:
|
||||||
desc += "\n" + t(lang, "permission.reason_line", reason=reason)
|
desc = t(lang, "common.server_blacklisted_reason", reason=reason)
|
||||||
|
else:
|
||||||
|
desc = t(lang, "common.access_denied_desc")
|
||||||
|
else:
|
||||||
|
desc = t(lang, "permission.blacklisted_desc")
|
||||||
|
if reason:
|
||||||
|
desc += "\n" + t(lang, "permission.reason_line", reason=reason)
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title=t(lang, "permission.blacklisted_title"),
|
title=t(lang, "permission.blacklisted_title"),
|
||||||
description=desc,
|
description=desc,
|
||||||
|
|||||||
Reference in New Issue
Block a user