Browse Source

Several GuildUser fixes

tags/1.0-rc
RogueException 9 years ago
parent
commit
b15853dc8b
2 changed files with 26 additions and 16 deletions
  1. +5
    -5
      src/Discord.Net/API/Common/GuildMember.cs
  2. +21
    -11
      src/Discord.Net/Entities/Users/GuildUser.cs

+ 5
- 5
src/Discord.Net/API/Common/GuildMember.cs 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; }
} }
} }

+ 21
- 11
src/Discord.Net/Entities/Users/GuildUser.cs 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,20 +47,25 @@ 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;
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) public void Update(VoiceStateModel model, UpdateSource source)
{ {
@@ -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));


Loading…
Cancel
Save