[Filter] Add listing commands (#3973)

This commit is contained in:
Jamie 2020-06-18 21:23:16 +01:00 committed by GitHub
parent 175fbebd73
commit 4e890814ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ from typing import Union, Set
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 from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.chat_formatting import pagify from redbot.core.utils.chat_formatting import pagify, humanize_list
_ = Translator("Filter", __file__) _ = Translator("Filter", __file__)
@ -100,44 +100,50 @@ class Filter(commands.Cog):
"""Add or remove words from server filter. """Add or remove words from server filter.
Use double quotes to add or remove sentences. Use double quotes to add or remove sentences.
Using this command with no subcommands will send the list of
the server's filtered words.
""" """
if ctx.invoked_subcommand is None: pass
server = ctx.guild
author = ctx.author @_filter.command(name="list")
word_list = await self.config.guild(server).filter() async def _global_list(self, ctx: commands.Context):
if word_list: """Send a list of this servers filtered words."""
words = ", ".join(word_list) server = ctx.guild
words = _("Filtered in this server:") + "\n\n" + words author = ctx.author
try: word_list = await self.config.guild(server).filter()
for page in pagify(words, delims=[" ", "\n"], shorten_by=8): if not word_list:
await author.send(page) await ctx.send(_("There is no current words setup to be filtered in this server."))
except discord.Forbidden: return
await ctx.send(_("I can't send direct messages to you.")) words = humanize_list(word_list)
words = _("Filtered in this server:") + "\n\n" + words
try:
for page in pagify(words, delims=[" ", "\n"], shorten_by=8):
await author.send(page)
except discord.Forbidden:
await ctx.send(_("I can't send direct messages to you."))
@_filter.group(name="channel") @_filter.group(name="channel")
async def _filter_channel(self, ctx: commands.Context): async def _filter_channel(self, ctx: commands.Context):
"""Add or remove words from channel filter. """Add or remove words from channel filter.
Use double quotes to add or remove sentences. Use double quotes to add or remove sentences.
Using this command with no subcommands will send the list of
the channel's filtered words.
""" """
if ctx.invoked_subcommand is None: pass
channel = ctx.channel
author = ctx.author @_filter_channel.command(name="list")
word_list = await self.config.channel(channel).filter() async def _channel_list(self, ctx: commands.Context):
if word_list: """Send the list of the channel's filtered words."""
words = ", ".join(word_list) channel = ctx.channel
words = _("Filtered in this channel:") + "\n\n" + words author = ctx.author
try: word_list = await self.config.channel(channel).filter()
for page in pagify(words, delims=[" ", "\n"], shorten_by=8): if not word_list:
await author.send(page) await ctx.send(_("There is no current words setup to be filtered in this channel."))
except discord.Forbidden: return
await ctx.send(_("I can't send direct messages to you.")) words = humanize_list(word_list)
words = _("Filtered in this channel:") + "\n\n" + words
try:
for page in pagify(words, delims=[" ", "\n"], shorten_by=8):
await author.send(page)
except discord.Forbidden:
await ctx.send(_("I can't send direct messages to you."))
@_filter_channel.command("add") @_filter_channel.command("add")
async def filter_channel_add(self, ctx: commands.Context, *words: str): async def filter_channel_add(self, ctx: commands.Context, *words: str):