mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 18:27:59 -05:00
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:
@@ -4,34 +4,8 @@ from . import commands
|
||||
|
||||
def init_global_checks(bot):
|
||||
@bot.check_once
|
||||
async def global_perms(ctx):
|
||||
"""Check the user is/isn't globally whitelisted/blacklisted."""
|
||||
if await bot.is_owner(ctx.author):
|
||||
return True
|
||||
|
||||
whitelist = await bot._config.whitelist()
|
||||
if whitelist:
|
||||
return ctx.author.id in whitelist
|
||||
|
||||
return ctx.author.id not in await bot._config.blacklist()
|
||||
|
||||
@bot.check_once
|
||||
async def local_perms(ctx: commands.Context):
|
||||
"""Check the user is/isn't locally whitelisted/blacklisted."""
|
||||
if await bot.is_owner(ctx.author):
|
||||
return True
|
||||
elif ctx.guild is None:
|
||||
return True
|
||||
guild_settings = bot._config.guild(ctx.guild)
|
||||
local_blacklist = await guild_settings.blacklist()
|
||||
local_whitelist = await guild_settings.whitelist()
|
||||
|
||||
_ids = [r.id for r in ctx.author.roles if not r.is_default()]
|
||||
_ids.append(ctx.author.id)
|
||||
if local_whitelist:
|
||||
return any(i in local_whitelist for i in _ids)
|
||||
|
||||
return not any(i in local_blacklist for i in _ids)
|
||||
async def whiteblacklist_checks(ctx):
|
||||
return await ctx.bot.allowed_by_whitelist_blacklist(ctx.author)
|
||||
|
||||
@bot.check_once
|
||||
async def bots(ctx):
|
||||
|
||||
Reference in New Issue
Block a user