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")] [JsonProperty("user")]
public User User { get; set; } public User User { get; set; }
[JsonProperty("nick")] [JsonProperty("nick")]
public string Nick { get; set; } public Optional<string> Nick { get; set; }
[JsonProperty("roles")] [JsonProperty("roles")]
public ulong[] Roles { get; set; } public Optional<ulong[]> Roles { get; set; }
[JsonProperty("joined_at")] [JsonProperty("joined_at")]
public DateTime?JoinedAt { get; set; } public Optional<DateTime> JoinedAt { get; set; }
[JsonProperty("deaf")] [JsonProperty("deaf")]
public bool? Deaf { get; set; } public Optional<bool> Deaf { get; set; }
[JsonProperty("mute")] [JsonProperty("mute")]
public bool? Mute { get; set; } public Optional<bool> Mute { get; set; }
} }
} }

View File

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