mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Fix issues with the black/whitelist cache (#3643)
* Fix issues with the black/whitelist cache * Address review * address review * or
This commit is contained in:
parent
15e3437001
commit
d957e44e1e
@ -130,7 +130,7 @@ class WhitelistBlacklistManager:
|
||||
ret = self._cached_whitelist[gid].copy()
|
||||
else:
|
||||
if gid is not None:
|
||||
ret = await self._config.guild_from_id(gid).whitelsit()
|
||||
ret = await self._config.guild_from_id(gid).whitelist()
|
||||
if not ret:
|
||||
ret = []
|
||||
else:
|
||||
@ -143,26 +143,31 @@ class WhitelistBlacklistManager:
|
||||
async def add_to_whitelist(self, guild: Optional[discord.Guild], role_or_user: List[int]):
|
||||
gid: Optional[int] = guild.id if guild else None
|
||||
role_or_user = role_or_user or []
|
||||
if not isinstance(role_or_user, list) and not all(
|
||||
isinstance(r_or_u, str) for r_or_u in role_or_user
|
||||
if not isinstance(role_or_user, list) or not all(
|
||||
isinstance(r_or_u, int) for r_or_u in role_or_user
|
||||
):
|
||||
raise TypeError("Whitelisted objects must be a list of ints")
|
||||
|
||||
if gid is None:
|
||||
if gid not in self._cached_whitelist:
|
||||
self._cached_whitelist[gid] = await self._config.whitelist()
|
||||
for obj_id in role_or_user:
|
||||
if obj_id not in self._cached_whitelist:
|
||||
if obj_id not in self._cached_whitelist[gid]:
|
||||
self._cached_whitelist[gid].append(obj_id)
|
||||
async with self._config.whitelist() as curr_list:
|
||||
curr_list.append(obj_id)
|
||||
else:
|
||||
if gid not in self._cached_whitelist:
|
||||
self._cached_whitelist[gid] = await self._config.guild_from_id(gid).whitelist()
|
||||
for obj_id in role_or_user:
|
||||
if obj_id not in self._cached_whitelist:
|
||||
if obj_id not in self._cached_whitelist[gid]:
|
||||
self._cached_whitelist[gid].append(obj_id)
|
||||
async with self._config.guild_from_id(gid).whitelist() as curr_list:
|
||||
curr_list.append(obj_id)
|
||||
|
||||
async def clear_whitelist(self, guild: Optional[discord.Guild] = None):
|
||||
gid: Optional[int] = guild.id if guild else None
|
||||
self._cached_whitelist[gid]
|
||||
self._cached_whitelist[gid] = []
|
||||
if gid is None:
|
||||
await self._config.whitelist.clear()
|
||||
else:
|
||||
@ -171,19 +176,24 @@ class WhitelistBlacklistManager:
|
||||
async def remove_from_whitelist(self, guild: Optional[discord.Guild], role_or_user: List[int]):
|
||||
gid: Optional[int] = guild.id if guild else None
|
||||
role_or_user = role_or_user or []
|
||||
if not isinstance(role_or_user, list) and not all(
|
||||
isinstance(r_or_u, str) for r_or_u in role_or_user
|
||||
if not isinstance(role_or_user, list) or not all(
|
||||
isinstance(r_or_u, int) for r_or_u in role_or_user
|
||||
):
|
||||
raise TypeError("Whitelisted objects must be a list of ints")
|
||||
|
||||
if gid is None:
|
||||
if gid not in self._cached_whitelist:
|
||||
self._cached_whitelist[gid] = await self._config.whitelist()
|
||||
for obj_id in role_or_user:
|
||||
if obj_id in self._cached_whitelist:
|
||||
if obj_id in self._cached_whitelist[gid]:
|
||||
self._cached_whitelist[gid].remove(obj_id)
|
||||
async with self._config.whitelist() as curr_list:
|
||||
curr_list.remove(obj_id)
|
||||
else:
|
||||
if gid not in self._cached_whitelist:
|
||||
self._cached_whitelist[gid] = await self._config.guild_from_id(gid).whitelist()
|
||||
for obj_id in role_or_user:
|
||||
if obj_id not in self._cached_whitelist:
|
||||
if obj_id in self._cached_whitelist[gid]:
|
||||
self._cached_whitelist[gid].remove(obj_id)
|
||||
async with self._config.guild_from_id(gid).whitelist() as curr_list:
|
||||
curr_list.remove(obj_id)
|
||||
@ -197,7 +207,7 @@ class WhitelistBlacklistManager:
|
||||
ret = self._cached_blacklist[gid].copy()
|
||||
else:
|
||||
if gid is not None:
|
||||
ret = await self._config.guild_from_id(gid).whitelsit()
|
||||
ret = await self._config.guild_from_id(gid).blacklist()
|
||||
if not ret:
|
||||
ret = []
|
||||
else:
|
||||
@ -210,26 +220,30 @@ class WhitelistBlacklistManager:
|
||||
async def add_to_blacklist(self, guild: Optional[discord.Guild], role_or_user: List[int]):
|
||||
gid: Optional[int] = guild.id if guild else None
|
||||
role_or_user = role_or_user or []
|
||||
if not isinstance(role_or_user, list) and not all(
|
||||
isinstance(r_or_u, str) for r_or_u in role_or_user
|
||||
if not isinstance(role_or_user, list) or not all(
|
||||
isinstance(r_or_u, int) for r_or_u in role_or_user
|
||||
):
|
||||
raise TypeError("Blacklisted objects must be a list of ints")
|
||||
if gid is None:
|
||||
if gid not in self._cached_blacklist:
|
||||
self._cached_blacklist[gid] = await self._config.blacklist()
|
||||
for obj_id in role_or_user:
|
||||
if obj_id not in self._cached_blacklist:
|
||||
if obj_id not in self._cached_blacklist[gid]:
|
||||
self._cached_blacklist[gid].append(obj_id)
|
||||
async with self._config.blacklist() as curr_list:
|
||||
curr_list.append(obj_id)
|
||||
else:
|
||||
if gid not in self._cached_blacklist:
|
||||
self._cached_blacklist[gid] = self._config.guild_from_id(gid).blacklist()
|
||||
for obj_id in role_or_user:
|
||||
if obj_id not in self._cached_blacklist:
|
||||
if obj_id not in self._cached_blacklist[gid]:
|
||||
self._cached_blacklist[gid].append(obj_id)
|
||||
async with self._config.guild_from_id(gid).blacklist() as curr_list:
|
||||
curr_list.append(obj_id)
|
||||
|
||||
async def clear_blacklist(self, guild: Optional[discord.Guild] = None):
|
||||
gid: Optional[int] = guild.id if guild else None
|
||||
self._cached_whitelist[gid]
|
||||
self._cached_blacklist[gid] = []
|
||||
if gid is None:
|
||||
await self._config.blacklist.clear()
|
||||
else:
|
||||
@ -238,19 +252,23 @@ class WhitelistBlacklistManager:
|
||||
async def remove_from_blacklist(self, guild: Optional[discord.Guild], role_or_user: List[int]):
|
||||
gid: Optional[int] = guild.id if guild else None
|
||||
role_or_user = role_or_user or []
|
||||
if not isinstance(role_or_user, list) and not all(
|
||||
isinstance(r_or_u, str) for r_or_u in role_or_user
|
||||
if not isinstance(role_or_user, list) or not all(
|
||||
isinstance(r_or_u, int) for r_or_u in role_or_user
|
||||
):
|
||||
raise TypeError("Blacklisted objects must be a list of ints")
|
||||
if gid is None:
|
||||
if gid not in self._cached_blacklist:
|
||||
self._cached_blacklist[gid] = await self._config.blacklist()
|
||||
for obj_id in role_or_user:
|
||||
if obj_id in self._cached_blacklist:
|
||||
if obj_id in self._cached_blacklist[gid]:
|
||||
self._cached_blacklist[gid].remove(obj_id)
|
||||
async with self._config.blacklist() as curr_list:
|
||||
curr_list.remove(obj_id)
|
||||
else:
|
||||
if gid not in self._cached_blacklist:
|
||||
self._cached_blacklist[gid] = self._config.guild_from_id(gid).blacklist()
|
||||
for obj_id in role_or_user:
|
||||
if obj_id not in self._cached_blacklist:
|
||||
if obj_id in self._cached_blacklist[gid]:
|
||||
self._cached_blacklist[gid].remove(obj_id)
|
||||
async with self._config.guild_from_id(gid).blacklist() as curr_list:
|
||||
curr_list.remove(obj_id)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user