fix(token): fix all possible flaw of leaked token

This commit is contained in:
Romain J 2020-01-15 21:40:12 +01:00
parent caa98c44f4
commit 96618fa502
2 changed files with 25 additions and 6 deletions

6
bot.py
View file

@ -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

View file

@ -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)