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
|
||||
jishaku>=1.19.1.200
|
||||
psutil>=5.7.2
|
||||
pyyaml>=5.3.1
|
||||
rich>=6.0.0
|
||||
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]Kernel:[/u] {os.uname().release}")
|
||||
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(
|
||||
f"[u]Load Average:[/u] {' '.join(map(str, os.getloadavg()))}"
|
||||
)
|
||||
|
|
|
@ -26,9 +26,7 @@ class Admin(commands.Cog, name="Admin"):
|
|||
self.bot = bot
|
||||
|
||||
async def _save_lang(self, ctx: ContextPlus, lang: str):
|
||||
await self.bot.config.update(
|
||||
"core", f"guild.{ctx.guild.id}.locale", lang
|
||||
)
|
||||
self.bot.config.Servers.all[ctx.guild.id].locale = lang
|
||||
|
||||
@group_extra(name="lang", aliases=["locale", "langue"], deletable=True)
|
||||
@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 tuxbot.core import Config
|
||||
from tuxbot.core.config import search_for
|
||||
from tuxbot.core.utils.functions.extra import ContextPlus
|
||||
|
||||
log = logging.getLogger("tuxbot.core.i18n")
|
||||
|
@ -59,12 +60,19 @@ class Translator(Callable[[str], str]):
|
|||
self, untranslated: str, ctx: ContextPlus, config: Config
|
||||
) -> str:
|
||||
try:
|
||||
locale = config.get_value(
|
||||
"core",
|
||||
f"guild.{ctx.guild.id}.locale",
|
||||
config.get_value("core", "locale"),
|
||||
user_locale = search_for(
|
||||
config.Users, ctx.author.id, "locale", None
|
||||
)
|
||||
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:
|
||||
return untranslated
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import asyncio
|
||||
import yaml
|
||||
|
||||
import discord
|
||||
from discord import Embed
|
||||
|
@ -9,18 +8,23 @@ from rich.console import Console
|
|||
|
||||
console = Console()
|
||||
|
||||
console.clear()
|
||||
TOKEN_REPLACEMENT = "whoops, leaked token"
|
||||
|
||||
|
||||
class ContextPlus(commands.Context):
|
||||
async def send(self, content=None, *args, **kwargs):
|
||||
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"):
|
||||
e = str(kwargs.get("embed").to_dict())
|
||||
e = e.replace(self.bot.config("core").get("token"), "<token>")
|
||||
e = yaml.load(e, Loader=yaml.FullLoader)
|
||||
kwargs["embed"] = Embed.from_dict(e)
|
||||
embed = kwargs.get("embed").to_dict()
|
||||
for key, value in embed.items():
|
||||
if isinstance(value, (str, bytes)):
|
||||
embed[key] = value.replace(
|
||||
self.bot.config.Core.token, TOKEN_REPLACEMENT
|
||||
)
|
||||
kwargs["embed"] = Embed.from_dict(embed)
|
||||
|
||||
if (
|
||||
hasattr(self.command, "deletable") and self.command.deletable
|
||||
|
|
Loading…
Reference in a new issue