Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
BrammyS committed Feb 14, 2023
2 parents e6c547d + 0746fdf commit def45ae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/Color-Chan.Discord.Core/Color-Chan.Discord.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
</PropertyGroup>

<ItemGroup>
<Folder Include="Common"/>
<Folder Include="Common" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.2"/>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.2" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup>
Expand Down Expand Up @@ -53,7 +53,7 @@
</PropertyGroup>

<ItemGroup>
<SourceRoot Include="$(MSBuildThisFileDirectory)/"/>
<SourceRoot Include="$(MSBuildThisFileDirectory)/" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Color_Chan.Discord.Core.Common.API.Params.Channel;

/// <summary>
/// Represents a discord Bulk Delete Messages API request model.
/// Docs: https://discord.com/developers/docs/resources/channel#bulk-delete-messages-json-params
/// </summary>
public class DiscordBulkDeleteMessages
{
/// <summary>
/// an array of message ids to delete (2-100)
/// </summary>
[JsonPropertyName("messages")]
public IReadOnlyCollection<ulong>? MessageIds { get; set; }
}
17 changes: 5 additions & 12 deletions src/Color-Chan.Discord.Rest/API/Rest/DiscordRestChannel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Color_Chan.Discord.Core.Common.API.DataModels;
Expand All @@ -11,22 +10,18 @@
using Color_Chan.Discord.Core.Common.Models.Message;
using Color_Chan.Discord.Core.Results;
using Color_Chan.Discord.Rest.Models;
using Microsoft.Extensions.Options;

namespace Color_Chan.Discord.Rest.API.Rest;

/// <inheritdoc cref="IDiscordRestChannel" />
public class DiscordRestChannel : DiscordRestBase, IDiscordRestChannel
{
private readonly IOptions<JsonSerializerOptions> _serializerOptions;

/// <summary>
/// Initializes a new instance of <see cref="DiscordRestGuild" />.
/// </summary>
/// <inheritdoc />
public DiscordRestChannel(IDiscordHttpClient httpClient, IOptions<JsonSerializerOptions> serializerOptions) : base(httpClient)
public DiscordRestChannel(IDiscordHttpClient httpClient) : base(httpClient)
{
_serializerOptions = serializerOptions;
}

// All api calls for channels.
Expand Down Expand Up @@ -128,13 +123,11 @@ public virtual async Task<Result> BulkDeleteMessageAsync(ulong channelId, IReadO
{
if (messageIds.Count is < 2 or > 100) throw new ArgumentOutOfRangeException(nameof(messageIds), "The amount of message IDs has to be between 2 and 100.");

var queries = new List<KeyValuePair<string, string>>
{
new(Constants.Headers.MessageQueryName, JsonSerializer.Serialize(messageIds, _serializerOptions.Value))
};

var endpoint = $"channels/{channelId.ToString()}/messages/bulk-delete";
return await HttpClient.PostAsync(endpoint, queries, auditLogReason, ct).ConfigureAwait(false);
return await HttpClient.PostAsync(endpoint, new DiscordBulkDeleteMessages
{
MessageIds = messageIds
}, auditLogReason, ct).ConfigureAwait(false);
}

#endregion
Expand Down
5 changes: 0 additions & 5 deletions src/Color-Chan.Discord.Rest/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ internal static class Constants
/// </summary>
internal static class Headers
{
/// <summary>
/// The query name for a list of message ids.
/// </summary>
internal static string MessageQueryName { get; } = "messages";

/// <summary>
/// The query name to limit a request to a certain number of results.
/// </summary>
Expand Down

0 comments on commit def45ae

Please sign in to comment.