mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
* Revert "new mention behavior, new filter behavior (#3553)" This reverts commit 066bf516d9b1ac27b1f7459a5f42aea56fffa4b1. * keep invalid escape fix
This commit is contained in:
parent
136fcd7bb2
commit
227009733e
@ -973,7 +973,6 @@ class RedBase(
|
|||||||
async def send_filtered(
|
async def send_filtered(
|
||||||
destination: discord.abc.Messageable,
|
destination: discord.abc.Messageable,
|
||||||
filter_mass_mentions=True,
|
filter_mass_mentions=True,
|
||||||
filter_roles=True,
|
|
||||||
filter_invite_links=True,
|
filter_invite_links=True,
|
||||||
filter_all_links=False,
|
filter_all_links=False,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
@ -1000,8 +999,6 @@ class RedBase(
|
|||||||
content = kwargs.pop("content", None)
|
content = kwargs.pop("content", None)
|
||||||
|
|
||||||
if content:
|
if content:
|
||||||
if filter_roles and isinstance(destination, discord.TextChannel):
|
|
||||||
content = common_filters.sanitize_role_mentions(content, destination.guild.roles)
|
|
||||||
if filter_mass_mentions:
|
if filter_mass_mentions:
|
||||||
content = common_filters.filter_mass_mentions(content)
|
content = common_filters.filter_mass_mentions(content)
|
||||||
if filter_invite_links:
|
if filter_invite_links:
|
||||||
|
|||||||
@ -75,9 +75,6 @@ class Context(DPYContext):
|
|||||||
:func:`~redbot.core.utils.common_filters.filter_mass_mentions`.
|
:func:`~redbot.core.utils.common_filters.filter_mass_mentions`.
|
||||||
This must take a single `str` as an argument, and return
|
This must take a single `str` as an argument, and return
|
||||||
the sanitized `str`.
|
the sanitized `str`.
|
||||||
sanitize_roles : bool
|
|
||||||
Whether or not role mentions should be sanitized for you.
|
|
||||||
Defaults to ``True``
|
|
||||||
**kwargs
|
**kwargs
|
||||||
See `discord.ext.commands.Context.send`.
|
See `discord.ext.commands.Context.send`.
|
||||||
|
|
||||||
@ -89,10 +86,6 @@ class Context(DPYContext):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_filter = kwargs.pop("filter", common_filters.filter_mass_mentions)
|
_filter = kwargs.pop("filter", common_filters.filter_mass_mentions)
|
||||||
sanitize_roles = kwargs.pop("sanitize_roles", True)
|
|
||||||
|
|
||||||
if sanitize_roles and content and self.guild:
|
|
||||||
content = common_filters.sanitize_role_mentions(str(content), self.guild.roles)
|
|
||||||
|
|
||||||
if _filter and content:
|
if _filter and content:
|
||||||
content = _filter(str(content))
|
content = _filter(str(content))
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
import re
|
import re
|
||||||
from typing import Iterable
|
|
||||||
|
|
||||||
import discord
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"URL_RE",
|
"URL_RE",
|
||||||
@ -14,7 +11,6 @@ __all__ = [
|
|||||||
"normalize_smartquotes",
|
"normalize_smartquotes",
|
||||||
"escape_spoilers",
|
"escape_spoilers",
|
||||||
"escape_spoilers_and_mass_mentions",
|
"escape_spoilers_and_mass_mentions",
|
||||||
"sanitize_role_mentions",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# regexes
|
# regexes
|
||||||
@ -177,32 +173,3 @@ def escape_spoilers_and_mass_mentions(content: str) -> str:
|
|||||||
The escaped string.
|
The escaped string.
|
||||||
"""
|
"""
|
||||||
return escape_spoilers(filter_mass_mentions(content))
|
return escape_spoilers(filter_mass_mentions(content))
|
||||||
|
|
||||||
|
|
||||||
def sanitize_role_mentions(content: str, roles: Iterable[discord.Role]) -> str:
|
|
||||||
"""
|
|
||||||
Swaps out role mentions for @RoleName
|
|
||||||
|
|
||||||
This should always be used prior to filtering everyone mentions
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
content: str
|
|
||||||
The string to make substitutions to
|
|
||||||
roles: Iterable[discord.Role]
|
|
||||||
The roles to make substitutions for
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
str
|
|
||||||
The resulting string
|
|
||||||
"""
|
|
||||||
transformations = {re.escape(fr"<@&{role.id}>"): f"@{role.name}" for role in roles}
|
|
||||||
|
|
||||||
def repl(obj):
|
|
||||||
return transformations.get(re.escape(obj.group(0)), "")
|
|
||||||
|
|
||||||
pattern = re.compile("|".join(transformations.keys()))
|
|
||||||
result = pattern.sub(repl, content)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user