Added support for changing nicknames

This commit is contained in:
RogueException
2016-05-12 23:43:34 -03:00
parent 14bb0f7e2e
commit 93bf06bcb6
4 changed files with 41 additions and 9 deletions

View File

@@ -738,6 +738,13 @@ namespace Discord.API
return await Send<User>("PATCH", "users/@me", args).ConfigureAwait(false);
}
public async Task ModifyCurrentUserNick(ulong guildId, ModifyCurrentUserNickParams args)
{
if (args == null) throw new ArgumentNullException(nameof(args));
if (args.Nickname == "") throw new ArgumentOutOfRangeException(nameof(args.Nickname));
await Send("PATCH", $"guilds/{guildId}/members/@me/nick", args).ConfigureAwait(false);
}
public async Task<Channel> CreateDMChannel(CreateDMChannelParams args)
{
if (args == null) throw new ArgumentNullException(nameof(args));

View File

@@ -0,0 +1,10 @@
using Newtonsoft.Json;
namespace Discord.API.Rest
{
public class ModifyCurrentUserNickParams
{
[JsonProperty("nick")]
public string Nickname { get; set; }
}
}

View File

@@ -70,6 +70,7 @@
<Compile Include="API\Optional.cs" />
<Compile Include="API\Rest\DeleteMessagesParam.cs" />
<Compile Include="API\Rest\GetGuildMembersParams.cs" />
<Compile Include="API\Rest\ModifyCurrentUserNickParams.cs" />
<Compile Include="API\Rest\UploadFileParams.cs" />
<Compile Include="API\Rest\GuildPruneParams.cs" />
<Compile Include="API\Rest\CreateChannelInviteParams.cs" />

View File

@@ -83,15 +83,29 @@ namespace Discord.Rest
var args = new ModifyGuildMemberParams();
func(args);
await Discord.BaseClient.ModifyGuildMember(Guild.Id, Id, args).ConfigureAwait(false);
if (args.Deaf.IsSpecified)
IsDeaf = args.Deaf;
if (args.Mute.IsSpecified)
IsMute = args.Mute;
if (args.Nickname.IsSpecified)
Nickname = args.Nickname;
if (args.Roles.IsSpecified)
_roles = args.Roles.Value.Select(x => Guild.GetRole(x)).Where(x => x != null).ToImmutableArray();
bool isCurrentUser = IsCurrentUser;
if (isCurrentUser && args.Nickname.IsSpecified)
{
var nickArgs = new ModifyCurrentUserNickParams
{
Nickname = args.Nickname.Value
};
await Discord.BaseClient.ModifyCurrentUserNick(Guild.Id, nickArgs).ConfigureAwait(false);
}
if (!isCurrentUser || args.Deaf.IsSpecified || args.Mute.IsSpecified || args.Roles.IsSpecified)
{
await Discord.BaseClient.ModifyGuildMember(Guild.Id, Id, args).ConfigureAwait(false);
if (args.Deaf.IsSpecified)
IsDeaf = args.Deaf;
if (args.Mute.IsSpecified)
IsMute = args.Mute;
if (args.Nickname.IsSpecified)
Nickname = args.Nickname;
if (args.Roles.IsSpecified)
_roles = args.Roles.Value.Select(x => Guild.GetRole(x)).Where(x => x != null).ToImmutableArray();
}
}