mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
More mention filtering (#2081)
* more filters * note to future people touching this * chan mentions were almost missed... * Swap strategies as the previous escaped the mention, while still pinging the user/role
This commit is contained in:
parent
d71c334a34
commit
9495432b8f
@ -12,7 +12,7 @@ from .checks import mod_or_voice_permissions, admin_or_voice_permissions, bot_ha
|
|||||||
from redbot.core.utils.mod import is_mod_or_superior, is_allowed_by_hierarchy, get_audit_reason
|
from redbot.core.utils.mod import is_mod_or_superior, is_allowed_by_hierarchy, get_audit_reason
|
||||||
from .log import log
|
from .log import log
|
||||||
|
|
||||||
from redbot.core.utils.common_filters import filter_invites
|
from redbot.core.utils.common_filters import filter_invites, filter_various_mentions
|
||||||
|
|
||||||
_ = Translator("Mod", __file__)
|
_ = Translator("Mod", __file__)
|
||||||
|
|
||||||
@ -1323,9 +1323,11 @@ class Mod:
|
|||||||
if roles is not None:
|
if roles is not None:
|
||||||
data.add_field(name=_("Roles"), value=roles, inline=False)
|
data.add_field(name=_("Roles"), value=roles, inline=False)
|
||||||
if names:
|
if names:
|
||||||
|
# May need sanitizing later, but mentions do not ping in embeds currently
|
||||||
val = filter_invites(", ".join(names))
|
val = filter_invites(", ".join(names))
|
||||||
data.add_field(name=_("Previous Names"), value=val, inline=False)
|
data.add_field(name=_("Previous Names"), value=val, inline=False)
|
||||||
if nicks:
|
if nicks:
|
||||||
|
# May need sanitizing later, but mentions do not ping in embeds currently
|
||||||
val = filter_invites(", ".join(nicks))
|
val = filter_invites(", ".join(nicks))
|
||||||
data.add_field(name=_("Previous Nicknames"), value=val, inline=False)
|
data.add_field(name=_("Previous Nicknames"), value=val, inline=False)
|
||||||
if voice_state and voice_state.channel:
|
if voice_state and voice_state.channel:
|
||||||
@ -1369,6 +1371,7 @@ class Mod:
|
|||||||
msg += "\n"
|
msg += "\n"
|
||||||
msg += ", ".join(nicks)
|
msg += ", ".join(nicks)
|
||||||
if msg:
|
if msg:
|
||||||
|
msg = filter_various_mentions(msg)
|
||||||
await ctx.send(msg)
|
await ctx.send(msg)
|
||||||
else:
|
else:
|
||||||
await ctx.send(_("That user doesn't have any recorded name or nickname change."))
|
await ctx.send(_("That user doesn't have any recorded name or nickname change."))
|
||||||
|
|||||||
@ -7,6 +7,7 @@ __all__ = [
|
|||||||
"filter_urls",
|
"filter_urls",
|
||||||
"filter_invites",
|
"filter_invites",
|
||||||
"filter_mass_mentions",
|
"filter_mass_mentions",
|
||||||
|
"filter_various_mentions",
|
||||||
]
|
]
|
||||||
|
|
||||||
# regexes
|
# regexes
|
||||||
@ -16,6 +17,7 @@ INVITE_URL_RE = re.compile(r"(discord.gg|discordapp.com/invite|discord.me)(\S+)"
|
|||||||
|
|
||||||
MASS_MENTION_RE = re.compile(r"(@)(?=everyone|here)") # This only matches the @ for sanitizing
|
MASS_MENTION_RE = re.compile(r"(@)(?=everyone|here)") # This only matches the @ for sanitizing
|
||||||
|
|
||||||
|
OTHER_MENTION_RE = re.compile(r"(<)(@[!&]?|#)(\d+>)")
|
||||||
|
|
||||||
# convenience wrappers
|
# convenience wrappers
|
||||||
def filter_urls(to_filter: str) -> str:
|
def filter_urls(to_filter: str) -> str:
|
||||||
@ -79,3 +81,23 @@ def filter_mass_mentions(to_filter: str) -> str:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
return MASS_MENTION_RE.sub("@\u200b", to_filter)
|
return MASS_MENTION_RE.sub("@\u200b", to_filter)
|
||||||
|
|
||||||
|
|
||||||
|
def filter_various_mentions(to_filter: str) -> str:
|
||||||
|
"""
|
||||||
|
Get a string with role, user, and channel mentions sanitized.
|
||||||
|
|
||||||
|
This is mainly for use on user display names, not message content,
|
||||||
|
and should be applied sparingly.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
to_filter : str
|
||||||
|
The string to filter.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
str
|
||||||
|
The sanitized string.
|
||||||
|
"""
|
||||||
|
return OTHER_MENTION_RE.sub(r"\1\\\2\3", to_filter)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user