Skip to content

Commit

Permalink
Implement support for monetized apps.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Oct 29, 2023
1 parent d1d2c21 commit d4ec1e8
Show file tree
Hide file tree
Showing 49 changed files with 1,651 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// IEntitlementCreate.cs
//
// Author:
// Jarl Gullberg <jarl.gullberg@gmail.com>
//
// 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.Discord.API.Abstractions.Objects;

namespace Remora.Discord.API.Abstractions.Gateway.Events;

/// <summary>
/// Represents a user's initial subscription to an SKU.
/// </summary>
[PublicAPI]
public interface IEntitlementCreate : IEntitlement, IGatewayEvent
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// IEntitlementDelete.cs
//
// Author:
// Jarl Gullberg <jarl.gullberg@gmail.com>
//
// 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.Discord.API.Abstractions.Objects;

namespace Remora.Discord.API.Abstractions.Gateway.Events;

/// <summary>
/// Represents a removal of an entitlement from a user.
/// </summary>
[PublicAPI]
public interface IEntitlementDelete : IEntitlement, IGatewayEvent
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// IEntitlementUpdate.cs
//
// Author:
// Jarl Gullberg <jarl.gullberg@gmail.com>
//
// 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.Discord.API.Abstractions.Objects;

namespace Remora.Discord.API.Abstractions.Gateway.Events;

/// <summary>
/// Represents a renewal of a user's entitlement to an SKU.
/// </summary>
[PublicAPI]
public interface IEntitlementUpdate : IEntitlement, IGatewayEvent
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//

using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using OneOf;
using Remora.Rest.Core;
Expand Down Expand Up @@ -116,4 +117,9 @@ public interface IInteraction
/// Gets the locale of the guild the interaction was sent from.
/// </summary>
Optional<string> GuildLocale { get; }

/// <summary>
/// Gets, for monetized apps, any entitlements for the invoking user.
/// </summary>
IReadOnlyList<IEntitlement> Entitlements { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,10 @@ public enum InteractionCallbackType
/// <remarks>
/// Only relevant for component-based interactions and application commands.
/// </remarks>
Modal = 9
Modal = 9,

/// <summary>
/// Respond to an interaction with an upgrade button. Only available for apps with monetization enabled.
/// </summary>
PremiumRequired = 10
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// EntitlementOwnerType.cs
//
// Author:
// Jarl Gullberg <jarl.gullberg@gmail.com>
//
// 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>
/// Enumerates various entitlement owner types.
/// </summary>
[PublicAPI]
public enum EntitlementOwnerType
{
/// <summary>
/// The entitlement is owned by a guild.
/// </summary>
Guild = 1,

/// <summary>
/// The entitlement is owned by a user.
/// </summary>
User = 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// EntitlementType.cs
//
// Author:
// Jarl Gullberg <jarl.gullberg@gmail.com>
//
// 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>
/// Enumerates various entitlement types.
/// </summary>
[PublicAPI]
public enum EntitlementType
{
/// <summary>
/// The entitlement was purchased as an app subscription.
/// </summary>
ApplicationSubscription = 8
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// IEntitlement.cs
//
// Author:
// Jarl Gullberg <jarl.gullberg@gmail.com>
//
// 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;
using JetBrains.Annotations;
using Remora.Rest.Core;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents information about a user's access to monetized application features.
/// </summary>
[PublicAPI]
public interface IEntitlement : IPartialEntitlement
{
/// <summary>
/// Gets the ID of the entitlement.
/// </summary>
new Snowflake ID { get; }

/// <summary>
/// Gets the ID of the SKU.
/// </summary>
new Snowflake SKUID { get; }

/// <summary>
/// Gets the ID of the parent application.
/// </summary>
new Snowflake ApplicationID { get; }

/// <summary>
/// Gets the ID of the user that is granted access to the entitlement's SKU.
/// </summary>
new Optional<Snowflake> UserID { get; }

/// <summary>
/// Gets the type of the entitlement.
/// </summary>
new EntitlementType Type { get; }

/// <summary>
/// Gets a value indicating whether the entitlement has been deleted.
/// </summary>
new bool IsDeleted { get; }

/// <summary>
/// Gets the start time at which the entitlement is valid.
/// </summary>
new Optional<DateTimeOffset> StartsAt { get; }

/// <summary>
/// Gets the end time at which the entitlement is no longer valid.
/// </summary>
new Optional<DateTimeOffset> EndsAt { get; }

/// <summary>
/// Gets the ID of the guild that is granted access to the entitlement's SKU.
/// </summary>
new Optional<Snowflake> GuildID { get; }

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

/// <inheritdoc/>
Optional<Snowflake> IPartialEntitlement.SKUID => this.SKUID;

/// <inheritdoc/>
Optional<Snowflake> IPartialEntitlement.UserID => this.UserID;

/// <inheritdoc/>
Optional<Snowflake> IPartialEntitlement.GuildID => this.GuildID;

/// <inheritdoc/>
Optional<Snowflake> IPartialEntitlement.ApplicationID => this.ApplicationID;

/// <inheritdoc/>
Optional<EntitlementType> IPartialEntitlement.Type => this.Type;

/// <inheritdoc/>
Optional<bool> IPartialEntitlement.IsDeleted => this.IsDeleted;

/// <inheritdoc/>
Optional<DateTimeOffset> IPartialEntitlement.StartsAt => this.StartsAt;

/// <inheritdoc/>
Optional<DateTimeOffset> IPartialEntitlement.EndsAt => this.EndsAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// IPartialEntitlement.cs
//
// Author:
// Jarl Gullberg <jarl.gullberg@gmail.com>
//
// 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;
using JetBrains.Annotations;
using Remora.Rest.Core;

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Represents partial information about a user's access to monetized application features.
/// </summary>
[PublicAPI]
public interface IPartialEntitlement
{
/// <inheritdoc cref="IEntitlement.ID"/>
Optional<Snowflake> ID { get; }

/// <inheritdoc cref="IEntitlement.SKUID"/>
Optional<Snowflake> SKUID { get; }

/// <inheritdoc cref="IEntitlement.ApplicationID"/>
Optional<Snowflake> ApplicationID { get; }

/// <inheritdoc cref="IEntitlement.UserID"/>
Optional<Snowflake> UserID { get; }

/// <inheritdoc cref="IEntitlement.Type"/>
Optional<EntitlementType> Type { get; }

/// <inheritdoc cref="IEntitlement.IsDeleted"/>
Optional<bool> IsDeleted { get; }

/// <inheritdoc cref="IEntitlement.StartsAt"/>
Optional<DateTimeOffset> StartsAt { get; }

/// <inheritdoc cref="IEntitlement.EndsAt"/>
Optional<DateTimeOffset> EndsAt { get; }

/// <inheritdoc cref="IEntitlement.GuildID"/>
Optional<Snowflake> GuildID { get; }
}
Loading

0 comments on commit d4ec1e8

Please sign in to comment.