bettah bulk bans (#2915)
This commit is contained in:
@@ -256,5 +256,10 @@ namespace Discord
|
||||
/// Returns the maximum number of entitlements that can be gotten per-batch.
|
||||
/// </summary>
|
||||
public const int MaxEntitlementsPerBatch = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the maximum number of bans that can be banned in a single bulk request.
|
||||
/// </summary>
|
||||
public const int MaxBansPerBulkBatch = 200;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,9 +251,20 @@ namespace Discord.Rest
|
||||
|
||||
public static async Task<BulkBanResult> BulkBanAsync(IGuild guild, BaseDiscordClient client, ulong[] userIds, int? deleteMessageSeconds, RequestOptions options)
|
||||
{
|
||||
var model = await client.ApiClient.BulkBanAsync(guild.Id, userIds, deleteMessageSeconds, options);
|
||||
return new(model.BannedUsers?.ToImmutableArray() ?? ImmutableArray<ulong>.Empty,
|
||||
model.FailedUsers?.ToImmutableArray() ?? ImmutableArray<ulong>.Empty);
|
||||
var pos = 0;
|
||||
var banned = new List<ulong>(userIds.Length);
|
||||
var failed = new List<ulong>();
|
||||
while (pos * DiscordConfig.MaxBansPerBulkBatch < userIds.Length)
|
||||
{
|
||||
var toBan = userIds
|
||||
.Skip(pos * DiscordConfig.MaxBansPerBulkBatch)
|
||||
.Take(DiscordConfig.MaxBansPerBulkBatch);
|
||||
pos++;
|
||||
var model = await client.ApiClient.BulkBanAsync(guild.Id, toBan.ToArray(), deleteMessageSeconds, options);
|
||||
banned.AddRange(model.BannedUsers ?? []);
|
||||
failed.AddRange(model.FailedUsers ?? []);
|
||||
}
|
||||
return new(banned.ToImmutableArray(), failed.ToImmutableArray());
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user