mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-22 10:47:58 -05:00
Output sanitisation (#1942)
* Add output sanitization defaults to context.send Add some common regex filters in redbot.core.utils.common_filters Add a wrapper for ease of use in bot.send_filtered Sanitize ModLog Case's user field (other's considered trusted as moderator input) Sanitize Usernames/Nicks in userinfo command. Santize Usernames in closing of tunnels. * Add documentation
This commit is contained in:
committed by
Toby Harradine
parent
6ebfdef025
commit
77944e195a
@@ -5,7 +5,7 @@ import discord
|
||||
from discord.ext import commands
|
||||
|
||||
from redbot.core.utils.chat_formatting import box
|
||||
|
||||
from redbot.core.utils import common_filters
|
||||
|
||||
TICK = "\N{WHITE HEAVY CHECK MARK}"
|
||||
|
||||
@@ -20,6 +20,42 @@ class Context(commands.Context):
|
||||
This class inherits from `discord.ext.commands.Context`.
|
||||
"""
|
||||
|
||||
async def send(self, content=None, **kwargs):
|
||||
"""Sends a message to the destination with the content given.
|
||||
|
||||
This acts the same as `discord.ext.commands.Context.send`, with
|
||||
one added keyword argument as detailed below in *Other Parameters*.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
content : str
|
||||
The content of the message to send.
|
||||
|
||||
Other Parameters
|
||||
----------------
|
||||
filter : Callable[`str`] -> `str`
|
||||
A function which is used to sanitize the ``content`` before
|
||||
it is sent. Defaults to
|
||||
:func:`~redbot.core.utils.common_filters.filter_mass_mentions`.
|
||||
This must take a single `str` as an argument, and return
|
||||
the sanitized `str`.
|
||||
\*\*kwargs
|
||||
See `discord.ext.commands.Context.send`.
|
||||
|
||||
Returns
|
||||
-------
|
||||
discord.Message
|
||||
The message that was sent.
|
||||
|
||||
"""
|
||||
|
||||
_filter = kwargs.pop("filter", common_filters.filter_mass_mentions)
|
||||
|
||||
if _filter and content:
|
||||
content = _filter(str(content))
|
||||
|
||||
return await super().send(content=content, **kwargs)
|
||||
|
||||
async def send_help(self) -> List[discord.Message]:
|
||||
"""Send the command help message.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user