Skip to content

Commit

Permalink
Merge pull request #139 from Color-Chan/dev
Browse files Browse the repository at this point in the history
Dev -> Main
  • Loading branch information
BrammyS authored Apr 22, 2023
2 parents f7826ca + f177905 commit e9d9d94
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

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

/// <summary>
/// Represents a discord Create Test Entitlement API request model.
/// </summary>
/// <param name="SkuId">The sku to grant entitlement to, as Discord for this value.</param>
/// <param name="OwnerId">The guild_id or user_id to grant entitlement to.</param>
/// <param name="OwnerType">1 for a server subscription, 2 for a user subscription.</param>
public record DiscordCreateTestEntitlement(
[property: JsonPropertyName("sku_id")]
ulong SkuId,
[property: JsonPropertyName("owner_id")]
ulong OwnerId,
[property: JsonPropertyName("owner_type")]
int OwnerType
);
138 changes: 117 additions & 21 deletions src/Color-Chan.Discord.Core/Common/API/Rest/IDiscordRestApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Color_Chan.Discord.Core.Common.API.Params.Application;
using Color_Chan.Discord.Core.Common.API.Params.Webhook;
using Color_Chan.Discord.Core.Common.Models.Application;
using Color_Chan.Discord.Core.Common.Models.Entitlement;
using Color_Chan.Discord.Core.Common.Models.Guild;
using Color_Chan.Discord.Core.Common.Models.Message;
using Color_Chan.Discord.Core.Results;
Expand All @@ -17,6 +18,43 @@ namespace Color_Chan.Discord.Core.Common.API.Rest;
/// </summary>
public interface IDiscordRestApplication
{
/// <summary>
/// Get the entitlements for an application.
/// </summary>
/// <param name="applicationId">The id of the application where the entitlement belongs to.</param>
/// <param name="ct">The <see cref="CancellationToken" />.</param>
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IReadOnlyList{T}" /> of <see cref="IDiscordEntitlement" />
/// with the request results.
/// </returns>
Task<Result<IReadOnlyList<IDiscordEntitlement>>> GetEntitlementsAsync(ulong applicationId, CancellationToken ct = default);

/// <summary>
/// Create a new test entitlement for a user or guild.
/// </summary>
/// <param name="applicationId">The id of the application where the entitlement will belong to.</param>
/// <param name="entitlement">The <see cref="DiscordCreateTestEntitlement"/> containing all the request params.</param>
/// <param name="ct">The <see cref="CancellationToken" />.</param>
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IDiscordEntitlement" /> with the request results.
/// </returns>
Task<Result<IDiscordEntitlement>> CreateTestEntitlementAsync(
ulong applicationId,
DiscordCreateTestEntitlement entitlement,
CancellationToken ct = default
);

/// <summary>
/// Delete a test entitlement for a user or guild.
/// </summary>
/// <param name="applicationId">The id of the application where the entitlement belongs to.</param>
/// <param name="entitlementId">The id of the entitlement.</param>
/// <param name="ct">The <see cref="CancellationToken" />.</param>
/// <returns>
/// The <see cref="Result" /> with the request results.
/// </returns>
Task<Result> DeleteTestEntitlementAsync(ulong applicationId, ulong entitlementId, CancellationToken ct = default);

/// <summary>
/// Fetch all of the global application commands for your application.
/// </summary>
Expand Down Expand Up @@ -44,7 +82,11 @@ public interface IDiscordRestApplication
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IDiscordApplicationCommand" /> with the request results.
/// </returns>
Task<Result<IDiscordApplicationCommand>> CreateGlobalApplicationCommandAsync(ulong applicationId, DiscordCreateApplicationCommand command, CancellationToken ct = default);
Task<Result<IDiscordApplicationCommand>> CreateGlobalApplicationCommandAsync(
ulong applicationId,
DiscordCreateApplicationCommand command,
CancellationToken ct = default
);

/// <summary>
/// Fetch a global application command for your application..
Expand All @@ -70,8 +112,12 @@ public interface IDiscordRestApplication
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IDiscordApplicationCommand" /> with the request results.
/// </returns>
Task<Result<IDiscordApplicationCommand>> EditGlobalApplicationCommandAsync(ulong applicationId, ulong commandId,
DiscordCreateApplicationCommand command, CancellationToken ct = default);
Task<Result<IDiscordApplicationCommand>> EditGlobalApplicationCommandAsync(
ulong applicationId,
ulong commandId,
DiscordCreateApplicationCommand command,
CancellationToken ct = default
);

/// <summary>
/// Deletes a global application command.
Expand All @@ -94,7 +140,11 @@ Task<Result<IDiscordApplicationCommand>> EditGlobalApplicationCommandAsync(ulong
/// The <see cref="Result{T}" /> of <see cref="IReadOnlyList{T}" /> of <see cref="IDiscordApplicationCommand" />
/// with the request results.
/// </returns>
Task<Result<IReadOnlyList<IDiscordApplicationCommand>>> GetGuildApplicationCommandsAsync(ulong applicationId, ulong guildId, CancellationToken ct = default);
Task<Result<IReadOnlyList<IDiscordApplicationCommand>>> GetGuildApplicationCommandsAsync(
ulong applicationId,
ulong guildId,
CancellationToken ct = default
);

/// <summary>
/// Overwrites existing application commands that are registered globally for the application.
Expand All @@ -110,9 +160,11 @@ Task<Result<IDiscordApplicationCommand>> EditGlobalApplicationCommandAsync(ulong
/// The <see cref="Result{T}" /> of <see cref="IReadOnlyList{T}" /> of <see cref="IDiscordApplicationCommand" />
/// with the request results.
/// </returns>
Task<Result<IReadOnlyList<IDiscordApplicationCommand>>> BulkOverwriteGlobalApplicationCommandsAsync(ulong applicationId,
IEnumerable<DiscordCreateApplicationCommand> commandParams,
CancellationToken ct = default);
Task<Result<IReadOnlyList<IDiscordApplicationCommand>>> BulkOverwriteGlobalApplicationCommandsAsync(
ulong applicationId,
IEnumerable<DiscordCreateApplicationCommand> commandParams,
CancellationToken ct = default
);

/// <summary>
/// Create a new guild application command.
Expand All @@ -128,8 +180,11 @@ Task<Result<IReadOnlyList<IDiscordApplicationCommand>>> BulkOverwriteGlobalAppli
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IDiscordApplicationCommand" /> with the request results.
/// </returns>
Task<Result<IDiscordApplicationCommand>> CreateGuildApplicationCommandAsync(ulong applicationId, ulong guildId,
DiscordCreateApplicationCommand command, CancellationToken ct = default
Task<Result<IDiscordApplicationCommand>> CreateGuildApplicationCommandAsync(
ulong applicationId,
ulong guildId,
DiscordCreateApplicationCommand command,
CancellationToken ct = default
);

/// <summary>
Expand All @@ -142,7 +197,12 @@ Task<Result<IDiscordApplicationCommand>> CreateGuildApplicationCommandAsync(ulon
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IDiscordApplicationCommand" /> with the request results.
/// </returns>
Task<Result<IDiscordApplicationCommand>> GetGuildApplicationCommandAsync(ulong applicationId, ulong guildId, ulong commandId, CancellationToken ct = default);
Task<Result<IDiscordApplicationCommand>> GetGuildApplicationCommandAsync(
ulong applicationId,
ulong guildId,
ulong commandId,
CancellationToken ct = default
);

/// <summary>
/// Edit a guild application command.
Expand All @@ -159,8 +219,13 @@ Task<Result<IDiscordApplicationCommand>> CreateGuildApplicationCommandAsync(ulon
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IDiscordApplicationCommand" /> with the request results.
/// </returns>
Task<Result<IDiscordApplicationCommand>> EditGuildApplicationCommandAsync(ulong applicationId, ulong guildId, ulong commandId,
DiscordCreateApplicationCommand command, CancellationToken ct = default);
Task<Result<IDiscordApplicationCommand>> EditGuildApplicationCommandAsync(
ulong applicationId,
ulong guildId,
ulong commandId,
DiscordCreateApplicationCommand command,
CancellationToken ct = default
);

/// <summary>
/// Delete a guild application command.
Expand Down Expand Up @@ -189,9 +254,12 @@ Task<Result<IDiscordApplicationCommand>> EditGuildApplicationCommandAsync(ulong
/// The <see cref="Result{T}" /> of <see cref="IReadOnlyList{T}" /> of <see cref="IDiscordApplicationCommand" />
/// with the request results.
/// </returns>
Task<Result<IReadOnlyList<IDiscordApplicationCommand>>> BulkOverwriteGuildApplicationCommandsAsync(ulong applicationId, ulong guildId,
IEnumerable<DiscordCreateApplicationCommand> commandParams,
CancellationToken ct = default);
Task<Result<IReadOnlyList<IDiscordApplicationCommand>>> BulkOverwriteGuildApplicationCommandsAsync(
ulong applicationId,
ulong guildId,
IEnumerable<DiscordCreateApplicationCommand> commandParams,
CancellationToken ct = default
);

/// <summary>
/// Fetches command permissions for all commands for your application in a guild.
Expand All @@ -204,7 +272,10 @@ Task<Result<IReadOnlyList<IDiscordApplicationCommand>>> BulkOverwriteGuildApplic
/// <see cref="IDiscordGuildApplicationCommandPermissions" /> with the request results.
/// </returns>
Task<Result<IReadOnlyList<IDiscordGuildApplicationCommandPermissions>>> GetGuildApplicationCommandPermissionsAsync(
ulong applicationId, ulong guildId, CancellationToken ct = default);
ulong applicationId,
ulong guildId,
CancellationToken ct = default
);

/// <summary>
/// Fetches command permissions for a command for your application in a guild.
Expand All @@ -218,7 +289,11 @@ Task<Result<IReadOnlyList<IDiscordGuildApplicationCommandPermissions>>> GetGuild
/// <see cref="IDiscordGuildApplicationCommandPermissions" /> with the request results.
/// </returns>
Task<Result<IReadOnlyList<IDiscordGuildApplicationCommandPermissions>>> GetGuildApplicationCommandPermissionsAsync(
ulong applicationId, ulong guildId, ulong commandId, CancellationToken ct = default);
ulong applicationId,
ulong guildId,
ulong commandId,
CancellationToken ct = default
);

/// <summary>
/// Create a response to an Interaction from the gateway.
Expand All @@ -230,7 +305,12 @@ Task<Result<IReadOnlyList<IDiscordGuildApplicationCommandPermissions>>> GetGuild
/// <returns>
/// The <see cref="Result" /> with the request results.
/// </returns>
Task<Result> CreateInteractionResponseAsync(ulong interactionId, string token, DiscordInteractionResponseData response, CancellationToken ct = default);
Task<Result> CreateInteractionResponseAsync(
ulong interactionId,
string token,
DiscordInteractionResponseData response,
CancellationToken ct = default
);

/// <summary>
/// Returns the initial Interaction response.
Expand All @@ -253,7 +333,12 @@ Task<Result<IReadOnlyList<IDiscordGuildApplicationCommandPermissions>>> GetGuild
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IDiscordMessage" /> with the request results.
/// </returns>
Task<Result<IDiscordMessage>> EditOriginalInteractionResponseAsync(ulong applicationId, string token, DiscordEditWebhookMessage webhookMessage, CancellationToken ct = default);
Task<Result<IDiscordMessage>> EditOriginalInteractionResponseAsync(
ulong applicationId,
string token,
DiscordEditWebhookMessage webhookMessage,
CancellationToken ct = default
);

/// <summary>
/// Deletes the initial Interaction response.
Expand All @@ -276,7 +361,12 @@ Task<Result<IReadOnlyList<IDiscordGuildApplicationCommandPermissions>>> GetGuild
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IDiscordMessage" /> with the request results.
/// </returns>
Task<Result<IDiscordMessage>> CreateFollowupMessageAsync(ulong applicationId, string token, DiscordCreateFollowupMessage followupMessage, CancellationToken ct = default);
Task<Result<IDiscordMessage>> CreateFollowupMessageAsync(
ulong applicationId,
string token,
DiscordCreateFollowupMessage followupMessage,
CancellationToken ct = default
);

/// <summary>
/// Returns a followup message for an Interaction.
Expand Down Expand Up @@ -307,7 +397,13 @@ Task<Result<IReadOnlyList<IDiscordGuildApplicationCommandPermissions>>> GetGuild
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IDiscordMessage" /> with the request results.
/// </returns>
Task<Result<IDiscordMessage>> EditFollowupMessageAsync(ulong applicationId, string token, ulong messageId, DiscordEditWebhookMessage webhookMessage, CancellationToken ct = default);
Task<Result<IDiscordMessage>> EditFollowupMessageAsync(
ulong applicationId,
string token,
ulong messageId,
DiscordEditWebhookMessage webhookMessage,
CancellationToken ct = default
);

/// <summary>
/// Deletes a followup message for an Interaction.
Expand Down
20 changes: 20 additions & 0 deletions src/Color-Chan.Discord.Rest/API/ApiResultConverters.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using System.Collections.Generic;
using Color_Chan.Discord.Core.Common.API.DataModels;
using Color_Chan.Discord.Core.Common.API.DataModels.Application;
using Color_Chan.Discord.Core.Common.API.DataModels.Entitlement;
using Color_Chan.Discord.Core.Common.API.DataModels.Guild;
using Color_Chan.Discord.Core.Common.API.DataModels.Interaction;
using Color_Chan.Discord.Core.Common.API.DataModels.Message;
using Color_Chan.Discord.Core.Common.Models;
using Color_Chan.Discord.Core.Common.Models.Application;
using Color_Chan.Discord.Core.Common.Models.Entitlement;
using Color_Chan.Discord.Core.Common.Models.Guild;
using Color_Chan.Discord.Core.Common.Models.Interaction;
using Color_Chan.Discord.Core.Common.Models.Message;
using Color_Chan.Discord.Core.Results;
using Color_Chan.Discord.Rest.Models;
using Color_Chan.Discord.Rest.Models.Application;
using Color_Chan.Discord.Rest.Models.Entitlement;
using Color_Chan.Discord.Rest.Models.Guild;
using Color_Chan.Discord.Rest.Models.Interaction;
using Color_Chan.Discord.Rest.Models.Message;
Expand Down Expand Up @@ -183,4 +186,21 @@ internal static Result<IReadOnlyList<IDiscordConnection>> ConvertResult(Result<I

return Result<IReadOnlyList<IDiscordConnection>>.FromSuccess(list);
}

internal static Result<IDiscordEntitlement> ConvertResult(Result<DiscordEntitlementData> result)
{
if (!result.IsSuccessful || result.Entity is null) return Result<IDiscordEntitlement>.FromError(null, result.ErrorResult);

return Result<IDiscordEntitlement>.FromSuccess(new DiscordEntitlement(result.Entity));
}

internal static Result<IReadOnlyList<IDiscordEntitlement>> ConvertResult(Result<IReadOnlyList<DiscordEntitlementData>> result)
{
if (!result.IsSuccessful || result.Entity is null) return Result<IReadOnlyList<IDiscordEntitlement>>.FromError(null, result.ErrorResult);

var list = new List<IDiscordEntitlement>();
foreach (var data in result.Entity) list.Add(new DiscordEntitlement(data));

return Result<IReadOnlyList<IDiscordEntitlement>>.FromSuccess(list);
}
}
Loading

0 comments on commit e9d9d94

Please sign in to comment.