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.
|
/// Returns the maximum number of entitlements that can be gotten per-batch.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const int MaxEntitlementsPerBatch = 100;
|
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)
|
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);
|
var pos = 0;
|
||||||
return new(model.BannedUsers?.ToImmutableArray() ?? ImmutableArray<ulong>.Empty,
|
var banned = new List<ulong>(userIds.Length);
|
||||||
model.FailedUsers?.ToImmutableArray() ?? ImmutableArray<ulong>.Empty);
|
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
|
#endregion
|
||||||
|
|
||||||
@@ -620,7 +631,7 @@ namespace Discord.Rest
|
|||||||
|
|
||||||
var createGuildRoleParams = new API.Rest.ModifyGuildRoleParams
|
var createGuildRoleParams = new API.Rest.ModifyGuildRoleParams
|
||||||
{
|
{
|
||||||
Color = color?.RawValue ?? Optional.Create<uint>(),
|
Color = color?.RawValue ?? Optional.Create<uint>(),
|
||||||
Hoist = isHoisted,
|
Hoist = isHoisted,
|
||||||
Mentionable = isMentionable,
|
Mentionable = isMentionable,
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|||||||
Reference in New Issue
Block a user