From 96618fa5025b957da8623194507ac8bf3d0a4481 Mon Sep 17 00:00:00 2001 From: Romain J Date: Wed, 15 Jan 2020 21:40:12 +0100 Subject: [PATCH] fix(token): fix all possible flaw of leaked token --- bot.py | 6 +++++- utils/functions/extra.py | 25 ++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/bot.py b/bot.py index f06583f..e7b3bc0 100755 --- a/bot.py +++ b/bot.py @@ -14,6 +14,7 @@ from utils import Config from utils import Database from utils import Texts from utils import Version +from utils import ContextPlus description = """ Je suis TuxBot, le bot qui vit de l'OpenSource ! ;) @@ -95,6 +96,9 @@ class TuxBot(commands.AutoShardedBot): return str(user.id) in self.config.get("permissions", "Owners").split( ', ') + async def get_context(self, message, *, cls=None): + return await super().get_context(message, cls=cls or ContextPlus) + async def on_socket_response(self, msg): self._prev_events.append(msg) @@ -112,7 +116,7 @@ class TuxBot(commands.AutoShardedBot): ) async def process_commands(self, message: discord.message): - ctx = await self.get_context(message) + ctx: commands.Context = await self.get_context(message) if ctx.command is None: return diff --git a/utils/functions/extra.py b/utils/functions/extra.py index 318ab04..d2779f6 100644 --- a/utils/functions/extra.py +++ b/utils/functions/extra.py @@ -1,20 +1,35 @@ from discord.ext import commands +from utils import Config -class commandsPlus(commands.Command): +class CommandsPlus(commands.Command): def __init__(self, func, **kwargs): super().__init__(func, **kwargs) self.category = kwargs.get("category", 'other') -def commandExtra(*args, **kwargs): - return commands.command(*args, **kwargs, cls=commandsPlus) - - class GroupPlus(commands.Group): def __init__(self, func, **kwargs): super().__init__(func, **kwargs) self.category = kwargs.get("category", 'other') + +class ContextPlus(commands.Context): + async def send(self, **kwargs): + config = Config('./configs/config.cfg') + content = kwargs.pop('content') + + content = content.replace(config.get("bot", "Token"), 'Whoops! leaked token') + content = content.replace(config.get("webhook", "Token"), 'Whoops! leaked token') + + kwargs['content'] = content + + return await super().send(**kwargs) + + +def commandExtra(*args, **kwargs): + return commands.command(*args, **kwargs, cls=CommandsPlus) + + def groupExtra(*args, **kwargs): return commands.group(*args, **kwargs, cls=GroupPlus)