From 4c72f07e8e3d3f34fe302adcb0edf5306e4d0ebb Mon Sep 17 00:00:00 2001 From: Romain J Date: Sat, 15 May 2021 21:36:30 +0200 Subject: [PATCH] feat(commands:rule>update|Mod): feat way to update rule messages --- tuxbot/cogs/Custom/locales/messages.pot | 2 +- tuxbot/cogs/Linux/locales/messages.pot | 2 +- tuxbot/cogs/Logs/locales/messages.pot | 2 +- tuxbot/cogs/Mod/functions/converters.py | 17 ++++++++ tuxbot/cogs/Mod/functions/exceptions.py | 8 ++++ tuxbot/cogs/Mod/locales/en-US.po | 8 ++++ tuxbot/cogs/Mod/locales/fr-FR.po | 7 ++++ tuxbot/cogs/Mod/locales/messages.pot | 35 ++++++++++------ tuxbot/cogs/Mod/mod.py | 51 +++++++++++++++++++++++- tuxbot/cogs/Network/locales/messages.pot | 2 +- tuxbot/cogs/Polls/locales/messages.pot | 2 +- tuxbot/cogs/Utils/locales/messages.pot | 2 +- 12 files changed, 118 insertions(+), 20 deletions(-) diff --git a/tuxbot/cogs/Custom/locales/messages.pot b/tuxbot/cogs/Custom/locales/messages.pot index 8ab1a8c..1a89c56 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-13 23:12+0200\n" +"POT-Creation-Date: 2021-05-15 21:32+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 ed6cb82..465dd15 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-13 23:12+0200\n" +"POT-Creation-Date: 2021-05-15 21:32+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 1e16c10..76c59f0 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-13 23:12+0200\n" +"POT-Creation-Date: 2021-05-15 21:32+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/functions/converters.py b/tuxbot/cogs/Mod/functions/converters.py index 64e68be..f8c4c53 100644 --- a/tuxbot/cogs/Mod/functions/converters.py +++ b/tuxbot/cogs/Mod/functions/converters.py @@ -4,6 +4,8 @@ from discord.ext.commands import Context from tuxbot.cogs.Mod.functions.exceptions import ( RuleTooLongException, UnknownRuleException, + NonMessageException, + NonBotMessageException, ) from tuxbot.cogs.Mod.models import Rule @@ -35,3 +37,18 @@ class RuleConverter(commands.Converter): ) return argument + + +class BotMessageConverter(commands.Converter): + async def convert(self, ctx: Context, argument: str): # skipcq: PYL-W0613 + try: + m = await commands.MessageConverter().convert(ctx, argument) + + if m.author == ctx.me: + return m + + raise NonBotMessageException(_("Please provide one of my message")) + except commands.BadArgument: + raise NonMessageException( + _("Please provide a message in this guild") + ) diff --git a/tuxbot/cogs/Mod/functions/exceptions.py b/tuxbot/cogs/Mod/functions/exceptions.py index 5f48419..2b87bcc 100644 --- a/tuxbot/cogs/Mod/functions/exceptions.py +++ b/tuxbot/cogs/Mod/functions/exceptions.py @@ -11,3 +11,11 @@ class RuleTooLongException(ModException): class UnknownRuleException(ModException): pass + + +class NonMessageException(ModException): + pass + + +class NonBotMessageException(ModException): + pass diff --git a/tuxbot/cogs/Mod/locales/en-US.po b/tuxbot/cogs/Mod/locales/en-US.po index a4ab532..94d9c5f 100644 --- a/tuxbot/cogs/Mod/locales/en-US.po +++ b/tuxbot/cogs/Mod/locales/en-US.po @@ -73,3 +73,11 @@ msgstr "" #: tuxbot/cogs/Mod/functions/converters.py:31 msgid "Rule length must be 300 characters or lower." msgstr "" + +#: tuxbot/cogs/Mod/functions/converters.py:50 +msgid "Please provide one of my message" +msgstr "" + +#: tuxbot/cogs/Mod/functions/converters.py:53 +msgid "Please provide a message in this guild" +msgstr "" diff --git a/tuxbot/cogs/Mod/locales/fr-FR.po b/tuxbot/cogs/Mod/locales/fr-FR.po index 6d8ba40..2f391d6 100644 --- a/tuxbot/cogs/Mod/locales/fr-FR.po +++ b/tuxbot/cogs/Mod/locales/fr-FR.po @@ -83,3 +83,10 @@ msgstr "Règle inconnue" msgid "Rule length must be 300 characters or lower." msgstr "La règles doit faire 300 characters ou moins" +#: tuxbot/cogs/Mod/functions/converters.py:50 +msgid "Please provide one of my message" +msgstr "Merci de donner un de mes messages" + +#: tuxbot/cogs/Mod/functions/converters.py:53 +msgid "Please provide a message in this guild" +msgstr "Merci de donner un message dans ce serveur" \ No newline at end of file diff --git a/tuxbot/cogs/Mod/locales/messages.pot b/tuxbot/cogs/Mod/locales/messages.pot index 056c1db..d1769bd 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-13 23:12+0200\n" +"POT-Creation-Date: 2021-05-15 21:32+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,59 +17,68 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: tuxbot/cogs/Mod/mod.py:67 +#: tuxbot/cogs/Mod/mod.py:71 #, python-brace-format msgid "Locale changed to {lang} successfully" msgstr "" -#: tuxbot/cogs/Mod/mod.py:78 +#: tuxbot/cogs/Mod/mod.py:82 msgid "List of available locales: " msgstr "" -#: tuxbot/cogs/Mod/mod.py:103 +#: tuxbot/cogs/Mod/mod.py:107 msgid "" "{}please read the following rule: \n" "{}" msgstr "" -#: tuxbot/cogs/Mod/mod.py:121 +#: tuxbot/cogs/Mod/mod.py:125 tuxbot/cogs/Mod/mod.py:225 msgid "No rules found for this server" msgstr "" -#: tuxbot/cogs/Mod/mod.py:125 +#: tuxbot/cogs/Mod/mod.py:129 tuxbot/cogs/Mod/mod.py:229 msgid "Rules for {}" msgstr "" -#: tuxbot/cogs/Mod/mod.py:131 +#: tuxbot/cogs/Mod/mod.py:135 tuxbot/cogs/Mod/mod.py:235 msgid "Latest change: {}" msgstr "" -#: tuxbot/cogs/Mod/mod.py:145 +#: tuxbot/cogs/Mod/mod.py:149 tuxbot/cogs/Mod/mod.py:249 msgid "Rules for {} ({}/{})" msgstr "" -#: tuxbot/cogs/Mod/mod.py:164 +#: tuxbot/cogs/Mod/mod.py:168 msgid "" "Following rule added: \n" "{}" msgstr "" -#: tuxbot/cogs/Mod/mod.py:187 +#: tuxbot/cogs/Mod/mod.py:191 msgid "" "Following rule updated: \n" "{}" msgstr "" -#: tuxbot/cogs/Mod/mod.py:205 +#: tuxbot/cogs/Mod/mod.py:209 msgid "" "Following rule deleted: \n" "{}" msgstr "" -#: tuxbot/cogs/Mod/functions/converters.py:22 +#: tuxbot/cogs/Mod/functions/converters.py:20 +#: tuxbot/cogs/Mod/functions/converters.py:27 msgid "Unknown rule" msgstr "" -#: tuxbot/cogs/Mod/functions/converters.py:31 +#: tuxbot/cogs/Mod/functions/converters.py:36 msgid "Rule length must be 300 characters or lower." msgstr "" + +#: tuxbot/cogs/Mod/functions/converters.py:50 +msgid "Please provide one of my message" +msgstr "" + +#: tuxbot/cogs/Mod/functions/converters.py:53 +msgid "Please provide a message in this guild" +msgstr "" diff --git a/tuxbot/cogs/Mod/mod.py b/tuxbot/cogs/Mod/mod.py index 0f40f6e..2ae0202 100644 --- a/tuxbot/cogs/Mod/mod.py +++ b/tuxbot/cogs/Mod/mod.py @@ -4,10 +4,16 @@ from datetime import datetime import discord from discord.ext import commands -from tuxbot.cogs.Mod.functions.converters import RuleConverter, RuleIDConverter +from tuxbot.cogs.Mod.functions.converters import ( + RuleConverter, + RuleIDConverter, + BotMessageConverter, +) from tuxbot.cogs.Mod.functions.exceptions import ( RuleTooLongException, UnknownRuleException, + NonMessageException, + NonBotMessageException, ) from tuxbot.cogs.Mod.functions.utils import ( save_lang, @@ -45,6 +51,8 @@ class Mod(commands.Cog): ( RuleTooLongException, UnknownRuleException, + NonMessageException, + NonBotMessageException, ), ): await ctx.send(_(str(error), ctx, self.bot.config)) @@ -206,3 +214,44 @@ class Mod(commands.Cog): format_rule(rule_row) ) ) + + @checks.is_admin() + @_rule.command(name="update") + async def _rule_update( + self, + ctx: ContextPlus, + message: BotMessageConverter, + ): + rules = await get_server_rules(ctx.guild.id) + + if not rules: + return await ctx.send( + _("No rules found for this server", ctx, self.bot.config) + ) + + embed = discord.Embed( + title=_("Rules for {}", ctx, self.bot.config).format( + ctx.guild.name + ), + color=discord.Color.blue(), + ) + embed.set_footer( + text=_("Latest change: {}", ctx, self.bot.config).format( + get_most_recent_server_rules(rules).updated_at.ctime() + ) + ) + + pages = paginate_server_rules(rules) + + if len(pages) == 1: + embed.description = pages[0] + + await message.edit(content="", embed=embed) + else: + for i, page in enumerate(pages): + embed.title = _( + "Rules for {} ({}/{})", ctx, self.bot.config + ).format(ctx.guild.name, str(i + 1), str(len(pages))) + embed.description = page + + await message.edit(content="", embed=embed) diff --git a/tuxbot/cogs/Network/locales/messages.pot b/tuxbot/cogs/Network/locales/messages.pot index 484b44a..d4953b9 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-13 23:12+0200\n" +"POT-Creation-Date: 2021-05-15 21:32+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 fb562a3..329e906 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-13 23:12+0200\n" +"POT-Creation-Date: 2021-05-15 21:32+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/Utils/locales/messages.pot b/tuxbot/cogs/Utils/locales/messages.pot index 5d5eb2c..098c9a3 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-13 23:12+0200\n" +"POT-Creation-Date: 2021-05-15 21:32+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n"