Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Disqord.Core/Discord/Limits/Rest/Discord.Limits.Rest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ public static partial class Limits
/// </summary>
public static class Rest
{
/// <summary>
/// Represents the number of days worth of messages that can be deleted when banning a user.
/// </summary>
public const int BanDeleteMessageDays = 7;

/// <summary>
/// Represents the number of seconds worth of messages that can be deleted when banning a user.
/// </summary>
/// <remarks>
/// <c>7 * 60 * 60 * 24 = 604800</c>
/// </remarks>
public const int BanDeleteMessageSeconds = 604800;

/// <summary>
/// Represents the maximum length of the <c>X-Audit-Log-Reason</c> header; used for sending audit log reasons.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ public class CreateBanJsonRestRequestContent : JsonModelRestRequestContent
{
[JsonProperty("delete_message_days")]
public Optional<int> DeleteMessageDays;

[JsonProperty("delete_message_seconds")]
public Optional<int> DeleteMessageSeconds;

[JsonProperty("reason")]
public Optional<string> Reason;

protected override void OnValidate()
{
OptionalGuard.CheckValue(DeleteMessageDays, static days => Guard.IsBetweenOrEqualTo(days, 0, Discord.Limits.Rest.BanDeleteMessageDays));
OptionalGuard.CheckValue(DeleteMessageSeconds, static days => Guard.IsBetweenOrEqualTo(days, 0, Discord.Limits.Rest.BanDeleteMessageSeconds));
OptionalGuard.CheckValue(Reason, static reason => Guard.HasSizeLessThanOrEqualTo(reason, Discord.Limits.Rest.MaxAuditLogReasonLength));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ public static Task<IReadOnlyList<IBan>> FetchBansAsync(this IGuild guild,
var client = guild.GetRestClient();
return client.FetchBanAsync(guild.Id, userId, options, cancellationToken);
}

public static Task CreateBanAsync(this IGuild guild,
Snowflake userId, string? reason = null, int? deleteMessageDays = null,
Snowflake userId, string? reason = null, TimeSpan? deleteMessageDuration = null,
IRestRequestOptions? options = null, CancellationToken cancellationToken = default)
{
var client = guild.GetRestClient();
return client.CreateBanAsync(guild.Id, userId, reason, deleteMessageDays, options, cancellationToken);
return client.CreateBanAsync(guild.Id, userId, reason, deleteMessageDuration, options, cancellationToken);
}

public static Task DeleteBanAsync(this IGuild guild,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public static Task KickAsync(this IMember member,
var client = member.GetRestClient();
return client.KickMemberAsync(member.GuildId, member.Id, options, cancellationToken);
}

public static Task BanAsync(this IMember member,
string? reason = null, int? deleteMessageDays = null,
string? reason = null, TimeSpan? deleteMessageDuration = null,
IRestRequestOptions? options = null, CancellationToken cancellationToken = default)
{
var client = member.GetRestClient();
return client.CreateBanAsync(member.GuildId, member.Id, reason, deleteMessageDays, options, cancellationToken);
return client.CreateBanAsync(member.GuildId, member.Id, reason, deleteMessageDuration, options, cancellationToken);
}

public static Task UnbanAsync(this IMember member,
Expand Down
6 changes: 3 additions & 3 deletions src/Disqord.Rest/Extensions/RestClientExtensions.Guild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,14 @@ internal static async Task<IReadOnlyList<IBan>> InternalFetchBansAsync(this IRes
return null;
}
}

public static Task CreateBanAsync(this IRestClient client,
Snowflake guildId, Snowflake userId, string? reason = null, int? deleteMessageDays = null,
Snowflake guildId, Snowflake userId, string? reason = null, TimeSpan? deleteMessageDuration = null,
IRestRequestOptions? options = null, CancellationToken cancellationToken = default)
{
var content = new CreateBanJsonRestRequestContent
{
DeleteMessageDays = Optional.FromNullable(deleteMessageDays),
DeleteMessageSeconds = Optional.FromNullable((int?) deleteMessageDuration?.TotalSeconds),
Reason = Optional.FromNullable(reason)
};

Expand Down
Loading