feat(commands:tag>all|Tag): feat way to see all tag for a guild

fix(core): close TUXBOT-BOT-4X
This commit is contained in:
Romain J 2021-05-16 15:27:27 +02:00
parent 614434aebf
commit 06bcae81fe
15 changed files with 100 additions and 25 deletions

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-05-16 00:28+0200\n"
"POT-Creation-Date: 2021-05-16 15:11+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-05-16 00:28+0200\n"
"POT-Creation-Date: 2021-05-16 15:11+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-05-16 00:28+0200\n"
"POT-Creation-Date: 2021-05-16 15:11+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-05-16 00:28+0200\n"
"POT-Creation-Date: 2021-05-16 15:11+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-05-16 00:28+0200\n"
"POT-Creation-Date: 2021-05-16 15:11+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-05-16 00:28+0200\n"
"POT-Creation-Date: 2021-05-16 15:11+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View file

@ -4,6 +4,8 @@ from discord.ext.commands import Context
from tuxbot.cogs.Tags.functions.exceptions import (
UnknownTagException,
ExistingTagException,
TooLongTagException,
ReservedTagException,
)
from tuxbot.cogs.Tags.models import Tag
@ -28,6 +30,16 @@ class NewTagConverter(commands.Converter):
async def convert(self, ctx: Context, argument: str): # skipcq: PYL-W0613
arg = argument.lower()
if len(arg) > 50:
raise TooLongTagException(
_("Tag must be lower than 50 characters")
)
if arg.split(" ")[0] in ctx.bot.get_command("tag").all_commands:
raise ReservedTagException(
_("This tag name starts with a tag subcommand name")
)
tag_row = await Tag.get_or_none(server_id=ctx.guild.id, name=arg)
if tag_row:

View file

@ -11,3 +11,11 @@ class UnknownTagException(TagsException):
class ExistingTagException(TagsException):
pass
class TooLongTagException(TagsException):
pass
class ReservedTagException(TagsException):
pass

View file

@ -24,7 +24,11 @@ async def get_all_tags(
async def search_tags(guild_id: int, q: str) -> list[Tag]:
return await Tag.filter(server_id=guild_id, name__icontains=q).all().order_by("-uses")
return (
await Tag.filter(server_id=guild_id, name__icontains=q)
.all()
.order_by("-uses")
)
async def create_tag(ctx: ContextPlus, name: str, content: str):

View file

@ -21,6 +21,14 @@ msgstr ""
msgid "Unknown tag"
msgstr ""
#: tuxbot/cogs/Tags/functions/converters.py:35
msgid "Tag must be lower than 50 characters"
msgstr ""
#: tuxbot/cogs/Tags/functions/converters.py:40
msgid "This tag name starts with a tag subcommand name"
msgstr ""
#: tuxbot/cogs/Tags/functions/converters.py:34
msgid "Tag already exists"
msgstr ""

View file

@ -22,6 +22,14 @@ msgstr ""
msgid "Unknown tag"
msgstr "Tag inconnu"
#: tuxbot/cogs/Tags/functions/converters.py:35
msgid "Tag must be lower than 50 characters"
msgstr "Le nom du tag doit faire moins de 50 caracteres"
#: tuxbot/cogs/Tags/functions/converters.py:40
msgid "This tag name starts with a tag subcommand name"
msgstr "Le nom du tag est reservé"
#: tuxbot/cogs/Tags/functions/converters.py:34
msgid "Tag already exists"
msgstr "Tag déjà existant"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-05-16 00:28+0200\n"
"POT-Creation-Date: 2021-05-16 15:11+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,58 +17,66 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: tuxbot/cogs/Tags/functions/converters.py:22
#: tuxbot/cogs/Tags/functions/converters.py:24
msgid "Unknown tag"
msgstr ""
#: tuxbot/cogs/Tags/functions/converters.py:34
#: tuxbot/cogs/Tags/functions/converters.py:35
msgid "Tag must be lower than 50 characters"
msgstr ""
#: tuxbot/cogs/Tags/functions/converters.py:40
msgid "This tag name starts with a tag subcommand name"
msgstr ""
#: tuxbot/cogs/Tags/functions/converters.py:46
msgid "Tag already exists"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:71
#: tuxbot/cogs/Tags/tags.py:78
msgid "Tag successfully deleted"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:74
#: tuxbot/cogs/Tags/tags.py:81
msgid "Your can't delete this tag"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:82
#: tuxbot/cogs/Tags/tags.py:89
msgid "Tag successfully created"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:98
#: tuxbot/cogs/Tags/tags.py:105
msgid "Tag successfully edited"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:101
#: tuxbot/cogs/Tags/tags.py:108
msgid "Your can't edit this tag"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:120
#: tuxbot/cogs/Tags/tags.py:127
msgid "Owner"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:122
#: tuxbot/cogs/Tags/tags.py:129
msgid "Uses"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:135
#: tuxbot/cogs/Tags/tags.py:142
msgid "The search must be at least 3 characters"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:150
#: tuxbot/cogs/Tags/tags.py:157
msgid "No tags found"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:171
#: tuxbot/cogs/Tags/tags.py:178 tuxbot/cogs/Tags/tags.py:193
msgid "No tags found for {}"
msgstr ""
#: tuxbot/cogs/Tags/tags.py:180
#: tuxbot/cogs/Tags/tags.py:204
msgid "Tag owner is on this server."
msgstr ""
#: tuxbot/cogs/Tags/tags.py:188
#: tuxbot/cogs/Tags/tags.py:212
msgid "This tag is now owned by you."
msgstr ""

View file

@ -8,6 +8,8 @@ from tuxbot.cogs.Tags.functions.converters import TagConverter, NewTagConverter
from tuxbot.cogs.Tags.functions.exceptions import (
UnknownTagException,
ExistingTagException,
TooLongTagException,
ReservedTagException,
)
from tuxbot.cogs.Tags.functions.paginator import TagPages
from tuxbot.cogs.Tags.functions.utils import (
@ -38,7 +40,12 @@ class Tags(commands.Cog):
async def cog_command_error(self, ctx: ContextPlus, error):
if isinstance(
error,
(UnknownTagException, ExistingTagException),
(
UnknownTagException,
ExistingTagException,
TooLongTagException,
ReservedTagException,
),
):
await ctx.send(_(str(error), ctx, self.bot.config))
@ -171,6 +178,23 @@ class Tags(commands.Cog):
_("No tags found for {}", ctx, self.bot.config).format(author)
)
@_tag.command(name="all")
async def _tag_all(self, ctx: ContextPlus):
tags = await get_all_tags(ctx.guild.id)
if tags:
try:
p = TagPages(entries=tags)
await p.start(ctx)
except menus.MenuError as e:
await ctx.send(e)
else:
await ctx.send(
_("No tags found for {}", ctx, self.bot.config).format(
ctx.guild.name
)
)
@_tag.command(name="claim")
async def _tag_claim(self, ctx: ContextPlus, *, name: TagConverter):
tag_row = await get_tag(ctx.guild.id, str(name))

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\n"
"POT-Creation-Date: 2021-05-16 00:28+0200\n"
"POT-Creation-Date: 2021-05-16 15:11+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

View file

@ -112,7 +112,10 @@ class ContextPlus(commands.Context):
"reaction_add", timeout=42.0, check=check
)
except asyncio.TimeoutError:
await message.remove_reaction("🗑", self.bot.user)
try:
await message.remove_reaction("🗑", self.bot.user)
except discord.HTTPException:
return None
else:
await message.delete()
return message