Skip to content

Commit

Permalink
Merge pull request #327 from VelvetToroyashi/feat/user-apps
Browse files Browse the repository at this point in the history
Add support for user-installable applications
  • Loading branch information
Nihlus authored Apr 6, 2024
2 parents 5219a50 + 5b4b055 commit 178574c
Show file tree
Hide file tree
Showing 46 changed files with 894 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .idea/.idea.Remora.Discord/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// ApplicationIntegrationType.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents valid locations for users to install application integrations.
/// </summary>
[PublicAPI]
public enum ApplicationIntegrationType
{
/// <summary>
/// Specifies that the integration can be installed on a guild.
/// </summary>
GuildInstallable = 0,

/// <summary>
/// Specifies that the integration can be installed on a user.
/// </summary>
UserInstallable = 1,
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public interface IApplication : IPartialApplication
/// </summary>
new Optional<Uri> CustomInstallUrl { get; }

/// <summary>
/// Gets the application's integration type configurations.
/// </summary>
new IReadOnlyDictionary<ApplicationIntegrationType, IApplicationIntegrationTypeConfig?> IntegrationTypesConfig { get; }

/// <inheritdoc/>
Optional<Snowflake> IPartialApplication.ID => this.ID;

Expand Down Expand Up @@ -242,4 +247,7 @@ public interface IApplication : IPartialApplication

/// <inheritdoc/>
Optional<Uri> IPartialApplication.CustomInstallUrl => this.CustomInstallUrl;

/// <inheritdoc/>
Optional<IReadOnlyDictionary<ApplicationIntegrationType, IApplicationIntegrationTypeConfig?>> IPartialApplication.IntegrationTypesConfig => new(this.IntegrationTypesConfig);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// IApplicationIntegrationTypeConfig.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// The integration type configuration for an application.
/// </summary>
[PublicAPI]
public interface IApplicationIntegrationTypeConfig
{
/// <summary>
/// Gets the OAuth2 install parameters for the integration type.
/// </summary>
public IApplicationOAuth2InstallParams OAuth2InstallParams { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// IApplicationOAuth2InstallParams.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Collections.Generic;
using JetBrains.Annotations;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents the OAuth2 install parameters for an application.
/// </summary>
[PublicAPI]
public interface IApplicationOAuth2InstallParams
{
/// <summary>
/// Gets the permissions required for the application.
/// </summary>
/// <remarks>
/// Only applicable if <see cref="IApplicationOAuth2InstallParams.Scopes"/> includes `bot`.
/// </remarks>
IDiscordPermissionSet Permissions { get; }

/// <summary>
/// Gets the list of OAuth2 scopes required for the application.
/// </summary>
IReadOnlyList<string> Scopes { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,7 @@ public interface IPartialApplication

/// <inheritdoc cref="IApplication.CustomInstallUrl" />
Optional<Uri> CustomInstallUrl { get; }

/// <inheritdoc cref="IApplication.IntegrationTypesConfig" />
Optional<IReadOnlyDictionary<ApplicationIntegrationType, IApplicationIntegrationTypeConfig?>> IntegrationTypesConfig { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,14 @@ public interface IApplicationCommand
/// Gets a value indicating whether this command is age-restricted.
/// </summary>
Optional<bool> IsNsfw { get; }

/// <summary>
/// Gets a value indicating the contexts in which this command can be installed.
/// </summary>
Optional<IReadOnlyList<ApplicationIntegrationType>> IntegrationTypes { get; }

/// <summary>
/// Gets a value indicating the contexts in which this command can be invoked.
/// </summary>
Optional<IReadOnlyList<InteractionContextType>> Contexts { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ public interface IBulkApplicationCommandData

/// <inheritdoc cref="IApplicationCommand.IsNsfw"/>
Optional<bool> IsNsfw { get; }

/// <inheritdoc cref="IApplicationCommand.IntegrationTypes"/>
Optional<IReadOnlyList<ApplicationIntegrationType>> IntegrationTypes { get; }

/// <inheritdoc cref="IApplicationCommand.Contexts"/>
Optional<IReadOnlyList<InteractionContextType>> Contexts { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// IApplicationCommandInteractionMetadata.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents metadata related to application commands.
/// </summary>
[PublicAPI]
public interface IApplicationCommandInteractionMetadata : IMessageInteractionMetadata
{
/// <summary>
/// Gets the name of the command.
/// </summary>
string Name { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public interface IInteraction
/// <summary>
/// Gets the computed permissions for the application in the context of the interaction's execution.
/// </summary>
Optional<IDiscordPermissionSet> AppPermissions { get; }
IDiscordPermissionSet AppPermissions { get; }

/// <summary>
/// Gets the locale of the invoking user.
Expand All @@ -122,4 +122,23 @@ public interface IInteraction
/// Gets, for monetized apps, any entitlements for the invoking user.
/// </summary>
IReadOnlyList<IEntitlement> Entitlements { get; }

/// <summary>
/// Gets the context of the interaction.
/// </summary>
Optional<InteractionContextType> Context { get; }

/// <summary>
/// Gets the integrations that authorized the interaction.
/// </summary>
/// <remarks>
/// This is a mapping of the integration type to the ID of its resource.
/// <para>
/// The dictionary contains the following, given the circumstances: <br/>
/// - If the integration is installed to a user, a key of <see cref="ApplicationIntegrationType.UserInstallable"/> and the value is the user ID. <br/>
/// - If the integration is installed to a guild, a key of <see cref="ApplicationIntegrationType.GuildInstallable"/> and the value is the guild ID.
/// If the interaction is sent outside the context of a guild, the value is always zero.<br/>
/// </para>
/// </remarks>
Optional<IReadOnlyDictionary<ApplicationIntegrationType, Snowflake>> AuthorizingIntegrationOwners { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// IMessageComponentInteractionMetadata.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using JetBrains.Annotations;
using Remora.Rest.Core;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents metadata related to a message component interaction.
/// </summary>
[PublicAPI]
public interface IMessageComponentInteractionMetadata : IMessageInteractionMetadata
{
/// <summary>
/// Gets the ID of the message that was interacted with.
/// </summary>
Snowflake InteractedMessageID { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// IMessageInteractionMetadata.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Collections.Generic;
using JetBrains.Annotations;
using Remora.Rest.Core;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents the metadata of an application command interaction.
/// </summary>
[PublicAPI]
public interface IMessageInteractionMetadata
{
/// <summary>
/// Gets the ID of the interaction.
/// </summary>
Snowflake ID { get; }

/// <summary>
/// Gets the ID of the user who triggered the interaction.
/// </summary>
Snowflake UserID { get; }

/// <summary>
/// Gets the type of the interaction.
/// </summary>
InteractionType Type { get; }

/// <summary>
/// Gets the ID of the original response message. Only applicable to followup messages.
/// </summary>
Optional<Snowflake> OriginalResponseMessageID { get; }

/// <summary>
/// Gets the integrations that authorized the interaction.
/// </summary>
/// <remarks>
/// This is a mapping of the integration type to the ID of its resource.
/// <para>
/// The dictionary contains the following, given the circumstances: <br/>
/// - If the integration is installed to a user, a key of <see cref="ApplicationIntegrationType.UserInstallable"/> and the value is the user ID. <br/>
/// - If the integration is installed to a guild, a key of <see cref="ApplicationIntegrationType.GuildInstallable"/> and the value is the guild ID.
/// If the interaction is sent outside the context of a guild, the value is always zero.<br/>
/// </para>
/// </remarks>
IReadOnlyDictionary<ApplicationIntegrationType, Snowflake> AuthorizingIntegrationOwners { get; }
}
Loading

0 comments on commit 178574c

Please sign in to comment.