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>
|
<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>
|
|
@ -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=
|
||||||
|
|
|
@ -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>`__.
|
||||||
|
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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):
|
|
||||||
prefixes: List[str] = []
|
|
||||||
disabled_command: List[str] = []
|
|
||||||
locale: str = StrField("")
|
|
||||||
blacklisted: bool = BoolField(False)
|
|
||||||
|
|
||||||
|
|
||||||
class Channel(Structure):
|
|
||||||
disabled_command: List[str] = []
|
|
||||||
locale: str = StrField("")
|
|
||||||
blacklisted: bool = BoolField(False)
|
|
||||||
|
|
||||||
|
|
||||||
class User(Structure):
|
|
||||||
aliases: List[dict] = []
|
|
||||||
locale: str = StrField("")
|
|
||||||
blacklisted: bool = BoolField(False)
|
|
||||||
|
|
||||||
|
|
||||||
class Config(Structure):
|
class Config(Structure):
|
||||||
class Servers(Structure):
|
class Server(Structure):
|
||||||
all: Dict[int, Server] = {}
|
prefixes: List[str] = []
|
||||||
|
disabled_command: List[str] = []
|
||||||
|
locale: str = StrField("")
|
||||||
|
blacklisted: bool = BoolField(False)
|
||||||
|
|
||||||
class Channels(Structure):
|
class Channel(Structure):
|
||||||
all: Dict[int, Channel] = {}
|
disabled_command: List[str] = []
|
||||||
|
locale: str = StrField("")
|
||||||
|
blacklisted: bool = BoolField(False)
|
||||||
|
|
||||||
class Users(Structure):
|
class User(Structure):
|
||||||
all: Dict[int, User] = {}
|
aliases: List[dict] = []
|
||||||
|
locale: str = StrField("")
|
||||||
|
blacklisted: bool = BoolField(False)
|
||||||
|
|
||||||
|
class Cog(Structure):
|
||||||
|
pass
|
||||||
|
|
||||||
|
Servers: Dict[int, Server] = {}
|
||||||
|
Channels: Dict[int, Channel] = {}
|
||||||
|
Users: Dict[int, User] = {}
|
||||||
|
Cogs: Dict[str, Cog] = {}
|
||||||
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue