sharding (blacklists): Blacklist shard support.
Moved the `user_blacklist` and `guild_blacklist` to a client TTL cache.
This commit is contained in:
@@ -43,7 +43,7 @@ async def cmd_topcoin(ctx):
|
||||
|
||||
# Fetch the leaderboard
|
||||
exclude = set(m.id for m in ctx.guild_settings.unranked_roles.members)
|
||||
exclude.update(ctx.client.objects['blacklisted_users'])
|
||||
exclude.update(ctx.client.user_blacklist())
|
||||
exclude.update(ctx.client.objects['ignored_members'][ctx.guild.id])
|
||||
|
||||
args = {
|
||||
|
||||
@@ -134,7 +134,7 @@ class Reminder:
|
||||
"""
|
||||
Execute the reminder.
|
||||
"""
|
||||
if self.data.userid in client.objects['blacklisted_users']:
|
||||
if self.data.userid in client.user_blacklist():
|
||||
self.delete(self.reminderid)
|
||||
return
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ async def cmd_stats(ctx):
|
||||
|
||||
# Leaderboard ranks
|
||||
exclude = set(m.id for m in ctx.guild_settings.unranked_roles.members)
|
||||
exclude.update(ctx.client.objects['blacklisted_users'])
|
||||
exclude.update(ctx.client.user_blacklist())
|
||||
exclude.update(ctx.client.objects['ignored_members'][ctx.guild.id])
|
||||
if target.id in exclude:
|
||||
time_rank = None
|
||||
|
||||
@@ -40,7 +40,7 @@ async def cmd_top(ctx):
|
||||
|
||||
# Fetch the leaderboard
|
||||
exclude = set(m.id for m in ctx.guild_settings.unranked_roles.members)
|
||||
exclude.update(ctx.client.objects['blacklisted_users'])
|
||||
exclude.update(ctx.client.user_blacklist())
|
||||
exclude.update(ctx.client.objects['ignored_members'][ctx.guild.id])
|
||||
|
||||
args = {
|
||||
|
||||
@@ -298,7 +298,7 @@ async def session_voice_tracker(client, member, before, after):
|
||||
pending.cancel()
|
||||
|
||||
if after.channel:
|
||||
blacklist = client.objects['blacklisted_users']
|
||||
blacklist = client.user_blacklist()
|
||||
guild_blacklist = client.objects['ignored_members'][guild.id]
|
||||
untracked = untracked_channels.get(guild.id).data
|
||||
start_session = (
|
||||
|
||||
@@ -47,7 +47,7 @@ def _scan(guild):
|
||||
members = itertools.chain(*channel_members)
|
||||
# TODO filter out blacklisted users
|
||||
|
||||
blacklist = client.objects['blacklisted_users']
|
||||
blacklist = client.user_blacklist()
|
||||
guild_blacklist = client.objects['ignored_members'][guild.id]
|
||||
|
||||
for member in members:
|
||||
|
||||
@@ -7,6 +7,8 @@ import discord
|
||||
from cmdClient.checks import is_owner
|
||||
from cmdClient.lib import ResponseTimedOut
|
||||
|
||||
from meta.sharding import sharded
|
||||
|
||||
from .module import module
|
||||
|
||||
|
||||
@@ -26,14 +28,14 @@ async def cmd_guildblacklist(ctx, flags):
|
||||
Description:
|
||||
View, add, or remove guilds from the blacklist.
|
||||
"""
|
||||
blacklist = ctx.client.objects['blacklisted_guilds']
|
||||
blacklist = ctx.client.guild_blacklist()
|
||||
|
||||
if ctx.args:
|
||||
# guildid parsing
|
||||
items = [item.strip() for item in ctx.args.split(',')]
|
||||
if any(not item.isdigit() for item in items):
|
||||
return await ctx.error_reply(
|
||||
"Please provide guilds as comma seprated guild ids."
|
||||
"Please provide guilds as comma separated guild ids."
|
||||
)
|
||||
|
||||
guildids = set(int(item) for item in items)
|
||||
@@ -80,9 +82,18 @@ async def cmd_guildblacklist(ctx, flags):
|
||||
insert_keys=('guildid', 'ownerid', 'reason')
|
||||
)
|
||||
|
||||
# Check if we are in any of these guilds
|
||||
to_leave = (ctx.client.get_guild(guildid) for guildid in to_add)
|
||||
to_leave = [guild for guild in to_leave if guild is not None]
|
||||
# Leave freshly blacklisted guilds, accounting for shards
|
||||
to_leave = []
|
||||
for guildid in to_add:
|
||||
guild = ctx.client.get_guild(guildid)
|
||||
if not guild and sharded:
|
||||
try:
|
||||
guild = await ctx.client.fetch_guild(guildid)
|
||||
except discord.HTTPException:
|
||||
pass
|
||||
if guild:
|
||||
to_leave.append(guild)
|
||||
|
||||
for guild in to_leave:
|
||||
await guild.leave()
|
||||
|
||||
@@ -102,9 +113,8 @@ async def cmd_guildblacklist(ctx, flags):
|
||||
)
|
||||
|
||||
# Refresh the cached blacklist after modification
|
||||
ctx.client.objects['blacklisted_guilds'] = set(
|
||||
row['guildid'] for row in ctx.client.data.global_guild_blacklist.select_where()
|
||||
)
|
||||
ctx.client.guild_blacklist.cache_clear()
|
||||
ctx.client.guild_blacklist()
|
||||
else:
|
||||
# Display the current blacklist
|
||||
# First fetch the full blacklist data
|
||||
@@ -183,7 +193,7 @@ async def cmd_userblacklist(ctx, flags):
|
||||
Description:
|
||||
View, add, or remove users from the blacklist.
|
||||
"""
|
||||
blacklist = ctx.client.objects['blacklisted_users']
|
||||
blacklist = ctx.client.user_blacklist()
|
||||
|
||||
if ctx.args:
|
||||
# userid parsing
|
||||
@@ -245,9 +255,8 @@ async def cmd_userblacklist(ctx, flags):
|
||||
)
|
||||
|
||||
# Refresh the cached blacklist after modification
|
||||
ctx.client.objects['blacklisted_users'] = set(
|
||||
row['userid'] for row in ctx.client.data.global_user_blacklist.select_where()
|
||||
)
|
||||
ctx.client.user_blacklist.cache_clear()
|
||||
ctx.client.user_blacklist()
|
||||
else:
|
||||
# Display the current blacklist
|
||||
# First fetch the full blacklist data
|
||||
|
||||
@@ -170,7 +170,7 @@ async def workout_voice_tracker(client, member, before, after):
|
||||
|
||||
if member.bot:
|
||||
return
|
||||
if member.id in client.objects['blacklisted_users']:
|
||||
if member.id in client.user_blacklist():
|
||||
return
|
||||
if member.id in client.objects['ignored_members'][member.guild.id]:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user