feat(commands:rule>update|Mod): feat way to update rule messages

This commit is contained in:
Romain J 2021-05-15 21:36:30 +02:00
parent 5afadb0f25
commit 4c72f07e8e
12 changed files with 118 additions and 20 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-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 <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-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 <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-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 <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.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")
)

View file

@ -11,3 +11,11 @@ class RuleTooLongException(ModException):
class UnknownRuleException(ModException):
pass
class NonMessageException(ModException):
pass
class NonBotMessageException(ModException):
pass

View file

@ -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 ""

View file

@ -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"

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-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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

View file

@ -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)

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-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 <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-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 <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-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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"