mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Filter] Add filter clear commands (#4981)
* [Filter] Add filter clear commands * define messagepredicate * actually send msg, lol * deco fixes * black * [Docs] Update filter documentation * fixes * style * Add missing whitespace Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
parent
6f0a8b11d7
commit
f628093208
@ -122,6 +122,22 @@ Examples:
|
|||||||
|
|
||||||
- ``[words...]`` The words or sentences to filter.
|
- ``[words...]`` The words or sentences to filter.
|
||||||
|
|
||||||
|
.. _filter-command-filter-channel-clear:
|
||||||
|
|
||||||
|
""""""""""""""""""""
|
||||||
|
filter channel clear
|
||||||
|
""""""""""""""""""""
|
||||||
|
|
||||||
|
**Syntax**
|
||||||
|
|
||||||
|
.. code-block:: none
|
||||||
|
|
||||||
|
[p]filter channel clear
|
||||||
|
|
||||||
|
**Description**
|
||||||
|
|
||||||
|
Clears this channel's filter list.
|
||||||
|
|
||||||
.. _filter-command-filter-channel-list:
|
.. _filter-command-filter-channel-list:
|
||||||
|
|
||||||
"""""""""""""""""""
|
"""""""""""""""""""
|
||||||
@ -164,6 +180,22 @@ Examples:
|
|||||||
|
|
||||||
- ``[words...]`` The words or sentences to no longer filter.
|
- ``[words...]`` The words or sentences to no longer filter.
|
||||||
|
|
||||||
|
.. _filter-command-filter-clear:
|
||||||
|
|
||||||
|
""""""""""""
|
||||||
|
filter clear
|
||||||
|
""""""""""""
|
||||||
|
|
||||||
|
**Syntax**
|
||||||
|
|
||||||
|
.. code-block:: none
|
||||||
|
|
||||||
|
[p]filter clear
|
||||||
|
|
||||||
|
**Description**
|
||||||
|
|
||||||
|
Clears this server's filter list.
|
||||||
|
|
||||||
.. _filter-command-filter-delete:
|
.. _filter-command-filter-delete:
|
||||||
|
|
||||||
"""""""""""""
|
"""""""""""""
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import discord
|
import discord
|
||||||
import re
|
import re
|
||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
@ -6,6 +7,7 @@ from typing import Union, Set, Literal
|
|||||||
from redbot.core import checks, Config, modlog, commands
|
from redbot.core import checks, Config, modlog, commands
|
||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
from redbot.core.i18n import Translator, cog_i18n, set_contextual_locales_from_guild
|
from redbot.core.i18n import Translator, cog_i18n, set_contextual_locales_from_guild
|
||||||
|
from redbot.core.utils.predicates import MessagePredicate
|
||||||
from redbot.core.utils import AsyncIter
|
from redbot.core.utils import AsyncIter
|
||||||
from redbot.core.utils.chat_formatting import pagify, humanize_list
|
from redbot.core.utils.chat_formatting import pagify, humanize_list
|
||||||
|
|
||||||
@ -150,6 +152,29 @@ class Filter(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@_filter.command(name="clear")
|
||||||
|
async def _filter_clear(self, ctx: commands.Context):
|
||||||
|
"""Clears this server's filter list."""
|
||||||
|
guild = ctx.guild
|
||||||
|
author = ctx.author
|
||||||
|
filter_list = await self.config.guild(guild).filter()
|
||||||
|
if not filter_list:
|
||||||
|
return await ctx.send(_("The filter list for this server is empty."))
|
||||||
|
await ctx.send(
|
||||||
|
_("Are you sure you want to clear this server's filter list?") + " (yes/no)"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
pred = MessagePredicate.yes_or_no(ctx, user=author)
|
||||||
|
await ctx.bot.wait_for("message", check=pred, timeout=60)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
await ctx.send(_("You took too long to respond."))
|
||||||
|
return
|
||||||
|
if pred.result:
|
||||||
|
await self.config.guild(guild).filter.clear()
|
||||||
|
await ctx.send(_("Server filter cleared."))
|
||||||
|
else:
|
||||||
|
await ctx.send(_("No changes have been made."))
|
||||||
|
|
||||||
@_filter.command(name="list")
|
@_filter.command(name="list")
|
||||||
async def _global_list(self, ctx: commands.Context):
|
async def _global_list(self, ctx: commands.Context):
|
||||||
"""Send a list of this server's filtered words."""
|
"""Send a list of this server's filtered words."""
|
||||||
@ -157,7 +182,7 @@ class Filter(commands.Cog):
|
|||||||
author = ctx.author
|
author = ctx.author
|
||||||
word_list = await self.config.guild(server).filter()
|
word_list = await self.config.guild(server).filter()
|
||||||
if not word_list:
|
if not word_list:
|
||||||
await ctx.send(_("There is no current words setup to be filtered in this server."))
|
await ctx.send(_("There are no current words setup to be filtered in this server."))
|
||||||
return
|
return
|
||||||
words = humanize_list(word_list)
|
words = humanize_list(word_list)
|
||||||
words = _("Filtered in this server:") + "\n\n" + words
|
words = _("Filtered in this server:") + "\n\n" + words
|
||||||
@ -175,6 +200,29 @@ class Filter(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@_filter_channel.command(name="clear")
|
||||||
|
async def _channel_clear(self, ctx: commands.Context):
|
||||||
|
"""Clears this channel's filter list."""
|
||||||
|
channel = ctx.channel
|
||||||
|
author = ctx.author
|
||||||
|
filter_list = await self.config.channel(channel).filter()
|
||||||
|
if not filter_list:
|
||||||
|
return await ctx.send(_("The filter list for this channel is empty."))
|
||||||
|
await ctx.send(
|
||||||
|
_("Are you sure you want to clear this channel's filter list?") + " (yes/no)"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
pred = MessagePredicate.yes_or_no(ctx, user=author)
|
||||||
|
await ctx.bot.wait_for("message", check=pred, timeout=60)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
await ctx.send(_("You took too long to respond."))
|
||||||
|
return
|
||||||
|
if pred.result:
|
||||||
|
await self.config.channel(channel).filter.clear()
|
||||||
|
await ctx.send(_("Channel filter cleared."))
|
||||||
|
else:
|
||||||
|
await ctx.send(_("No changes have been made."))
|
||||||
|
|
||||||
@_filter_channel.command(name="list")
|
@_filter_channel.command(name="list")
|
||||||
async def _channel_list(self, ctx: commands.Context):
|
async def _channel_list(self, ctx: commands.Context):
|
||||||
"""Send a list of the channel's filtered words."""
|
"""Send a list of the channel's filtered words."""
|
||||||
@ -182,7 +230,7 @@ class Filter(commands.Cog):
|
|||||||
author = ctx.author
|
author = ctx.author
|
||||||
word_list = await self.config.channel(channel).filter()
|
word_list = await self.config.channel(channel).filter()
|
||||||
if not word_list:
|
if not word_list:
|
||||||
await ctx.send(_("There is no current words setup to be filtered in this channel."))
|
await ctx.send(_("There are no current words setup to be filtered in this channel."))
|
||||||
return
|
return
|
||||||
words = humanize_list(word_list)
|
words = humanize_list(word_list)
|
||||||
words = _("Filtered in this channel:") + "\n\n" + words
|
words = _("Filtered in this channel:") + "\n\n" + words
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user