Skip to content

Commit

Permalink
Implement with_counts for user guild endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Jul 14, 2023
1 parent 8f8d27d commit 2d50e88
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ Task<Result<IUser>> ModifyCurrentUserAsync
/// <param name="before">Get guilds before this guild ID.</param>
/// <param name="after">Get guilds after this guild ID.</param>
/// <param name="limit">The maximum number of guilds to get (1-200). Defaults to 200.</param>
/// <param name="withCounts">Whether member and presence counts should be included.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A retrieval result which may or may not have succeeded.</returns>
Task<Result<IReadOnlyList<IPartialGuild>>> GetCurrentUserGuildsAsync
(
Optional<Snowflake> before = default,
Optional<Snowflake> after = default,
Optional<int> limit = default,
Optional<bool> withCounts = default,
CancellationToken ct = default
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ public Task<Result<IReadOnlyList<IPartialGuild>>> GetCurrentUserGuildsAsync
Optional<Snowflake> before = default,
Optional<Snowflake> after = default,
Optional<int> limit = default,
Optional<bool> withCounts = default,
CancellationToken ct = default
)
{
return _actual.GetCurrentUserGuildsAsync(before, after, limit, ct);
return _actual.GetCurrentUserGuildsAsync(before, after, limit, withCounts, ct);
}

/// <inheritdoc />
Expand Down
6 changes: 6 additions & 0 deletions Backend/Remora.Discord.Rest/API/Users/DiscordRestUserAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public virtual async Task<Result<IReadOnlyList<IPartialGuild>>> GetCurrentUserGu
Optional<Snowflake> before = default,
Optional<Snowflake> after = default,
Optional<int> limit = default,
Optional<bool> withCounts = default,
CancellationToken ct = default
)
{
Expand Down Expand Up @@ -155,6 +156,11 @@ public virtual async Task<Result<IReadOnlyList<IPartialGuild>>> GetCurrentUserGu
b.AddQueryParameter("limit", realLimit.ToString());
}

if (withCounts.TryGet(out var realWithCounts))
{
b.AddQueryParameter("with_counts", realWithCounts.ToString());
}

b.WithRateLimitContext(this.RateLimitCache);
},
ct: ct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public async Task PerformsRequestCorrectly()
var before = DiscordSnowflake.New(0);
var after = DiscordSnowflake.New(1);
var limit = 10;
var withCounts = true;

var api = CreateAPI
(
Expand All @@ -250,13 +251,14 @@ public async Task PerformsRequestCorrectly()
{
new KeyValuePair<string, string>("before", before.ToString()),
new KeyValuePair<string, string>("after", after.ToString()),
new KeyValuePair<string, string>("limit", limit.ToString())
new KeyValuePair<string, string>("limit", limit.ToString()),
new KeyValuePair<string, string>("with_counts", withCounts.ToString())
}
)
.Respond("application/json", "[]")
);

var result = await api.GetCurrentUserGuildsAsync(before, after, limit);
var result = await api.GetCurrentUserGuildsAsync(before, after, limit, withCounts);
ResultAssert.Successful(result);
}

Expand Down

0 comments on commit 2d50e88

Please sign in to comment.