Skip to content
Draft
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
118 changes: 36 additions & 82 deletions NetCord/Application.cs
Original file line number Diff line number Diff line change
@@ -1,206 +1,175 @@
using System.Linq;
using NetCord.JsonModels;
using NetCord.Rest;

namespace NetCord;

/// <summary>
/// Applications or 'apps', are containers for developer platform features, and can contain bots installable to guilds and/or user accounts.
/// </summary>
public partial class Application : ClientEntity, IJsonModel<JsonModels.JsonApplication>
public partial class Application(JsonApplication jsonModel, RestClient client)
: ClientEntity(client), IJsonModel<JsonApplication>
{
JsonModels.JsonApplication IJsonModel<JsonModels.JsonApplication>.JsonModel => _jsonModel;
private readonly JsonModels.JsonApplication _jsonModel;

/// <summary>
/// Constructs an <see cref="Application"/> using a JSON Model and <see cref="RestClient"/>.
/// </summary>
/// <param name="jsonModel">The JSON model to create an <see cref="Application"/> from.</param>
/// <param name="client">The <see cref="RestClient"/> to use for construction.</param>
public Application(JsonModels.JsonApplication jsonModel, RestClient client) : base(client)
{
_jsonModel = jsonModel;

var bot = jsonModel.Bot;
if (bot is not null)
Bot = new(bot, client);

var owner = jsonModel.Owner;
if (owner is not null)
Owner = new(owner, client);

var team = jsonModel.Team;
if (team is not null)
Team = new(team, client);

var guild = jsonModel.Guild;
if (guild is not null)
Guild = new(guild, client);

var installParams = jsonModel.InstallParams;
if (installParams is not null)
InstallParams = new(installParams);

var integrationTypesConfiguration = jsonModel.IntegrationTypesConfiguration;
if (integrationTypesConfiguration is not null)
IntegrationTypesConfiguration = integrationTypesConfiguration.ToDictionary(i => i.Key, i => new ApplicationIntegrationTypeConfiguration(i.Value));
}
JsonApplication IJsonModel<JsonApplication>.JsonModel => jsonModel;

/// <summary>
/// The application's ID..
/// </summary>
public override ulong Id => _jsonModel.Id;
public override ulong Id => jsonModel.Id;

/// <summary>
/// The application's name.
/// </summary>
public string Name => _jsonModel.Name;
public string Name => jsonModel.Name;

/// <summary>
/// The application's icon hash.
/// </summary>
public string? IconHash => _jsonModel.IconHash;
public string? IconHash => jsonModel.IconHash;

/// <summary>
/// The application's description.
/// </summary>
public string Description => _jsonModel.Description;
public string Description => jsonModel.Description;

/// <summary>
/// A list of the application's RPC origin URLs if enabled, otherwise <see langword="null"/>.
/// </summary>
public IReadOnlyList<string> RpcOrigins => _jsonModel.RpcOrigins;
public IReadOnlyList<string> RpcOrigins => jsonModel.RpcOrigins;

/// <summary>
/// Whether users other than the owner can add the application to guilds.
/// </summary>
public bool? BotPublic => _jsonModel.BotPublic;
public bool? BotPublic => jsonModel.BotPublic;

/// <summary>
/// Whether the application's bot will only join upon completion of the full OAuth2 code grant flow.
/// </summary>
public bool? BotRequireCodeGrant => _jsonModel.BotRequireCodeGrant;
public bool? BotRequireCodeGrant => jsonModel.BotRequireCodeGrant;

/// <summary>
/// The application's user object, representing its bot.
/// </summary>
public User? Bot { get; }
public User? Bot { get; } = jsonModel.Bot is { } bot ? new(bot, client) : null;

/// <summary>
/// The application's Terms of Service URL.
/// </summary>
public string? TermsOfServiceUrl => _jsonModel.TermsOfServiceUrl;
public string? TermsOfServiceUrl => jsonModel.TermsOfServiceUrl;

/// <summary>
/// The application's Privacy Policy URL.
/// </summary>
public string? PrivacyPolicyUrl => _jsonModel.PrivacyPolicyUrl;
public string? PrivacyPolicyUrl => jsonModel.PrivacyPolicyUrl;

/// <summary>
/// The application owner's user object.
/// </summary>
public User? Owner { get; }
public User? Owner { get; } = jsonModel.Owner is { } owner ? new(owner, client) : null;

/// <summary>
/// A hex-encoded verification key, used for HTTP interactions and the GameSDK's GetTicket endpoint.
/// </summary>
public string VerifyKey => _jsonModel.VerifyKey;
public string VerifyKey => jsonModel.VerifyKey;

/// <summary>
/// The team the application belongs to, if any.
/// </summary>
public Team? Team { get; }
public Team? Team { get; } = jsonModel.Team is { } team ? new(team, client) : null;

/// <summary>
/// The ID corresponding to the application's guild.
/// </summary>
public ulong? GuildId => _jsonModel.GuildId;
public ulong? GuildId => jsonModel.GuildId;

/// <summary>
/// The application guild's object.
/// </summary>
public RestGuild? Guild { get; }
public RestGuild? Guild { get; } = jsonModel.Guild is { } guild ? new(guild, client) : null;

/// <summary>
/// The ID of the application's Game SKU if it exists, otherwise <see langword="null"/>.
/// </summary>
public ulong? PrimarySkuId => _jsonModel.PrimarySkuId;
public ulong? PrimarySkuId => jsonModel.PrimarySkuId;

/// <summary>
/// The URL slug that links to an application's store page if it exists, otherwise <see langword="null"/>.
/// </summary>
public string? Slug => _jsonModel.Slug;
public string? Slug => jsonModel.Slug;

/// <summary>
/// The cover image hash for the application's default rich presence invite.
/// </summary>
public string? CoverImageHash => _jsonModel.CoverImageHash;
public string? CoverImageHash => jsonModel.CoverImageHash;

/// <summary>
/// The application's public flags.
/// </summary>
public ApplicationFlags? Flags => _jsonModel.Flags;
public ApplicationFlags? Flags => jsonModel.Flags;

/// <summary>
/// The approximate number of guilds the application has been added to.
/// </summary>
public int? ApproximateGuildCount => _jsonModel.ApproximateGuildCount;
public int? ApproximateGuildCount => jsonModel.ApproximateGuildCount;

/// <summary>
/// The approximate number of users that have installed the application.
/// </summary>
public int? ApproximateUserInstallCount => _jsonModel.ApproximateUserInstallCount;
public int? ApproximateUserInstallCount => jsonModel.ApproximateUserInstallCount;

/// <summary>
/// A list of the application's redirect URIs.
/// </summary>
public IReadOnlyList<string>? RedirectUris => _jsonModel.RedirectUris;
public IReadOnlyList<string>? RedirectUris => jsonModel.RedirectUris;

/// <summary>
/// The application's interactions endpoint URL.
/// </summary>
public string? InteractionsEndpointUrl => _jsonModel.InteractionsEndpointUrl;
public string? InteractionsEndpointUrl => jsonModel.InteractionsEndpointUrl;

/// <summary>
/// The application's role connection verification URL.
/// </summary>
public string? RoleConnectionsVerificationUrl => _jsonModel.RoleConnectionsVerificationUrl;
public string? RoleConnectionsVerificationUrl => jsonModel.RoleConnectionsVerificationUrl;

/// <summary>
/// The application's event webhooks URL to receive webhook events.
/// </summary>
public string? EventWebhooksUrl => _jsonModel.EventWebhooksUrl;
public string? EventWebhooksUrl => jsonModel.EventWebhooksUrl;

/// <summary>
/// The application's configuration for webhook events.
/// </summary>
public ApplicationEventWebhooksStatus EventWebhooksStatus => _jsonModel.EventWebhooksStatus;
public ApplicationEventWebhooksStatus EventWebhooksStatus => jsonModel.EventWebhooksStatus;

/// <summary>
/// A list of event webhook types that the application supports.
/// </summary>
public IReadOnlyList<string>? EventWebhooksTypes => _jsonModel.EventWebhooksTypes;
public IReadOnlyList<string>? EventWebhooksTypes => jsonModel.EventWebhooksTypes;

/// <summary>
/// A list of the application's tags, describing its content and functionality.
/// </summary>
/// <remarks>
/// A maximum of 5 tags is supported.
/// </remarks>
public IReadOnlyList<string>? Tags => _jsonModel.Tags;
public IReadOnlyList<string>? Tags => jsonModel.Tags;

/// <summary>
/// The application's default in-application authorization URL if enabled, otherwise <see langword="null"/>.
/// </summary>
public ApplicationInstallParams? InstallParams { get; }
public ApplicationInstallParams? InstallParams { get; } = jsonModel.InstallParams is { } installParams ? new(installParams) : null;

/// <summary>
/// A list of the application's default scopes and permissions, for each supported installation context.
/// </summary>
public IReadOnlyDictionary<ApplicationIntegrationType, ApplicationIntegrationTypeConfiguration>? IntegrationTypesConfiguration { get; }
= jsonModel.IntegrationTypesConfiguration?.ToDictionary(i => i.Key, i => new ApplicationIntegrationTypeConfiguration(i.Value));

/// <summary>
/// The application's default custom install URL if enabled, otherwise <see langword="null"/>.
/// </summary>
public string? CustomInstallUrl => _jsonModel.CustomInstallUrl;
public string? CustomInstallUrl => jsonModel.CustomInstallUrl;

/// <summary>
/// Gets the <see cref="ImageUrl"/> of the application's icon.
Expand All @@ -220,19 +189,4 @@ public Application(JsonModels.JsonApplication jsonModel, RestClient client) : ba
/// <param name="assetId">The ID of the asset to get an <see cref="ImageUrl"/> for.</param>
/// <param name="format">The format of the returned <see cref="ImageUrl"/>.</param>
public ImageUrl? GetAssetUrl(ulong assetId, ImageFormat format) => ImageUrl.ApplicationAsset(Id, assetId, format);

/// <summary>
/// Gets the <see cref="ImageUrl"/> of an achievement associated with the application.
/// </summary>
/// <param name="achievementId">The ID of the achievement to get an <see cref="ImageUrl"/> for.</param>
/// <param name="iconHash">The hash of the achievement's icon.</param>
/// <param name="format">The format of the returned <see cref="ImageUrl"/>.</param>
public ImageUrl? GetAchievementIconUrl(ulong achievementId, string iconHash, ImageFormat format) => ImageUrl.AchievementIcon(Id, achievementId, iconHash, format);

/// <summary>
/// Gets the <see cref="ImageUrl"/> of a store page asset associated with the application.
/// </summary>
/// <param name="assetId">The ID of the asset to get an <see cref="ImageUrl"/> for.</param>
/// <param name="format">The format of the returned <see cref="ImageUrl"/>.</param>
public ImageUrl? GetStorePageAssetUrl(ulong assetId, ImageFormat format) => ImageUrl.StorePageAsset(Id, assetId, format);
}
21 changes: 9 additions & 12 deletions NetCord/ApplicationCommandInteraction.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using NetCord.Gateway;
using NetCord.JsonModels;
using NetCord.Rest;

namespace NetCord;
namespace NetCord.Gateway;

/// <summary>
/// Acts as a base class for application commands, such as slash commands and message commands.
/// </summary>
public abstract class ApplicationCommandInteraction : Interaction
public abstract class ApplicationCommandInteraction(JsonInteraction jsonModel, Guild? guild, InteractionResponseDelegate sendResponseAsync, RestClient client)
: Interaction(jsonModel, guild, sendResponseAsync, client)
{
private protected ApplicationCommandInteraction(JsonModels.JsonInteraction jsonModel, Guild? guild, InteractionResponseDelegate sendResponseAsync, RestClient client) : base(jsonModel, guild, sendResponseAsync, client)
{
}

/// <summary>
/// Holds the containing application command's data.
/// </summary>
Expand All @@ -21,25 +18,25 @@ private protected ApplicationCommandInteraction(JsonModels.JsonInteraction jsonM
/// <summary>
/// Contains data for an invoked <see cref="ApplicationCommand"/>.
/// </summary>
public class ApplicationCommandInteractionData(JsonModels.JsonInteractionData jsonModel) : InteractionData(jsonModel)
public class ApplicationCommandInteractionData(JsonInteractionData jsonModel) : InteractionData(jsonModel)
{
/// <summary>
/// The invoked <see cref="ApplicationCommand"/>'s ID.
/// </summary>
public ulong Id => _jsonModel.Id.GetValueOrDefault();
public ulong Id => jsonModel.Id.GetValueOrDefault();

/// <summary>
/// The invoked <see cref="ApplicationCommand"/>'s name.
/// </summary>
public string Name => _jsonModel.Name!;
public string Name => jsonModel.Name!;

/// <summary>
/// The invoked <see cref="ApplicationCommand"/>'s type.
/// </summary>
public ApplicationCommandType Type => _jsonModel.Type.GetValueOrDefault();
public ApplicationCommandType Type => jsonModel.Type.GetValueOrDefault();

/// <summary>
/// The ID of the guild the <see cref="ApplicationCommand"/> is registered to.
/// </summary>
public ulong? GuildId => _jsonModel.GuildId;
public ulong? GuildId => jsonModel.GuildId;
}
17 changes: 4 additions & 13 deletions NetCord/ApplicationIntegrationTypeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,13 @@ namespace NetCord;
/// <summary>
/// Represents additional configuration for a specific application installation context.
/// </summary>
public class ApplicationIntegrationTypeConfiguration : IJsonModel<JsonApplicationIntegrationTypeConfiguration>
public class ApplicationIntegrationTypeConfiguration(JsonApplicationIntegrationTypeConfiguration jsonModel)
: IJsonModel<JsonApplicationIntegrationTypeConfiguration>
{
private readonly JsonApplicationIntegrationTypeConfiguration _jsonModel;
JsonApplicationIntegrationTypeConfiguration IJsonModel<JsonApplicationIntegrationTypeConfiguration>.JsonModel => _jsonModel;

public ApplicationIntegrationTypeConfiguration(JsonApplicationIntegrationTypeConfiguration jsonModel)
{
_jsonModel = jsonModel;

var oAuth2InstallParams = jsonModel.OAuth2InstallParams;
if (oAuth2InstallParams is not null)
OAuth2InstallParams = new(oAuth2InstallParams);
}
JsonApplicationIntegrationTypeConfiguration IJsonModel<JsonApplicationIntegrationTypeConfiguration>.JsonModel => jsonModel;

/// <summary>
/// Additional installation params to apply to the specific install context.
/// </summary>
public ApplicationInstallParams? OAuth2InstallParams { get; }
public ApplicationInstallParams? OAuth2InstallParams { get; } = jsonModel.OAuth2InstallParams is { } oAuth2InstallParams ? new(oAuth2InstallParams) : null;
}
Loading
Loading