diff --git a/tuxbot/cogs/Custom/locales/messages.pot b/tuxbot/cogs/Custom/locales/messages.pot index 5eb7438..feeefc5 100644 --- a/tuxbot/cogs/Custom/locales/messages.pot +++ b/tuxbot/cogs/Custom/locales/messages.pot @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/tuxbot/cogs/Linux/locales/messages.pot b/tuxbot/cogs/Linux/locales/messages.pot index 3e61664..8c5752e 100644 --- a/tuxbot/cogs/Linux/locales/messages.pot +++ b/tuxbot/cogs/Linux/locales/messages.pot @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/tuxbot/cogs/Logs/locales/messages.pot b/tuxbot/cogs/Logs/locales/messages.pot index 2822dd1..da92f97 100644 --- a/tuxbot/cogs/Logs/locales/messages.pot +++ b/tuxbot/cogs/Logs/locales/messages.pot @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/tuxbot/cogs/Mod/locales/messages.pot b/tuxbot/cogs/Mod/locales/messages.pot index f8e6df6..3956439 100644 --- a/tuxbot/cogs/Mod/locales/messages.pot +++ b/tuxbot/cogs/Mod/locales/messages.pot @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/tuxbot/cogs/Network/locales/messages.pot b/tuxbot/cogs/Network/locales/messages.pot index 4e34ff7..2c41755 100644 --- a/tuxbot/cogs/Network/locales/messages.pot +++ b/tuxbot/cogs/Network/locales/messages.pot @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/tuxbot/cogs/Polls/locales/messages.pot b/tuxbot/cogs/Polls/locales/messages.pot index b03876f..b8e143b 100644 --- a/tuxbot/cogs/Polls/locales/messages.pot +++ b/tuxbot/cogs/Polls/locales/messages.pot @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/tuxbot/cogs/Tags/functions/converters.py b/tuxbot/cogs/Tags/functions/converters.py index 64ad8d3..1981c4c 100644 --- a/tuxbot/cogs/Tags/functions/converters.py +++ b/tuxbot/cogs/Tags/functions/converters.py @@ -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: diff --git a/tuxbot/cogs/Tags/functions/exceptions.py b/tuxbot/cogs/Tags/functions/exceptions.py index 75cea57..ec816c7 100644 --- a/tuxbot/cogs/Tags/functions/exceptions.py +++ b/tuxbot/cogs/Tags/functions/exceptions.py @@ -11,3 +11,11 @@ class UnknownTagException(TagsException): class ExistingTagException(TagsException): pass + + +class TooLongTagException(TagsException): + pass + + +class ReservedTagException(TagsException): + pass diff --git a/tuxbot/cogs/Tags/functions/utils.py b/tuxbot/cogs/Tags/functions/utils.py index 5cc9aeb..3b3197b 100644 --- a/tuxbot/cogs/Tags/functions/utils.py +++ b/tuxbot/cogs/Tags/functions/utils.py @@ -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): diff --git a/tuxbot/cogs/Tags/locales/en-US.po b/tuxbot/cogs/Tags/locales/en-US.po index 8e55f4e..dcb1539 100644 --- a/tuxbot/cogs/Tags/locales/en-US.po +++ b/tuxbot/cogs/Tags/locales/en-US.po @@ -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 "" diff --git a/tuxbot/cogs/Tags/locales/fr-FR.po b/tuxbot/cogs/Tags/locales/fr-FR.po index cdd4578..5de6cb6 100644 --- a/tuxbot/cogs/Tags/locales/fr-FR.po +++ b/tuxbot/cogs/Tags/locales/fr-FR.po @@ -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" diff --git a/tuxbot/cogs/Tags/locales/messages.pot b/tuxbot/cogs/Tags/locales/messages.pot index e0a32fa..c8c68d0 100644 --- a/tuxbot/cogs/Tags/locales/messages.pot +++ b/tuxbot/cogs/Tags/locales/messages.pot @@ -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 \n" "Language-Team: LANGUAGE \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 "" diff --git a/tuxbot/cogs/Tags/tags.py b/tuxbot/cogs/Tags/tags.py index 304eb9c..919aae8 100644 --- a/tuxbot/cogs/Tags/tags.py +++ b/tuxbot/cogs/Tags/tags.py @@ -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)) diff --git a/tuxbot/cogs/Utils/locales/messages.pot b/tuxbot/cogs/Utils/locales/messages.pot index 3a641a7..5262488 100644 --- a/tuxbot/cogs/Utils/locales/messages.pot +++ b/tuxbot/cogs/Utils/locales/messages.pot @@ -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 \n" "Language-Team: LANGUAGE \n" diff --git a/tuxbot/core/utils/functions/extra.py b/tuxbot/core/utils/functions/extra.py index e103779..f023cb5 100644 --- a/tuxbot/core/utils/functions/extra.py +++ b/tuxbot/core/utils/functions/extra.py @@ -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