feat(lang): done lang switcher

This commit is contained in:
Romain J 2020-10-19 15:04:10 +02:00
parent 888a7924be
commit 554ec46413
5 changed files with 58 additions and 36 deletions

View file

@ -3,30 +3,43 @@
<words> <words>
<w>anglais</w> <w>anglais</w>
<w>appdirs</w> <w>appdirs</w>
<w>apres</w>
<w>asctime</w> <w>asctime</w>
<w>commandstats</w> <w>commandstats</w>
<w>ctype</w>
<w>debian</w>
<w>découverte</w>
<w>fonction</w>
<w>francais</w> <w>francais</w>
<w>français</w> <w>français</w>
<w>gnous</w> <w>gnous</w>
<w>ipinfo</w> <w>ipinfo</w>
<w>iplocalise</w> <w>iplocalise</w>
<w>jishaku</w> <w>jishaku</w>
<w>langue</w>
<w>levelname</w> <w>levelname</w>
<w>liste</w>
<w>localiseip</w> <w>localiseip</w>
<w>octobre</w>
<w>pacman</w>
<w>postgresql</w> <w>postgresql</w>
<w>pred</w> <w>pred</w>
<w>pylint</w> <w>pylint</w>
<w>releaselevel</w> <w>releaselevel</w>
<w>rprint</w> <w>rprint</w>
<w>socketstats</w> <w>socketstats</w>
<w>soit</w>
<w>splt</w> <w>splt</w>
<w>suivante</w>
<w>systemd</w> <w>systemd</w>
<w>tldr</w> <w>tldr</w>
<w>tutux</w> <w>tutux</w>
<w>tuxbot</w> <w>tuxbot</w>
<w>tuxbot's</w> <w>tuxbot's</w>
<w>tuxvenv</w> <w>tuxvenv</w>
<w>venv</w>
<w>webhooks</w> <w>webhooks</w>
<w>écrite</w>
</words> </words>
</dictionary> </dictionary>
</component> </component>

View file

@ -2,6 +2,8 @@
good-names= good-names=
e, # (exception) as e e, # (exception) as e
f, # (file) as f f, # (file) as f
k, # for k, v in
v, # for k, v in
[MASTER] [MASTER]
disable= disable=

View file

@ -28,7 +28,7 @@ Arch Linux
$ sudo pacman -Syu python python-pip python-virtualenv git $ 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 update
$ sudo apt -y install python3 python3-dev python3-pip python3-venv git $ 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>`__.
-------------- --------------

View file

@ -5,6 +5,8 @@ from discord.ext import commands
from tuxbot.core import checks from tuxbot.core import checks
from tuxbot.core.bot import Tux from tuxbot.core.bot import Tux
from tuxbot.core.config import set_for
from tuxbot.core.config import Config
from tuxbot.core.i18n import ( from tuxbot.core.i18n import (
Translator, Translator,
find_locale, find_locale,
@ -26,7 +28,9 @@ class Admin(commands.Cog, name="Admin"):
self.bot = bot self.bot = bot
async def _save_lang(self, ctx: ContextPlus, lang: str): 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) @group_extra(name="lang", aliases=["locale", "langue"], deletable=True)
@commands.guild_only() @commands.guild_only()

View file

@ -1,5 +1,5 @@
import logging import logging
from typing import List, Dict from typing import List, Dict, Any
from structured_config import ( from structured_config import (
Structure, Structure,
IntField, 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") log = logging.getLogger("tuxbot.core.config")
class Server(Structure): class Config(Structure):
class Server(Structure):
prefixes: List[str] = [] prefixes: List[str] = []
disabled_command: List[str] = [] disabled_command: List[str] = []
locale: str = StrField("") locale: str = StrField("")
blacklisted: bool = BoolField(False) blacklisted: bool = BoolField(False)
class Channel(Structure):
class Channel(Structure):
disabled_command: List[str] = [] disabled_command: List[str] = []
locale: str = StrField("") locale: str = StrField("")
blacklisted: bool = BoolField(False) blacklisted: bool = BoolField(False)
class User(Structure):
class User(Structure):
aliases: List[dict] = [] aliases: List[dict] = []
locale: str = StrField("") locale: str = StrField("")
blacklisted: bool = BoolField(False) blacklisted: bool = BoolField(False)
class Cog(Structure):
pass
class Config(Structure): Servers: Dict[int, Server] = {}
class Servers(Structure): Channels: Dict[int, Channel] = {}
all: Dict[int, Server] = {} Users: Dict[int, User] = {}
Cogs: Dict[str, Cog] = {}
class Channels(Structure):
all: Dict[int, Channel] = {}
class Users(Structure):
all: Dict[int, User] = {}
class Core(Structure): class Core(Structure):
owners_id: List[int] = [] owners_id: List[int] = []
@ -51,9 +47,6 @@ class Config(Structure):
locale: str = StrField("") locale: str = StrField("")
disabled_command: List[str] = [] disabled_command: List[str] = []
class Cogs(Structure):
pass
# ============================================================================= # =============================================================================
# Configuration of Tuxbot Application (not the bot) # Configuration of Tuxbot Application (not the bot)
@ -74,7 +67,17 @@ class AppConfig(Structure):
# ============================================================================= # =============================================================================
def search_for(config, key, value, default=False): def search_for(config, key, value, default=False) -> Any:
if key in config.all: if key in config:
return getattr(config.all[key], value) return getattr(config[key], value)
return default 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)