feat(commands:*|Mod): first commit

This commit is contained in:
Romain J 2021-05-13 16:45:49 +02:00
parent 4678be191d
commit 4e3fbd7f4d
17 changed files with 160 additions and 71 deletions

View file

@ -1,6 +1,5 @@
import logging import logging
import discord
from discord.ext import commands from discord.ext import commands
from tuxbot.core.utils import checks 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.config import Config
from tuxbot.core.i18n import ( from tuxbot.core.i18n import (
Translator, Translator,
find_locale,
get_locale_name,
list_locales,
) )
from tuxbot.core.utils.functions.extra import ( from tuxbot.core.utils.functions.extra import (
group_extra,
command_extra, command_extra,
ContextPlus, 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) @command_extra(name="quit", aliases=["shutdown"], deletable=False)
@checks.is_owner() @checks.is_owner()
async def _quit(self, ctx: ContextPlus): async def _quit(self, ctx: ContextPlus):

View file

@ -2,7 +2,7 @@ from typing import Dict
from structured_config import Structure from structured_config import Structure
HAS_MODELS = True HAS_MODELS = False
class AdminConfig(Structure): class AdminConfig(Structure):

View file

@ -16,12 +16,3 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\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 ""

View file

@ -17,12 +17,3 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\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 : "

View file

@ -16,12 +16,3 @@ msgstr ""
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\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 ""

View file

@ -1,2 +0,0 @@
from .alias import *
from .warns import *

View file

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

12
tuxbot/cogs/Mod/config.py Normal file
View file

@ -0,0 +1,12 @@
from typing import Dict
from structured_config import Structure
HAS_MODELS = True
class ModConfig(Structure):
pass
extra: Dict[str, Dict] = {}

View file

View file

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

View file

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Tuxbot-bot\n" "Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\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" "PO-Revision-Date: 2020-06-10 00:38+0200\n"
"Last-Translator: Automatically generated\n" "Last-Translator: Automatically generated\n"
"Language-Team: none\n" "Language-Team: none\n"
@ -22,6 +22,6 @@ msgstr ""
msgid "Locale changed to {lang} successfully" msgid "Locale changed to {lang} successfully"
msgstr "" msgstr ""
#: tuxbot/cogs/Admin/admin.py:65 #: tuxbot/cogs/Admin/admin.py:61
msgid "List of available locales: " msgid "List of available locales: "
msgstr "" msgstr ""

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Tuxbot-bot\n" "Project-Id-Version: Tuxbot-bot\n"
"Report-Msgid-Bugs-To: rick@gnous.eu\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" "PO-Revision-Date: 2020-06-10 00:38+0200\n"
"Last-Translator: Automatically generated\n" "Last-Translator: Automatically generated\n"
"Language-Team: none\n" "Language-Team: none\n"
@ -23,6 +23,6 @@ msgstr ""
msgid "Locale changed to {lang} successfully" msgid "Locale changed to {lang} successfully"
msgstr "Langue changée pour {lang} avec succès" 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: " msgid "List of available locales: "
msgstr "Liste des langues disponibles : " msgstr "Liste des langues disponibles : "

View file

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

60
tuxbot/cogs/Mod/mod.py Normal file
View file

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

View file

@ -0,0 +1 @@
from .warns import *

View file

@ -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"<Warn id={self.id} "
f"server_id={self.server_id} "
f"user_id={self.user_id} "
f"reason='{self.reason}' "
f"created_at={self.created_at}>"
)
__repr__ = __str__

View file

@ -43,6 +43,7 @@ packages: Tuple = (
"tuxbot.cogs.Custom", "tuxbot.cogs.Custom",
"tuxbot.cogs.Network", "tuxbot.cogs.Network",
"tuxbot.cogs.Linux", "tuxbot.cogs.Linux",
"tuxbot.cogs.Mod",
) )