[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.bot import Red
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__)
@ -100,16 +100,19 @@ class Filter(commands.Cog):
"""Add or remove words from server filter.
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
@_filter.command(name="list")
async def _global_list(self, ctx: commands.Context):
"""Send a list of this servers filtered words."""
server = ctx.guild
author = ctx.author
word_list = await self.config.guild(server).filter()
if word_list:
words = ", ".join(word_list)
if not word_list:
await ctx.send(_("There is no current words setup to be filtered in this server."))
return
words = humanize_list(word_list)
words = _("Filtered in this server:") + "\n\n" + words
try:
for page in pagify(words, delims=[" ", "\n"], shorten_by=8):
@ -122,16 +125,19 @@ class Filter(commands.Cog):
"""Add or remove words from channel filter.
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
@_filter_channel.command(name="list")
async def _channel_list(self, ctx: commands.Context):
"""Send the list of the channel's filtered words."""
channel = ctx.channel
author = ctx.author
word_list = await self.config.channel(channel).filter()
if word_list:
words = ", ".join(word_list)
if not word_list:
await ctx.send(_("There is no current words setup to be filtered in this channel."))
return
words = humanize_list(word_list)
words = _("Filtered in this channel:") + "\n\n" + words
try:
for page in pagify(words, delims=[" ", "\n"], shorten_by=8):