Fixed Server.AFKChannel

This commit is contained in:
RogueException
2015-10-25 05:28:03 -03:00
parent b8e201d652
commit 22a4865971

View File

@@ -29,11 +29,12 @@ namespace Discord
[JsonIgnore] [JsonIgnore]
public User Owner { get; private set; } public User Owner { get; private set; }
private string _ownerId; private string _ownerId;
/// <summary> Returns the AFK voice channel for this server (see AFKTimeout). </summary> /// <summary> Returns the AFK voice channel for this server (see AFKTimeout). </summary>
[JsonIgnore] [JsonIgnore]
public Channel AFKChannel { get; private set; } public Channel AFKChannel => _afkChannel.Value;
private Reference<Channel> _afkChannel;
/// <summary> Returns the default channel for this server. </summary> /// <summary> Returns the default channel for this server. </summary>
[JsonIgnore] [JsonIgnore]
public Channel DefaultChannel { get; private set; } public Channel DefaultChannel { get; private set; }
@@ -75,6 +76,8 @@ namespace Discord
internal Server(DiscordClient client, string id) internal Server(DiscordClient client, string id)
: base(client, id) : base(client, id)
{ {
_afkChannel = new Reference<Channel>(x => _client.Channels[x]);
//Global Cache //Global Cache
_channels = new ConcurrentDictionary<string, Channel>(); _channels = new ConcurrentDictionary<string, Channel>();
_members = new ConcurrentDictionary<string, User>(); _members = new ConcurrentDictionary<string, User>();
@@ -83,8 +86,11 @@ namespace Discord
//Local Cache //Local Cache
_bans = new ConcurrentDictionary<string, bool>(); _bans = new ConcurrentDictionary<string, bool>();
_invites = new ConcurrentDictionary<string, Invite>(); _invites = new ConcurrentDictionary<string, Invite>();
} }
internal override void LoadReferences() { } internal override void LoadReferences()
{
_afkChannel.Load();
}
internal override void UnloadReferences() internal override void UnloadReferences()
{ {
//Global Cache //Global Cache
@@ -113,15 +119,15 @@ namespace Discord
invites.Clear(); invites.Clear();
_bans.Clear(); _bans.Clear();
}
_afkChannel.Unload();
}
internal void Update(GuildInfo model) internal void Update(GuildInfo model)
{ {
//Can be null
AFKChannel = _client.Channels[model.AFKChannelId];
if (model.AFKTimeout != null) if (model.AFKTimeout != null)
AFKTimeout = model.AFKTimeout.Value; AFKTimeout = model.AFKTimeout.Value;
if (model.AFKChannelId != null)
if (model.JoinedAt != null) if (model.JoinedAt != null)
JoinedAt = model.JoinedAt.Value; JoinedAt = model.JoinedAt.Value;
if (model.Name != null) if (model.Name != null)
@@ -143,6 +149,8 @@ namespace Discord
role.Update(x); role.Update(x);
} }
} }
_afkChannel.Id = model.AFKChannelId; //Can be null
} }
internal void Update(ExtendedGuildInfo model) internal void Update(ExtendedGuildInfo model)
{ {