feat(lang): done lang switcher
This commit is contained in:
parent
888a7924be
commit
554ec46413
5 changed files with 58 additions and 36 deletions
|
@ -3,30 +3,43 @@
|
|||
<words>
|
||||
<w>anglais</w>
|
||||
<w>appdirs</w>
|
||||
<w>apres</w>
|
||||
<w>asctime</w>
|
||||
<w>commandstats</w>
|
||||
<w>ctype</w>
|
||||
<w>debian</w>
|
||||
<w>découverte</w>
|
||||
<w>fonction</w>
|
||||
<w>francais</w>
|
||||
<w>français</w>
|
||||
<w>gnous</w>
|
||||
<w>ipinfo</w>
|
||||
<w>iplocalise</w>
|
||||
<w>jishaku</w>
|
||||
<w>langue</w>
|
||||
<w>levelname</w>
|
||||
<w>liste</w>
|
||||
<w>localiseip</w>
|
||||
<w>octobre</w>
|
||||
<w>pacman</w>
|
||||
<w>postgresql</w>
|
||||
<w>pred</w>
|
||||
<w>pylint</w>
|
||||
<w>releaselevel</w>
|
||||
<w>rprint</w>
|
||||
<w>socketstats</w>
|
||||
<w>soit</w>
|
||||
<w>splt</w>
|
||||
<w>suivante</w>
|
||||
<w>systemd</w>
|
||||
<w>tldr</w>
|
||||
<w>tutux</w>
|
||||
<w>tuxbot</w>
|
||||
<w>tuxbot's</w>
|
||||
<w>tuxvenv</w>
|
||||
<w>venv</w>
|
||||
<w>webhooks</w>
|
||||
<w>écrite</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
|
@ -2,6 +2,8 @@
|
|||
good-names=
|
||||
e, # (exception) as e
|
||||
f, # (file) as f
|
||||
k, # for k, v in
|
||||
v, # for k, v in
|
||||
|
||||
[MASTER]
|
||||
disable=
|
||||
|
|
|
@ -28,7 +28,7 @@ Arch Linux
|
|||
|
||||
$ sudo pacman -Syu python python-pip python-virtualenv git
|
||||
|
||||
Continue to `create the venv <#creating-the-virtual-environnement>`__.
|
||||
Continue to `create the venv <#creating-the-virtual-environment>`__.
|
||||
|
||||
--------------
|
||||
|
||||
|
@ -40,7 +40,7 @@ Debian
|
|||
$ sudo apt update
|
||||
$ sudo apt -y install python3 python3-dev python3-pip python3-venv git
|
||||
|
||||
Continue to `create the venv <#creating-the-virtual-environnement>`__.
|
||||
Continue to `create the venv <#creating-the-virtual-environment>`__.
|
||||
|
||||
--------------
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ from discord.ext import commands
|
|||
|
||||
from tuxbot.core import checks
|
||||
from tuxbot.core.bot import Tux
|
||||
from tuxbot.core.config import set_for
|
||||
from tuxbot.core.config import Config
|
||||
from tuxbot.core.i18n import (
|
||||
Translator,
|
||||
find_locale,
|
||||
|
@ -26,7 +28,9 @@ class Admin(commands.Cog, name="Admin"):
|
|||
self.bot = bot
|
||||
|
||||
async def _save_lang(self, ctx: ContextPlus, lang: str):
|
||||
self.bot.config.Servers.all[ctx.guild.id].locale = lang
|
||||
set_for(
|
||||
self.bot.config.Servers, ctx.guild.id, Config.Server, locale=lang
|
||||
)
|
||||
|
||||
@group_extra(name="lang", aliases=["locale", "langue"], deletable=True)
|
||||
@commands.guild_only()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import logging
|
||||
from typing import List, Dict
|
||||
from typing import List, Dict, Any
|
||||
from structured_config import (
|
||||
Structure,
|
||||
IntField,
|
||||
|
@ -9,39 +9,35 @@ from structured_config import (
|
|||
)
|
||||
|
||||
|
||||
__all__ = ["Config", "ConfigFile", "search_for"]
|
||||
__all__ = ["Config", "ConfigFile", "search_for", "set_for"]
|
||||
|
||||
log = logging.getLogger("tuxbot.core.config")
|
||||
|
||||
|
||||
class Server(Structure):
|
||||
class Config(Structure):
|
||||
class Server(Structure):
|
||||
prefixes: List[str] = []
|
||||
disabled_command: List[str] = []
|
||||
locale: str = StrField("")
|
||||
blacklisted: bool = BoolField(False)
|
||||
|
||||
|
||||
class Channel(Structure):
|
||||
class Channel(Structure):
|
||||
disabled_command: List[str] = []
|
||||
locale: str = StrField("")
|
||||
blacklisted: bool = BoolField(False)
|
||||
|
||||
|
||||
class User(Structure):
|
||||
class User(Structure):
|
||||
aliases: List[dict] = []
|
||||
locale: str = StrField("")
|
||||
blacklisted: bool = BoolField(False)
|
||||
|
||||
class Cog(Structure):
|
||||
pass
|
||||
|
||||
class Config(Structure):
|
||||
class Servers(Structure):
|
||||
all: Dict[int, Server] = {}
|
||||
|
||||
class Channels(Structure):
|
||||
all: Dict[int, Channel] = {}
|
||||
|
||||
class Users(Structure):
|
||||
all: Dict[int, User] = {}
|
||||
Servers: Dict[int, Server] = {}
|
||||
Channels: Dict[int, Channel] = {}
|
||||
Users: Dict[int, User] = {}
|
||||
Cogs: Dict[str, Cog] = {}
|
||||
|
||||
class Core(Structure):
|
||||
owners_id: List[int] = []
|
||||
|
@ -51,9 +47,6 @@ class Config(Structure):
|
|||
locale: str = StrField("")
|
||||
disabled_command: List[str] = []
|
||||
|
||||
class Cogs(Structure):
|
||||
pass
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Configuration of Tuxbot Application (not the bot)
|
||||
|
@ -74,7 +67,17 @@ class AppConfig(Structure):
|
|||
# =============================================================================
|
||||
|
||||
|
||||
def search_for(config, key, value, default=False):
|
||||
if key in config.all:
|
||||
return getattr(config.all[key], value)
|
||||
def search_for(config, key, value, default=False) -> Any:
|
||||
if key in config:
|
||||
return getattr(config[key], value)
|
||||
return default
|
||||
|
||||
|
||||
# la fonction suivante a été écrite le lundi 19 octobre 2020 à 13h49 soit 1h
|
||||
# apres la découverte de mon chat, rip roxy, 201?-2020 :'(
|
||||
def set_for(config, key, ctype, **values) -> Any:
|
||||
if key not in config:
|
||||
config[key] = ctype()
|
||||
|
||||
for k, v in values.items():
|
||||
setattr(config[key], k, v)
|
||||
|
|
Loading…
Reference in a new issue