More privatization, and some error helpers (#2976)

* More privatization, and some error helpers

This makes a lot more things private. Continued from #2967, fixes #2984
Adds public methods for various things.

Below is a brief summary of things available elsewhere, though this
particular set of changes may warrant a detailed section in the release notes.

 - bot.db.locale -> redbot.core.i18n.get_locale
   - Note: This one already existed.
 - bot.db.help -> redbot.core.commands.help.HelpSettings
 - bot db whitelist/blaclist? -> bot.allowed_by_whitelist_blacklist
   - This has also been made a single cannonical function for this
   purpose including check usage
 - bot color? -> bot.get_embed_color/bot.get_embed_colour
 - bot.id.api_tokens? ->

   - bot.get_shared_api_tokens
   - bot.set_shared_api_tokens
   - bot.remove_shared_api_tokens

 -bot.db.prefix -> bot.get_valid_prefixes
   - (Note: This is a wrapper around bot.get_prefix)

 Other changes include
  - removing `bot.counter` as it was never used anywhere
  - Adding properties with helpful error messages for moved and renamed
  things
  - making bot.uptime a property with an error on set
  - adding a migration to the bot config for shared_api_tokens

* Remove overly encompassing message redaction, eval is a risk, dont run in dev if you cant manage it

* address Flame's feedback

* rephrase example

* changelog extras

* You saw nothing
This commit is contained in:
Michael H
2019-09-26 12:55:05 -04:00
committed by GitHub
parent 62dcebff94
commit 25614620db
12 changed files with 295 additions and 86 deletions

View File

@@ -61,19 +61,10 @@ class Dev(commands.Cog):
return pagify(msg, delims=["\n", " "], priority=True, shorten_by=10)
@staticmethod
def sanitize_output(ctx: commands.Context, keys: dict, input_: str) -> str:
def sanitize_output(ctx: commands.Context, input_: str) -> str:
"""Hides the bot's token from a string."""
token = ctx.bot.http.token
r = "[EXPUNGED]"
result = input_.replace(token, r)
result = result.replace(token.lower(), 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 re.sub(re.escape(token), "[EXPUNGED]", input_, re.I)
@commands.command()
@checks.is_owner()
@@ -125,9 +116,7 @@ class Dev(commands.Cog):
result = await result
self._last_result = result
api_keys = await ctx.bot._config.api_tokens()
result = self.sanitize_output(ctx, api_keys, str(result))
result = self.sanitize_output(ctx, str(result))
await ctx.send_interactive(self.get_pages(result), box_lang="py")
@@ -191,8 +180,7 @@ class Dev(commands.Cog):
msg = "{}{}".format(printed, result)
else:
msg = printed
api_keys = await ctx.bot._config.api_tokens()
msg = self.sanitize_output(ctx, api_keys, msg)
msg = self.sanitize_output(ctx, msg)
await ctx.send_interactive(self.get_pages(msg), box_lang="py")
@@ -276,8 +264,7 @@ class Dev(commands.Cog):
elif value:
msg = "{}".format(value)
api_keys = await ctx.bot._config.api_tokens()
msg = self.sanitize_output(ctx, api_keys, msg)
msg = self.sanitize_output(ctx, msg)
try:
await ctx.send_interactive(self.get_pages(msg), box_lang="py")