[Dev] Sanitize API tokens in debug and eval (#2585)

* Sanitize API tokens in debug and eval

* Not sure what happened there
This commit is contained in:
Neuro Assassin 2019-04-22 18:43:02 -04:00 committed by Will
parent 95d5ec5f0e
commit b8190c44a8

View File

@ -61,13 +61,18 @@ class Dev(commands.Cog):
return pagify(msg, delims=["\n", " "], priority=True, shorten_by=10) return pagify(msg, delims=["\n", " "], priority=True, shorten_by=10)
@staticmethod @staticmethod
def sanitize_output(ctx: commands.Context, input_: str) -> str: def sanitize_output(ctx: commands.Context, keys: dict, input_: str) -> str:
"""Hides the bot's token from a string.""" """Hides the bot's token from a string."""
token = ctx.bot.http.token token = ctx.bot.http.token
r = "[EXPUNGED]" r = "[EXPUNGED]"
result = input_.replace(token, r) result = input_.replace(token, r)
result = result.replace(token.lower(), r) result = result.replace(token.lower(), r)
result = result.replace(token.upper(), r) result = result.replace(token.upper(), r)
for provider, data in keys.items():
for name, key in data.items():
result = result.replace(key, r)
result = result.replace(key.upper(), r)
result = result.replace(key.lower(), r)
return result return result
@commands.command() @commands.command()
@ -121,7 +126,8 @@ class Dev(commands.Cog):
self._last_result = result self._last_result = result
result = self.sanitize_output(ctx, str(result)) api_keys = await ctx.bot.db.api_tokens()
result = self.sanitize_output(ctx, api_keys, str(result))
await ctx.send_interactive(self.get_pages(result), box_lang="py") await ctx.send_interactive(self.get_pages(result), box_lang="py")
@ -185,7 +191,8 @@ class Dev(commands.Cog):
msg = "{}{}".format(printed, result) msg = "{}{}".format(printed, result)
else: else:
msg = printed msg = printed
msg = self.sanitize_output(ctx, msg) api_keys = await ctx.bot.db.api_tokens()
msg = self.sanitize_output(ctx, api_keys, msg)
await ctx.send_interactive(self.get_pages(msg), box_lang="py") await ctx.send_interactive(self.get_pages(msg), box_lang="py")