diff --git a/tuxbot/core/utils/functions/extra.py b/tuxbot/core/utils/functions/extra.py index a0b2be7..23cd4fe 100644 --- a/tuxbot/core/utils/functions/extra.py +++ b/tuxbot/core/utils/functions/extra.py @@ -10,9 +10,9 @@ from rich.console import Console console = Console() -TOKEN_REPLACEMENT = "\\*" * random.randint(3, 15) -PASSWORD_REPLACEMENT = "\\*" * random.randint(3, 15) -IP_REPLACEMENT = "\\*" * random.randint(3, 15) +TOKEN_REPLACEMENT = "■" * random.randint(3, 15) +PASSWORD_REPLACEMENT = "■" * random.randint(3, 15) +IP_REPLACEMENT = "■" * random.randint(3, 15) class ContextPlus(commands.Context): @@ -29,6 +29,10 @@ class ContextPlus(commands.Context): allowed_mentions=None, deletable=True ): # i know *args and **kwargs but, i prefer work with same values + from tuxbot.core.utils.functions.utils import ( + replace_in_dict, + replace_in_list, + ) if content: content = ( @@ -53,6 +57,30 @@ class ContextPlus(commands.Context): ) .replace(self.bot.config.Core.ip, IP_REPLACEMENT) ) + elif isinstance(value, list): + e[key] = replace_in_list( + value, self.bot.config.Core.token, TOKEN_REPLACEMENT + ) + e[key] = replace_in_list( + e[key], + self.bot.config.Core.Database.password, + PASSWORD_REPLACEMENT, + ) + e[key] = replace_in_list( + e[key], self.bot.config.Core.ip, IP_REPLACEMENT + ) + elif isinstance(value, dict): + e[key] = replace_in_dict( + value, self.bot.config.Core.token, TOKEN_REPLACEMENT + ) + e[key] = replace_in_dict( + e[key], + self.bot.config.Core.Database.password, + PASSWORD_REPLACEMENT, + ) + e[key] = replace_in_dict( + e[key], self.bot.config.Core.ip, IP_REPLACEMENT + ) embed = Embed.from_dict(e) if ( diff --git a/tuxbot/core/utils/functions/utils.py b/tuxbot/core/utils/functions/utils.py index c2f30ee..6656c6a 100644 --- a/tuxbot/core/utils/functions/utils.py +++ b/tuxbot/core/utils/functions/utils.py @@ -44,3 +44,35 @@ async def shorten(ctx: ContextPlus, text: str, length: int) -> dict: pass return output + + +def replace_in_dict(value: dict, search: str, replace: str) -> dict: + clean = {} + + for k, v in value.items(): + if isinstance(v, (str, bytes)): + v = v.replace(search, replace) + elif isinstance(v, list): + v = replace_in_list(v, search, replace) + elif isinstance(v, dict): + v = replace_in_dict(v, search, replace) + + clean[k] = v + + return clean + + +def replace_in_list(value: list, search: str, replace: str) -> list: + clean = [] + + for v in value: + if isinstance(v, (str, bytes)): + v = v.replace(search, replace) + elif isinstance(v, list): + v = replace_in_list(v, search, replace) + elif isinstance(v, dict): + v = replace_in_dict(v, search, replace) + + clean.append(v) + + return clean