diff --git a/tuxbot/cogs/Admin/admin.py b/tuxbot/cogs/Admin/admin.py index b771043..3219717 100644 --- a/tuxbot/cogs/Admin/admin.py +++ b/tuxbot/cogs/Admin/admin.py @@ -1,6 +1,5 @@ import logging -import discord from discord.ext import commands from tuxbot.core.utils import checks @@ -9,12 +8,8 @@ from tuxbot.core.config import set_for_key from tuxbot.core.config import Config from tuxbot.core.i18n import ( Translator, - find_locale, - get_locale_name, - list_locales, ) from tuxbot.core.utils.functions.extra import ( - group_extra, command_extra, ContextPlus, ) @@ -35,38 +30,6 @@ class Admin(commands.Cog): # ========================================================================= # ========================================================================= - @group_extra(name="lang", aliases=["locale", "langue"], deletable=True) - @commands.guild_only() - @checks.is_admin() - async def _lang(self, ctx: ContextPlus): - """Manage lang settings.""" - - @_lang.command(name="set", aliases=["define", "choice"]) - async def _lang_set(self, ctx: ContextPlus, lang: str): - try: - await self._save_lang(ctx, find_locale(lang.lower())) - await ctx.send( - _( - "Locale changed to {lang} successfully", - ctx, - self.bot.config, - ).format(lang=f"`{get_locale_name(lang).lower()}`") - ) - except NotImplementedError: - await self._lang_list(ctx) - - @_lang.command(name="list", aliases=["liste", "all", "view"]) - async def _lang_list(self, ctx: ContextPlus): - e = discord.Embed( - title=_("List of available locales: ", ctx, self.bot.config), - description=list_locales, - color=0x36393E, - ) - - await ctx.send(embed=e) - - # ========================================================================= - @command_extra(name="quit", aliases=["shutdown"], deletable=False) @checks.is_owner() async def _quit(self, ctx: ContextPlus): diff --git a/tuxbot/cogs/Admin/config.py b/tuxbot/cogs/Admin/config.py index 8702f08..ea96572 100644 --- a/tuxbot/cogs/Admin/config.py +++ b/tuxbot/cogs/Admin/config.py @@ -2,7 +2,7 @@ from typing import Dict from structured_config import Structure -HAS_MODELS = True +HAS_MODELS = False class AdminConfig(Structure): diff --git a/tuxbot/cogs/Admin/locales/en-US.po b/tuxbot/cogs/Admin/locales/en-US.po index 89e4b2f..eaec822 100644 --- a/tuxbot/cogs/Admin/locales/en-US.po +++ b/tuxbot/cogs/Admin/locales/en-US.po @@ -16,12 +16,3 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" - -#: tuxbot/cogs/Admin/admin.py:50 -#, python-brace-format -msgid "Locale changed to {lang} successfully" -msgstr "" - -#: tuxbot/cogs/Admin/admin.py:61 -msgid "List of available locales: " -msgstr "" diff --git a/tuxbot/cogs/Admin/locales/fr-FR.po b/tuxbot/cogs/Admin/locales/fr-FR.po index eb80950..a5f7a9f 100644 --- a/tuxbot/cogs/Admin/locales/fr-FR.po +++ b/tuxbot/cogs/Admin/locales/fr-FR.po @@ -17,12 +17,3 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" - -#: tuxbot/cogs/Admin/admin.py:50 -#, fuzzy, python-brace-format -msgid "Locale changed to {lang} successfully" -msgstr "Langue changée pour {lang} avec succès" - -#: tuxbot/cogs/Admin/admin.py:61 -msgid "List of available locales: " -msgstr "Liste des langues disponibles : " diff --git a/tuxbot/cogs/Admin/locales/messages.pot b/tuxbot/cogs/Admin/locales/messages.pot index 827fcdc..eda546e 100644 --- a/tuxbot/cogs/Admin/locales/messages.pot +++ b/tuxbot/cogs/Admin/locales/messages.pot @@ -16,12 +16,3 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" - -#: tuxbot/cogs/Admin/admin.py:50 -#, python-brace-format -msgid "Locale changed to {lang} successfully" -msgstr "" - -#: tuxbot/cogs/Admin/admin.py:61 -msgid "List of available locales: " -msgstr "" diff --git a/tuxbot/cogs/Admin/models/__init__.py b/tuxbot/cogs/Admin/models/__init__.py index 7b6f395..e69de29 100644 --- a/tuxbot/cogs/Admin/models/__init__.py +++ b/tuxbot/cogs/Admin/models/__init__.py @@ -1,2 +0,0 @@ -from .alias import * -from .warns import * diff --git a/tuxbot/cogs/Mod/__init__.py b/tuxbot/cogs/Mod/__init__.py new file mode 100644 index 0000000..a6e6eb3 --- /dev/null +++ b/tuxbot/cogs/Mod/__init__.py @@ -0,0 +1,19 @@ +from collections import namedtuple + +from tuxbot.core.bot import Tux +from .mod import Mod +from .config import ModConfig, HAS_MODELS + +VersionInfo = namedtuple("VersionInfo", "major minor micro release_level") +version_info = VersionInfo(major=1, minor=0, micro=0, release_level="alpha") + +__version__ = "v{}.{}.{}-{}".format( + version_info.major, + version_info.minor, + version_info.micro, + version_info.release_level, +).replace("\n", "") + + +def setup(bot: Tux): + bot.add_cog(Mod(bot)) diff --git a/tuxbot/cogs/Mod/config.py b/tuxbot/cogs/Mod/config.py new file mode 100644 index 0000000..0f95d9f --- /dev/null +++ b/tuxbot/cogs/Mod/config.py @@ -0,0 +1,12 @@ +from typing import Dict + +from structured_config import Structure + +HAS_MODELS = True + + +class ModConfig(Structure): + pass + + +extra: Dict[str, Dict] = {} diff --git a/tuxbot/cogs/Mod/functions/__init__.py b/tuxbot/cogs/Mod/functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tuxbot/cogs/Mod/functions/utils.py b/tuxbot/cogs/Mod/functions/utils.py new file mode 100644 index 0000000..97cf551 --- /dev/null +++ b/tuxbot/cogs/Mod/functions/utils.py @@ -0,0 +1,11 @@ +from tuxbot.core.config import set_for_key +from tuxbot.core.config import Config + +from tuxbot.core.bot import Tux +from tuxbot.core.utils.functions.extra import ContextPlus + + +async def save_lang(bot: Tux, ctx: ContextPlus, lang: str): + set_for_key( + bot.config.Servers, ctx.guild.id, Config.Server, locale=lang + ) diff --git a/tuxbot/cogs/Admin/locales/en-US.po~ b/tuxbot/cogs/Mod/locales/en-US.po similarity index 90% rename from tuxbot/cogs/Admin/locales/en-US.po~ rename to tuxbot/cogs/Mod/locales/en-US.po index 25a4a1e..89e4b2f 100644 --- a/tuxbot/cogs/Admin/locales/en-US.po~ +++ b/tuxbot/cogs/Mod/locales/en-US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Tuxbot-bot\n" "Report-Msgid-Bugs-To: rick@gnous.eu\n" -"POT-Creation-Date: 2020-11-11 02:40+0100\n" +"POT-Creation-Date: 2021-01-19 14:42+0100\n" "PO-Revision-Date: 2020-06-10 00:38+0200\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -22,6 +22,6 @@ msgstr "" msgid "Locale changed to {lang} successfully" msgstr "" -#: tuxbot/cogs/Admin/admin.py:65 +#: tuxbot/cogs/Admin/admin.py:61 msgid "List of available locales: " msgstr "" diff --git a/tuxbot/cogs/Admin/locales/fr-FR.po~ b/tuxbot/cogs/Mod/locales/fr-FR.po similarity index 91% rename from tuxbot/cogs/Admin/locales/fr-FR.po~ rename to tuxbot/cogs/Mod/locales/fr-FR.po index 2b14077..eb80950 100644 --- a/tuxbot/cogs/Admin/locales/fr-FR.po~ +++ b/tuxbot/cogs/Mod/locales/fr-FR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Tuxbot-bot\n" "Report-Msgid-Bugs-To: rick@gnous.eu\n" -"POT-Creation-Date: 2020-11-11 02:40+0100\n" +"POT-Creation-Date: 2021-01-19 14:42+0100\n" "PO-Revision-Date: 2020-06-10 00:38+0200\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -23,6 +23,6 @@ msgstr "" msgid "Locale changed to {lang} successfully" msgstr "Langue changée pour {lang} avec succès" -#: tuxbot/cogs/Admin/admin.py:65 +#: tuxbot/cogs/Admin/admin.py:61 msgid "List of available locales: " msgstr "Liste des langues disponibles : " diff --git a/tuxbot/cogs/Mod/locales/messages.pot b/tuxbot/cogs/Mod/locales/messages.pot new file mode 100644 index 0000000..827fcdc --- /dev/null +++ b/tuxbot/cogs/Mod/locales/messages.pot @@ -0,0 +1,27 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the Tuxbot-bot package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: Tuxbot-bot\n" +"Report-Msgid-Bugs-To: rick@gnous.eu\n" +"POT-Creation-Date: 2021-03-01 14:59+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: tuxbot/cogs/Admin/admin.py:50 +#, python-brace-format +msgid "Locale changed to {lang} successfully" +msgstr "" + +#: tuxbot/cogs/Admin/admin.py:61 +msgid "List of available locales: " +msgstr "" diff --git a/tuxbot/cogs/Mod/mod.py b/tuxbot/cogs/Mod/mod.py new file mode 100644 index 0000000..d2c3481 --- /dev/null +++ b/tuxbot/cogs/Mod/mod.py @@ -0,0 +1,60 @@ +import logging + +import discord +from discord.ext import commands + +from tuxbot.cogs.Mod.functions.utils import save_lang +from tuxbot.core.utils import checks +from tuxbot.core.bot import Tux + +from tuxbot.core.i18n import ( + Translator, + find_locale, + get_locale_name, + list_locales, +) +from tuxbot.core.utils.functions.extra import ( + group_extra, + ContextPlus, +) + +log = logging.getLogger("tuxbot.cogs.Mod") +_ = Translator("Mod", __file__) + + +class Mod(commands.Cog): + def __init__(self, bot: Tux): + self.bot = bot + + # ========================================================================= + # ========================================================================= + + @group_extra(name="lang", aliases=["locale", "langue"], deletable=True) + @commands.guild_only() + @checks.is_admin() + async def _lang(self, ctx: ContextPlus): + """Manage lang settings.""" + + @_lang.command(name="set", aliases=["define", "choice"]) + async def _lang_set(self, ctx: ContextPlus, lang: str): + try: + await save_lang(self.bot, ctx, find_locale(lang.lower())) + await ctx.send( + _( + "Locale changed to {lang} successfully", + ctx, + self.bot.config, + ).format(lang=f"`{get_locale_name(lang).lower()}`") + ) + except NotImplementedError: + await self._lang_list(ctx) + + @_lang.command(name="list", aliases=["liste", "all", "view"]) + async def _lang_list(self, ctx: ContextPlus): + e = discord.Embed( + title=_("List of available locales: ", ctx, self.bot.config), + description=list_locales(), + color=0x36393E, + ) + + await ctx.send(embed=e) diff --git a/tuxbot/cogs/Mod/models/__init__.py b/tuxbot/cogs/Mod/models/__init__.py new file mode 100644 index 0000000..bc90900 --- /dev/null +++ b/tuxbot/cogs/Mod/models/__init__.py @@ -0,0 +1 @@ +from .warns import * diff --git a/tuxbot/cogs/Mod/models/warns.py b/tuxbot/cogs/Mod/models/warns.py new file mode 100644 index 0000000..4bda9fc --- /dev/null +++ b/tuxbot/cogs/Mod/models/warns.py @@ -0,0 +1,24 @@ +import tortoise +from tortoise import fields + + +class Warn(tortoise.Model): + id = fields.BigIntField(pk=True) + server_id = fields.BigIntField() + user_id = fields.BigIntField() + reason = fields.TextField(max_length=255) + created_at = fields.DatetimeField() + + class Meta: + table = "warns" + + def __str__(self): + return ( + f"" + ) + + __repr__ = __str__ diff --git a/tuxbot/core/bot.py b/tuxbot/core/bot.py index b8aa209..f425a08 100644 --- a/tuxbot/core/bot.py +++ b/tuxbot/core/bot.py @@ -43,6 +43,7 @@ packages: Tuple = ( "tuxbot.cogs.Custom", "tuxbot.cogs.Network", "tuxbot.cogs.Linux", + "tuxbot.cogs.Mod", )