Skip to content

Commit

Permalink
Implement approximate guild count and partial guild.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Jul 14, 2023
1 parent 8035f68 commit 88f69d4
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ public interface IApplication : IPartialApplication
new ITeam? Team { get; }

/// <summary>
/// Gets the guild the game is linked to, if the application is a game sold on the Discord storefront.
/// Gets the guild the application is associated with.
/// </summary>
new Optional<Snowflake> GuildID { get; }

/// <summary>
/// Gets the associated guild object, if any.
/// </summary>
new Optional<IPartialGuild> Guild { get; }

/// <summary>
/// Gets the primary SKU ID of the game, if the application is a game sold on the Discord storefront.
/// </summary>
Expand All @@ -118,6 +123,11 @@ public interface IApplication : IPartialApplication
/// </summary>
new Optional<ApplicationFlags> Flags { get; }

/// <summary>
/// Gets an approximate count of the application's guild membership.
/// </summary>
new Optional<int> ApproximateGuildCount { get; }

/// <summary>
/// Gets up to 5 tags describing the content and functionality of the application.
/// </summary>
Expand Down Expand Up @@ -179,6 +189,9 @@ public interface IApplication : IPartialApplication
/// <inheritdoc/>
Optional<Snowflake> IPartialApplication.GuildID => this.GuildID;

/// <inheritdoc/>
Optional<IPartialGuild> IPartialApplication.Guild => this.Guild;

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

Expand All @@ -191,6 +204,9 @@ public interface IApplication : IPartialApplication
/// <inheritdoc/>
Optional<ApplicationFlags> IPartialApplication.Flags => this.Flags;

/// <inheritdoc/>
Optional<int> IPartialApplication.ApproximateGuildCount => this.ApproximateGuildCount;

/// <inheritdoc/>
Optional<IReadOnlyList<string>> IPartialApplication.Tags => this.Tags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public interface IPartialApplication
/// <inheritdoc cref="IApplication.GuildID" />
Optional<Snowflake> GuildID { get; }

/// <inheritdoc cref="IApplication.Guild" />
Optional<IPartialGuild> Guild { get; }

/// <inheritdoc cref="IApplication.PrimarySKUID" />
Optional<Snowflake> PrimarySKUID { get; }

Expand All @@ -84,6 +87,9 @@ public interface IPartialApplication
/// <inheritdoc cref="IApplication.Flags" />
Optional<ApplicationFlags> Flags { get; }

/// <inheritdoc cref="IApplication.ApproximateGuildCount" />
Optional<int> ApproximateGuildCount { get; }

/// <inheritdoc cref="IApplication.Tags" />
Optional<IReadOnlyList<string>> Tags { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,11 @@ Task<Result<IReadOnlyList<IApplicationRoleConnectionMetadata>>> UpdateApplicatio
IReadOnlyList<IApplicationRoleConnectionMetadata> records,
CancellationToken ct = default
);

/// <summary>
/// Gets the application object associated with the requesting user.
/// </summary>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>The application object.</returns>
Task<Result<IApplication>> GetCurrentApplicationAsync(CancellationToken ct = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ public record Application
string VerifyKey,
ITeam? Team,
Optional<Snowflake> GuildID = default,
Optional<IPartialGuild> Guild = default,
Optional<Snowflake> PrimarySKUID = default,
Optional<string> Slug = default,
Optional<IImageHash> CoverImage = default,
Optional<ApplicationFlags> Flags = default,
Optional<int> ApproximateGuildCount = default,
Optional<IReadOnlyList<string>> Tags = default,
Optional<IApplicationInstallParameters> InstallParams = default,
Optional<Uri> CustomInstallUrl = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ public record PartialApplication
Optional<string> VerifyKey = default,
Optional<ITeam?> Team = default,
Optional<Snowflake> GuildID = default,
Optional<IPartialGuild> Guild = default,
Optional<Snowflake> PrimarySKUID = default,
Optional<string> Slug = default,
Optional<IImageHash> CoverImage = default,
Optional<ApplicationFlags> Flags = default,
Optional<int> ApproximateGuildCount = default,
Optional<IReadOnlyList<string>> Tags = default,
Optional<IApplicationInstallParameters> InstallParams = default,
Optional<Uri> CustomInstallUrl = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,15 @@ public virtual async Task<Result<IReadOnlyList<IApplicationRoleConnectionMetadat
ct: ct
);
}

/// <inheritdoc />
public Task<Result<IApplication>> GetCurrentApplicationAsync(CancellationToken ct = default)
{
return this.RestHttpClient.GetAsync<IApplication>
(
"applications/@me",
b => b.WithRateLimitContext(this.RateLimitCache),
ct: ct
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2407,4 +2407,43 @@ public async Task ReturnsUnsuccessfulIfDescriptionIsTooLong()
ResultAssert.Unsuccessful(result);
}
}

/// <summary>
/// Tests the <see cref="DiscordRestApplicationAPI.GetCurrentApplicationAsync"/> method.
/// </summary>
public class GetCurrentApplicationAsync : RestAPITestBase<IDiscordRestApplicationAPI>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetCurrentApplicationAsync"/> class.
/// </summary>
/// <param name="fixture">The test fixture.</param>
public GetCurrentApplicationAsync(RestAPITestFixture fixture)
: base(fixture)
{
}

/// <summary>
/// Tests whether the API method performs its request correctly.
/// </summary>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
[Fact]
public async Task PerformsRequestCorrectly()
{
var api = CreateAPI
(
b => b
.Expect
(
HttpMethod.Get,
$"{Constants.BaseURL}applications/@me"
)
.WithNoContent()
.Respond("application/json", SampleRepository.Samples[typeof(IApplication)])
);

var result = await api.GetCurrentApplicationAsync();

ResultAssert.Successful(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
"owner_user_id": "999999999999999999"
},
"guild_id": "999999999999999999",
"guild": { },
"primary_sku_id": "999999999999999999",
"slug": "test",
"cover_image": "68b329da9893e34099c7d8ad5cb9c940",
"flags": 0,
"approximate_guild_count": 0,
"tags": [
"none"
],
Expand All @@ -49,4 +51,4 @@
},
"custom_install_url": "https://www.example.org",
"role_connections_verification_url": "https://www.example.org"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
"verify_key": "none",
"team": null,
"guild_id": "999999999999999999",
"guild": { },
"primary_sku_id": "999999999999999999",
"slug": "test",
"cover_image": "68b329da9893e34099c7d8ad5cb9c940",
"flags": 0,
"approximate_guild_count": 0,
"tags": [
"none"
],
Expand All @@ -29,4 +31,4 @@
},
"custom_install_url": "https://www.example.org",
"role_connections_verification_url": "https://www.example.org"
}
}

0 comments on commit 88f69d4

Please sign in to comment.