Several GuildUser fixes

This commit is contained in:
RogueException
2016-06-11 19:55:38 -03:00
parent 5278d798fa
commit b15853dc8b
2 changed files with 26 additions and 16 deletions

View File

@@ -8,14 +8,14 @@ namespace Discord.API
[JsonProperty("user")]
public User User { get; set; }
[JsonProperty("nick")]
public string Nick { get; set; }
public Optional<string> Nick { get; set; }
[JsonProperty("roles")]
public ulong[] Roles { get; set; }
public Optional<ulong[]> Roles { get; set; }
[JsonProperty("joined_at")]
public DateTime?JoinedAt { get; set; }
public Optional<DateTime> JoinedAt { get; set; }
[JsonProperty("deaf")]
public bool? Deaf { get; set; }
public Optional<bool> Deaf { get; set; }
[JsonProperty("mute")]
public bool? Mute { get; set; }
public Optional<bool> Mute { get; set; }
}
}

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Model = Discord.API.GuildMember;
@@ -9,6 +10,7 @@ using VoiceStateModel = Discord.API.VoiceState;
namespace Discord
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
internal class GuildUser : IGuildUser, ISnowflakeEntity
{
public bool IsDeaf { get; private set; }
@@ -45,20 +47,25 @@ namespace Discord
{
if (source == UpdateSource.Rest && IsAttached) return;
if (model.Deaf.HasValue)
if (model.Deaf.IsSpecified)
IsDeaf = model.Deaf.Value;
if (model.Mute.HasValue)
if (model.Mute.IsSpecified)
IsMute = model.Mute.Value;
JoinedAt = model.JoinedAt.Value;
Nickname = model.Nick;
if (model.JoinedAt.IsSpecified)
JoinedAt = model.JoinedAt.Value;
if (model.Nick.IsSpecified)
Nickname = model.Nick.Value;
var roles = ImmutableArray.CreateBuilder<Role>(model.Roles.Length + 1);
roles.Add(Guild.EveryoneRole);
for (int i = 0; i < model.Roles.Length; i++)
roles.Add(Guild.GetRole(model.Roles[i]));
Roles = roles.ToImmutable();
GuildPermissions = new GuildPermissions(Permissions.ResolveGuild(this));
if (model.Roles.IsSpecified)
{
var value = model.Roles.Value;
var roles = ImmutableArray.CreateBuilder<Role>(value.Length + 1);
roles.Add(Guild.EveryoneRole);
for (int i = 0; i < value.Length; i++)
roles.Add(Guild.GetRole(value[i]));
Roles = roles.ToImmutable();
GuildPermissions = new GuildPermissions(Permissions.ResolveGuild(this));
}
}
public void Update(VoiceStateModel model, UpdateSource source)
{
@@ -108,6 +115,9 @@ namespace Discord
await Discord.ApiClient.RemoveGuildMemberAsync(Guild.Id, Id).ConfigureAwait(false);
}
public override string ToString() => $"{Username}#{Discriminator}";
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id})";
public ChannelPermissions GetPermissions(IGuildChannel channel)
{
if (channel == null) throw new ArgumentNullException(nameof(channel));