fix help output for list/export

This commit is contained in:
io mintz 2020-06-01 05:47:10 +00:00
parent 7e5f01b82d
commit aa298198f1
2 changed files with 21 additions and 10 deletions

View File

@ -37,7 +37,7 @@ import utils
import utils.archive
import utils.image
from utils import errors
from utils.converter import emote_type_filter
from utils.converter import emote_type_filter_default
from utils.paginator import ListPaginator
logger = logging.getLogger(__name__)
@ -210,9 +210,10 @@ class Emotes(commands.Cog):
await context.send(message)
@emote_type_filter_default
@commands.command()
@commands.bot_has_permissions(attach_files=True)
async def export(self, context, *, image_type: emote_type_filter = lambda _: True):
async def export(self, context, image_type='all'):
"""Export all emotes from this server to a zip file, suitable for use with the import command.
If animated is provided, only include animated emotes.
@ -404,18 +405,19 @@ class Emotes(commands.Cog):
await context.send(fr'Emote successfully renamed to \:{new_name}:')
@emote_type_filter_default
@commands.command(aliases=('ls', 'dir'))
async def list(self, context, animated: emote_type_filter = lambda _: True):
async def list(self, context, image_type='all'):
"""A list of all emotes on this server.
The list shows each emote and its raw form.
If "animated" is provided, only show animated emotes.
If "static" is provided, only show static emotes.
Otherwise, or if all is provided, show all emotes.
If all is provided, show all emotes.
"""
emotes = sorted(
filter(animated, context.guild.emojis),
filter(image_type, context.guild.emojis),
key=lambda e: e.name.lower())
processed = []

View File

@ -13,14 +13,23 @@
# You should have received a copy of the GNU Affero General Public License
# along with Emote Manager. If not, see <https://www.gnu.org/licenses/>.
import functools
_emote_type_predicates = {
'': lambda _: True, # allow usage as a "consume rest" converter
'all': lambda _: True,
'static': lambda e: not e.animated,
'animated': lambda e: e.animated}
def emote_type_filter(argument):
try:
return _emote_type_predicates[argument.lower()]
except KeyError:
raise commands.BadArgument('Invalid emote type. Specify “static”, “animated”, “all”.')
# this is kind of a hack to ensure that the last argument is always converted, even if the default is used.
def emote_type_filter_default(command):
old_callback = command.callback
@functools.wraps(old_callback)
async def callback(self, ctx, *args):
image_type = args[-1]
image_type = _emote_type_predicates[image_type]
return await old_callback(self, ctx, *args[:-1], image_type)
command.callback = callback
return command