Skip to content

Commit

Permalink
Merge branch 'main' into fix/user-apps
Browse files Browse the repository at this point in the history
  • Loading branch information
VelvetToroyashi authored May 4, 2024
2 parents 9e027f5 + 61691e8 commit 3ea760b
Show file tree
Hide file tree
Showing 60 changed files with 1,324 additions and 656 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
dotnet build -c Release --no-restore
- name: Test
run: dotnet test -c Release --no-restore --no-build --verbosity minimal
run: dotnet test -c Release --no-restore --no-build --verbosity minimal --collect:"XPlat Code Coverage" --results-directory ./coverage

- name: Inspect
uses: JetBrains/[email protected]
Expand All @@ -46,6 +46,23 @@ jobs:
no-build: true
telemetry-optout: true

- name: Coverage
uses: irongut/[email protected]
with:
filename: coverage/**/coverage.cobertura.xml
badge: true
format: markdown
indicators: true
output: both
thresholds: '60 80'

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md

- name: Package
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: dotnet pack -c Release --no-restore --no-build --version-suffix "github$GITHUB_RUN_ID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ public interface IApplicationCommandPermissions
/// <summary>
/// Gets a value indicating whether the referenced entity has permission to use the command.
/// </summary>
bool HasPermission { get; }
bool HasPermission { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public interface IMessage : IPartialMessage
/// <summary>
/// Gets the message reference. Sent with cross-posted messages.
/// </summary>
new Optional<IMessageReference> MessageReference { get; }
new Optional<IMessageReference> MessageReference { get; }

/// <summary>
/// Gets a set of bitwise flags describing extra features of the message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public interface IPartialMessage
Optional<Snowflake> ApplicationID { get; }

/// <inheritdoc cref="IMessage.MessageReference" />
Optional<IMessageReference> MessageReference { get; }
Optional<IMessageReference> MessageReference { get; }

/// <inheritdoc cref="IMessage.Flags" />
Optional<MessageFlags> Flags { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,41 @@ namespace Remora.Discord.API.Abstractions.Objects;
[PublicAPI]
public enum EntitlementType
{
/// <summary>
/// The entitlement was purchased by a user.
/// </summary>
Purchase = 1,

/// <summary>
/// The entitlement is a Nitro subscription.
/// </summary>
PremiumSubscription = 2,

/// <summary>
/// The entitlement was gifted by a developer.
/// </summary>
DeveloperGift = 3,

/// <summary>
/// The entitlement was purchased by a developer in application test mode.
/// </summary>
TestModePurchase = 4,

/// <summary>
/// The entitlement was granted when the SKU was free.
/// </summary>
FreePurchase = 5,

/// <summary>
/// The entitlement was gifted by another user.
/// </summary>
UserGift = 6,

/// <summary>
/// The entitlement was claimed by a user for free as part of their Nitro subscription.
/// </summary>
PremiumPurchase = 7,

/// <summary>
/// The entitlement was purchased as an app subscription.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,22 @@ public interface IEntitlement : IPartialEntitlement
/// </summary>
new Optional<Snowflake> GuildID { get; }

/// <summary>
/// Gets a value indicating whether the entitlement has been consumed.
/// </summary>
new Optional<bool> IsConsumed { 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;
Optional<Snowflake> IPartialEntitlement.ApplicationID => this.ApplicationID;

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

/// <inheritdoc/>
Optional<EntitlementType> IPartialEntitlement.Type => this.Type;
Expand All @@ -103,4 +105,10 @@ public interface IEntitlement : IPartialEntitlement

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

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

/// <inheritdoc/>
Optional<bool> IPartialEntitlement.IsConsumed => this.IsConsumed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ public interface IPartialEntitlement

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

/// <inheritdoc cref="IEntitlement.IsConsumed"/>
Optional<bool> IsConsumed { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// IBulkBanResponse.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.Rest;

/// <summary>
/// Represents a response to a bulk banning request.
/// </summary>
[PublicAPI]
public interface IBulkBanResponse
{
/// <summary>
/// Gets the IDs of the users who were successfully banned.
/// </summary>
IReadOnlyList<Snowflake> BannedUsers { get; }

/// <summary>
/// Gets the IDs of the users who were not banned.
/// </summary>
IReadOnlyList<Snowflake> FailedUsers { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ Task<Result<IMessage>> GetChannelMessageAsync
/// mentioned in this parameter will be deleted.
/// </param>
/// <param name="flags">The message flags.</param>
/// <param name="enforceNonce">Indicates whether messages should be deduplicated using the passed nonce.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A creation result which may or may not have succeeded.</returns>
Task<Result<IMessage>> CreateMessageAsync
Expand All @@ -507,6 +508,7 @@ Task<Result<IMessage>> CreateMessageAsync
Optional<IReadOnlyList<Snowflake>> stickerIDs = default,
Optional<IReadOnlyList<OneOf<FileData, IPartialAttachment>>> attachments = default,
Optional<MessageFlags> flags = default,
Optional<bool> enforceNonce = default,
CancellationToken ct = default
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,26 @@ Task<Result> RemoveGuildBanAsync
CancellationToken ct = default
);

/// <summary>
/// Bans up to 200 users from the given guild.
/// </summary>
/// <param name="guildID">The ID of the guild.</param>
/// <param name="userIDs">The IDs of the users to ban.</param>
/// <param name="deleteMessageSeconds">
/// The number of seconds to delete messages for (0-604800). Defaults to 0.
/// </param>
/// <param name="reason">The reason to mark the action in the audit log with.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>The bulk banning response.</returns>
Task<Result<IBulkBanResponse>> BulkGuildBanAsync
(
Snowflake guildID,
IReadOnlyList<Snowflake> userIDs,
Optional<int> deleteMessageSeconds = default,
Optional<string> reason = default,
CancellationToken ct = default
);

/// <summary>
/// Gets the roles in the guild.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ Task<Result<IReadOnlyList<IEntitlement>>> ListEntitlementsAsync
CancellationToken ct = default
);

/// <summary>
/// Marks the given one-time purchase item as consumed.
/// </summary>
/// <param name="applicationID">The ID of the application.</param>
/// <param name="entitlementID">The ID of the entitlement.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A value representing the result of the operation.</returns>
Task<Result> ConsumeEntitlementAsync
(
Snowflake applicationID,
Snowflake entitlementID,
CancellationToken ct = default
);

/// <summary>
/// Creates a test entitlement to a given SKU for a given guild or user.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<Compile Update="API\Rest\IChannelPositionModification.cs">
<DependentUpon>IDiscordRestGuildAPI.cs</DependentUpon>
</Compile>
<Compile Update="API\Rest\IBulkBanResponse.cs">
<DependentUpon>IDiscordRestGuildAPI.cs</DependentUpon>
</Compile>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -1046,5 +1046,10 @@ public enum DiscordError
/// <summary>
/// Onboarding cannot be updated while requirements are not met.
/// </summary>
CannotUpdateOnboarding = 350001
CannotUpdateOnboarding = 350001,

/// <summary>
/// Failed to bulk ban the given set of users.
/// </summary>
FailedToBanUsers = 500000
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ IReadOnlyList<Snowflake> ExemptChannels
IsEnabled,
ExemptRoles,
ExemptChannels
), IAutoModerationRuleCreate;
),
IAutoModerationRuleCreate;
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ IReadOnlyList<Snowflake> ExemptChannels
IsEnabled,
ExemptRoles,
ExemptChannels
), IAutoModerationRuleDelete;
),
IAutoModerationRuleDelete;
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ IReadOnlyList<Snowflake> ExemptChannels
IsEnabled,
ExemptRoles,
ExemptChannels
), IAutoModerationRuleUpdate;
),
IAutoModerationRuleUpdate;
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public record EntitlementCreate
bool IsDeleted,
Optional<DateTimeOffset> StartsAt = default,
Optional<DateTimeOffset> EndsAt = default,
Optional<Snowflake> GuildID = default
Optional<Snowflake> GuildID = default,
Optional<bool> IsConsumed = default
) : IEntitlementCreate;
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public record EntitlementDelete
bool IsDeleted,
Optional<DateTimeOffset> StartsAt = default,
Optional<DateTimeOffset> EndsAt = default,
Optional<Snowflake> GuildID = default
Optional<Snowflake> GuildID = default,
Optional<bool> IsConsumed = default
) : IEntitlementDelete;
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public record EntitlementUpdate
bool IsDeleted,
Optional<DateTimeOffset> StartsAt = default,
Optional<DateTimeOffset> EndsAt = default,
Optional<Snowflake> GuildID = default
Optional<Snowflake> GuildID = default,
Optional<bool> IsConsumed = default
) : IEntitlementUpdate;
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ public record Entitlement
bool IsDeleted,
Optional<DateTimeOffset> StartsAt = default,
Optional<DateTimeOffset> EndsAt = default,
Optional<Snowflake> GuildID = default
Optional<Snowflake> GuildID = default,
Optional<bool> IsConsumed = default
) : IEntitlement;
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ public record PartialEntitlement
Optional<bool> IsDeleted = default,
Optional<DateTimeOffset> StartsAt = default,
Optional<DateTimeOffset> EndsAt = default,
Optional<Snowflake> GuildID = default
Optional<Snowflake> GuildID = default,
Optional<bool> IsConsumed = default
) : IPartialEntitlement;
36 changes: 36 additions & 0 deletions Backend/Remora.Discord.API/API/Rest/BulkBanResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// BulkBanResponse.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.Discord.API.Abstractions.Rest;
using Remora.Rest.Core;

namespace Remora.Discord.API.Rest;

/// <inheritdoc />
[PublicAPI]
public record BulkBanResponse
(
IReadOnlyList<Snowflake> BannedUsers,
IReadOnlyList<Snowflake> FailedUsers
) : IBulkBanResponse;
Loading

0 comments on commit 3ea760b

Please sign in to comment.