feat: strip all mentions from relayed messages by default (v3.4.3)
- Default mention_policy now disables all mention types including user mentions (previously allow_user_mentions defaulted to True) - Blocked mentions are now removed entirely instead of replaced with ZWSP placeholders — '@mention HI!' becomes 'HI!' on the other side - Trailing whitespace from removed mentions is cleaned up - Updated both apply_mention_policy() and sanitise_mentions()
This commit is contained in:
parent
f1c8970d3d
commit
9e8650c01a
2 changed files with 17 additions and 13 deletions
|
|
@ -215,26 +215,30 @@ def generate_invite_code(length: int = 8) -> str:
|
|||
def sanitise_mentions(content: str, config: dict) -> str:
|
||||
"""Legacy mention control — kept for backwards compatibility."""
|
||||
if config.get("strip_everyone"):
|
||||
content = content.replace("@everyone", "@\u200beveryone").replace("@here", "@\u200bhere")
|
||||
content = content.replace("@everyone", "").replace("@here", "")
|
||||
if config.get("strip_role_mentions"):
|
||||
content = re.sub(r"<@&(\d+)>", r"@role", content)
|
||||
content = re.sub(r"<@&\d+>\s?", "", content)
|
||||
if config.get("strip_user_mentions"):
|
||||
content = re.sub(r"<@!?(\d+)>", r"@user", content)
|
||||
content = re.sub(r"<@!?\d+>\s?", "", content)
|
||||
if content != content:
|
||||
content = re.sub(r" +", " ", content).strip()
|
||||
return content
|
||||
|
||||
|
||||
def apply_mention_policy(content: str, policy: dict, author_id: int, exempt_users: list) -> str:
|
||||
"""Apply granular mention policy. If the user is exempt, mentions pass through."""
|
||||
"""Apply granular mention policy — blocked mentions are stripped entirely."""
|
||||
if author_id in exempt_users:
|
||||
return content
|
||||
if not policy.get("allow_everyone", False):
|
||||
content = content.replace("@everyone", "@\u200beveryone")
|
||||
content = content.replace("@everyone", "")
|
||||
if not policy.get("allow_here", False):
|
||||
content = content.replace("@here", "@\u200bhere")
|
||||
content = content.replace("@here", "")
|
||||
if not policy.get("allow_role_mentions", False):
|
||||
content = re.sub(r"<@&(\d+)>", "@\u200brole", content)
|
||||
if not policy.get("allow_user_mentions", True):
|
||||
content = re.sub(r"<@!?(\d+)>", "@\u200buser", content)
|
||||
content = re.sub(r"<@&\d+>\s?", "", content)
|
||||
if not policy.get("allow_user_mentions", False):
|
||||
content = re.sub(r"<@!?\d+>\s?", "", content)
|
||||
# Collapse any leftover double-spaces from removals
|
||||
content = re.sub(r" +", " ", content).strip()
|
||||
return content
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -243,10 +243,10 @@ _DEFAULT_NETWORK = {
|
|||
# ── Phase 5 ──
|
||||
# Granular mention policy
|
||||
"mention_policy": {
|
||||
"allow_user_mentions": True, # allow @user pings to relay as real pings
|
||||
"allow_role_mentions": False, # allow @role pings
|
||||
"allow_everyone": False, # allow @everyone
|
||||
"allow_here": False, # allow @here
|
||||
"allow_user_mentions": False, # strip @user pings from relayed messages
|
||||
"allow_role_mentions": False, # strip @role pings
|
||||
"allow_everyone": False, # strip @everyone
|
||||
"allow_here": False, # strip @here
|
||||
},
|
||||
"server_mention_overrides": {}, # {guild_id_str: {same keys as mention_policy}}
|
||||
"mention_exempt_users": [], # user IDs allowed to bypass mention policy
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue