[Feature] Expose GetCurrentUser method & missing current user API methods (#2574)
* add stuff * forgot to push * docs * Update DiscordRestClient.cs * Apply suggestions from code review * Update toc.yml --------- Co-authored-by: Casmir <68127614+csmir@users.noreply.github.com>
This commit is contained in:
@@ -18,5 +18,13 @@ namespace Discord
|
||||
/// Returns the current user's permissions for this guild.
|
||||
/// </summary>
|
||||
GuildPermissions Permissions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the features for this guild.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A flags enum containing all the features for the guild.
|
||||
/// </returns>
|
||||
GuildFeatures Features { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,5 +14,7 @@ namespace Discord.API
|
||||
public bool Owner { get; set; }
|
||||
[JsonProperty("permissions"), Int53]
|
||||
public string Permissions { get; set; }
|
||||
[JsonProperty("features")]
|
||||
public GuildFeatures Features { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
using Discord.API.Rest;
|
||||
using Discord.Net;
|
||||
using Discord.Net.Converters;
|
||||
@@ -2204,6 +2203,14 @@ namespace Discord.API
|
||||
|
||||
return await SendJsonAsync<Channel>("POST", () => "users/@me/channels", args, new BucketIds(), options: options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<GuildMember> GetCurrentUserGuildMember(ulong guildId, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
|
||||
var ids = new BucketIds();
|
||||
return await SendAsync<GuildMember>("GET", () => $"users/@me/guilds/{guildId}/member", ids, options: options).ConfigureAwait(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Voice Regions
|
||||
|
||||
@@ -152,6 +152,19 @@ namespace Discord.Rest
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task<RestSelfUser> GetCurrentUserAsync(RequestOptions options = null)
|
||||
{
|
||||
var user = await ApiClient.GetMyUserAsync(options);
|
||||
CurrentUser.Update(user);
|
||||
return CurrentUser;
|
||||
}
|
||||
|
||||
public async Task<RestGuildUser> GetCurrentUserGuildMemberAsync(ulong guildId, RequestOptions options = null)
|
||||
{
|
||||
var user = await ApiClient.GetCurrentUserGuildMember(guildId, options);
|
||||
return RestGuildUser.Create(this, null, user, guildId);
|
||||
}
|
||||
|
||||
public async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null)
|
||||
{
|
||||
return _applicationInfo ??= await ClientHelper.GetApplicationInfoAsync(this, options).ConfigureAwait(false);
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace Discord.Rest
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
/// <inheritdoc />
|
||||
public string IconUrl => CDN.GetGuildIconUrl(Id, _iconId);
|
||||
/// <inheritdoc />
|
||||
public GuildFeatures Features { get; private set; }
|
||||
|
||||
internal RestUserGuild(BaseDiscordClient discord, ulong id)
|
||||
: base(discord, id)
|
||||
@@ -39,12 +41,20 @@ namespace Discord.Rest
|
||||
IsOwner = model.Owner;
|
||||
Name = model.Name;
|
||||
Permissions = new GuildPermissions(model.Permissions);
|
||||
Features = model.Features;
|
||||
}
|
||||
|
||||
public async Task LeaveAsync(RequestOptions options = null)
|
||||
{
|
||||
await Discord.ApiClient.LeaveGuildAsync(Id, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<RestGuildUser> GetCurrentUserGuildMemberAsync(RequestOptions options = null)
|
||||
{
|
||||
var user = await Discord.ApiClient.GetCurrentUserGuildMember(Id, options);
|
||||
return RestGuildUser.Create(Discord, null, user, Id);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task DeleteAsync(RequestOptions options = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user