mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Make localwhitelist check if caller will still be able to use bot after changes (#3903)
* Check invokers theoretical perms in localwhitelist add before completing command * remove unnecessary code * add check to remove * ignore bot owner and server owner * Update core_commands.py * lets not crash shit
This commit is contained in:
parent
60df447550
commit
e0b922c949
@ -2014,8 +2014,20 @@ class Core(commands.Cog, CoreLogic):
|
|||||||
return
|
return
|
||||||
|
|
||||||
names = [getattr(u_or_r, "name", u_or_r) for u_or_r in users_or_roles]
|
names = [getattr(u_or_r, "name", u_or_r) for u_or_r in users_or_roles]
|
||||||
uids = [getattr(u_or_r, "id", u_or_r) for u_or_r in users_or_roles]
|
uids = {getattr(u_or_r, "id", u_or_r) for u_or_r in users_or_roles}
|
||||||
await self.bot._whiteblacklist_cache.add_to_whitelist(ctx.guild, uids)
|
if not (ctx.guild.owner == ctx.author or await self.bot.is_owner(ctx.author)):
|
||||||
|
current_whitelist = set(await self.bot._whiteblacklist_cache.get_whitelist(ctx.guild))
|
||||||
|
theoretical_whitelist = current_whitelist.union(uids)
|
||||||
|
ids = {i for i in (ctx.author.id, *(getattr(ctx.author, "_roles", [])))}
|
||||||
|
if ids.isdisjoint(theoretical_whitelist):
|
||||||
|
return await ctx.send(
|
||||||
|
_(
|
||||||
|
"I cannot allow you to do this, as it would "
|
||||||
|
"remove your ability to run commands, "
|
||||||
|
"please ensure to add yourself to the whitelist first."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await self.bot._whiteblacklist_cache.add_to_whitelist(ctx.guild, list(uids))
|
||||||
|
|
||||||
await ctx.send(_("{names} added to whitelist.").format(names=humanize_list(names)))
|
await ctx.send(_("{names} added to whitelist.").format(names=humanize_list(names)))
|
||||||
|
|
||||||
@ -2049,8 +2061,19 @@ class Core(commands.Cog, CoreLogic):
|
|||||||
return
|
return
|
||||||
|
|
||||||
names = [getattr(u_or_r, "name", u_or_r) for u_or_r in users_or_roles]
|
names = [getattr(u_or_r, "name", u_or_r) for u_or_r in users_or_roles]
|
||||||
uids = [getattr(u_or_r, "id", u_or_r) for u_or_r in users_or_roles]
|
uids = {getattr(u_or_r, "id", u_or_r) for u_or_r in users_or_roles}
|
||||||
await self.bot._whiteblacklist_cache.remove_from_whitelist(ctx.guild, uids)
|
if not (ctx.guild.owner == ctx.author or await self.bot.is_owner(ctx.author)):
|
||||||
|
current_whitelist = set(await self.bot._whiteblacklist_cache.get_whitelist(ctx.guild))
|
||||||
|
theoretical_whitelist = current_whitelist - uids
|
||||||
|
ids = {i for i in (ctx.author.id, *(getattr(ctx.author, "_roles", [])))}
|
||||||
|
if theoretical_whitelist and ids.isdisjoint(theoretical_whitelist):
|
||||||
|
return await ctx.send(
|
||||||
|
_(
|
||||||
|
"I cannot allow you to do this, as it would "
|
||||||
|
"remove your ability to run commands."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await self.bot._whiteblacklist_cache.remove_from_whitelist(ctx.guild, list(uids))
|
||||||
|
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
_("{names} removed from the local whitelist.").format(names=humanize_list(names))
|
_("{names} removed from the local whitelist.").format(names=humanize_list(names))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user