update(extra): remove yaml for token replacement
This commit is contained in:
parent
1be4af8405
commit
888a7924be
6 changed files with 27 additions and 18 deletions
|
@ -23,7 +23,6 @@ install_requires =
|
||||||
humanize==2.6.0
|
humanize==2.6.0
|
||||||
jishaku>=1.19.1.200
|
jishaku>=1.19.1.200
|
||||||
psutil>=5.7.2
|
psutil>=5.7.2
|
||||||
pyyaml>=5.3.1
|
|
||||||
rich>=6.0.0
|
rich>=6.0.0
|
||||||
structured_config>=4.12
|
structured_config>=4.12
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ def debug_info() -> NoReturn:
|
||||||
table.add_row(f"[u]System arch:[/u] {os.uname().machine}")
|
table.add_row(f"[u]System arch:[/u] {os.uname().machine}")
|
||||||
table.add_row(f"[u]Kernel:[/u] {os.uname().release}")
|
table.add_row(f"[u]Kernel:[/u] {os.uname().release}")
|
||||||
table.add_row(f"[u]User:[/u] {os.getlogin()}")
|
table.add_row(f"[u]User:[/u] {os.getlogin()}")
|
||||||
table.add_row(f"[u]Uptime:[/u] {uptime[2]}")
|
table.add_row(f"[u]Uptime:[/u] {uptime[2][:-1]}")
|
||||||
table.add_row(
|
table.add_row(
|
||||||
f"[u]Load Average:[/u] {' '.join(map(str, os.getloadavg()))}"
|
f"[u]Load Average:[/u] {' '.join(map(str, os.getloadavg()))}"
|
||||||
)
|
)
|
||||||
|
|
|
@ -26,9 +26,7 @@ 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):
|
||||||
await self.bot.config.update(
|
self.bot.config.Servers.all[ctx.guild.id].locale = lang
|
||||||
"core", f"guild.{ctx.guild.id}.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()
|
||||||
|
|
|
@ -70,7 +70,7 @@ class AppConfig(Structure):
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Useful functions to browse configs
|
# Useful functions to interact with configs
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ from typing import Callable, Union, Dict, List
|
||||||
from babel.messages.pofile import read_po
|
from babel.messages.pofile import read_po
|
||||||
|
|
||||||
from tuxbot.core import Config
|
from tuxbot.core import Config
|
||||||
|
from tuxbot.core.config import search_for
|
||||||
from tuxbot.core.utils.functions.extra import ContextPlus
|
from tuxbot.core.utils.functions.extra import ContextPlus
|
||||||
|
|
||||||
log = logging.getLogger("tuxbot.core.i18n")
|
log = logging.getLogger("tuxbot.core.i18n")
|
||||||
|
@ -59,12 +60,19 @@ class Translator(Callable[[str], str]):
|
||||||
self, untranslated: str, ctx: ContextPlus, config: Config
|
self, untranslated: str, ctx: ContextPlus, config: Config
|
||||||
) -> str:
|
) -> str:
|
||||||
try:
|
try:
|
||||||
locale = config.get_value(
|
user_locale = search_for(
|
||||||
"core",
|
config.Users, ctx.author.id, "locale", None
|
||||||
f"guild.{ctx.guild.id}.locale",
|
|
||||||
config.get_value("core", "locale"),
|
|
||||||
)
|
)
|
||||||
return self.translations[locale][untranslated]
|
if user_locale:
|
||||||
|
return self.translations[user_locale][untranslated]
|
||||||
|
|
||||||
|
guild_locale = search_for(
|
||||||
|
config.Servers, ctx.guild.id, "locale", None
|
||||||
|
)
|
||||||
|
if guild_locale:
|
||||||
|
return self.translations[guild_locale][untranslated]
|
||||||
|
|
||||||
|
return self.translations[config.Core.locale][untranslated]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return untranslated
|
return untranslated
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import yaml
|
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord import Embed
|
from discord import Embed
|
||||||
|
@ -9,18 +8,23 @@ from rich.console import Console
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
console.clear()
|
TOKEN_REPLACEMENT = "whoops, leaked token"
|
||||||
|
|
||||||
|
|
||||||
class ContextPlus(commands.Context):
|
class ContextPlus(commands.Context):
|
||||||
async def send(self, content=None, *args, **kwargs):
|
async def send(self, content=None, *args, **kwargs):
|
||||||
if content is not None:
|
if content is not None:
|
||||||
content = content.replace(self.bot.config.Core.token, "<token>")
|
content = content.replace(
|
||||||
|
self.bot.config.Core.token, TOKEN_REPLACEMENT
|
||||||
|
)
|
||||||
if kwargs.get("embed"):
|
if kwargs.get("embed"):
|
||||||
e = str(kwargs.get("embed").to_dict())
|
embed = kwargs.get("embed").to_dict()
|
||||||
e = e.replace(self.bot.config("core").get("token"), "<token>")
|
for key, value in embed.items():
|
||||||
e = yaml.load(e, Loader=yaml.FullLoader)
|
if isinstance(value, (str, bytes)):
|
||||||
kwargs["embed"] = Embed.from_dict(e)
|
embed[key] = value.replace(
|
||||||
|
self.bot.config.Core.token, TOKEN_REPLACEMENT
|
||||||
|
)
|
||||||
|
kwargs["embed"] = Embed.from_dict(embed)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
hasattr(self.command, "deletable") and self.command.deletable
|
hasattr(self.command, "deletable") and self.command.deletable
|
||||||
|
|
Loading…
Reference in a new issue