Fixed a login crash bug, fixed permissions resolving twice during READY

This commit is contained in:
RogueException
2016-02-15 20:35:18 -04:00
parent 19e2528aff
commit d68e699556
4 changed files with 36 additions and 40 deletions

View File

@@ -714,7 +714,7 @@ namespace Discord
if (server != null) if (server != null)
{ {
var role = server.AddRole(data.Data.Id); var role = server.AddRole(data.Data.Id);
role.Update(data.Data); role.Update(data.Data, false);
Logger.Debug($"GUILD_ROLE_CREATE: {role.Path}"); Logger.Debug($"GUILD_ROLE_CREATE: {role.Path}");
OnRoleCreated(role); OnRoleCreated(role);
} }
@@ -732,7 +732,7 @@ namespace Discord
if (role != null) if (role != null)
{ {
var before = Config.EnablePreUpdateEvents ? role.Clone() : null; var before = Config.EnablePreUpdateEvents ? role.Clone() : null;
role.Update(data.Data); role.Update(data.Data, true);
Logger.Debug($"GUILD_ROLE_UPDATE: {role.Path}"); Logger.Debug($"GUILD_ROLE_UPDATE: {role.Path}");
OnRoleUpdated(before, role); OnRoleUpdated(before, role);
} }

View File

@@ -142,17 +142,12 @@ namespace Discord
_messages = new ConcurrentDictionary<ulong, Message>(2, (int)(client.Config.MessageCacheSize * 1.05)); _messages = new ConcurrentDictionary<ulong, Message>(2, (int)(client.Config.MessageCacheSize * 1.05));
} }
internal void Update(ChannelReference model) internal void Update(APIChannel model)
{ {
if (!IsPrivate && model.Name != null) if (!IsPrivate && model.Name != null)
Name = model.Name; Name = model.Name;
if (model.Type != null) if (model.Type != null)
Type = model.Type; Type = model.Type;
}
internal void Update(APIChannel model)
{
Update(model as ChannelReference);
if (model.Position != null) if (model.Position != null)
Position = model.Position.Value; Position = model.Position.Value;
if (model.Topic != null) if (model.Topic != null)

View File

@@ -52,7 +52,7 @@ namespace Discord
Color = new Color(0); Color = new Color(0);
} }
internal void Update(APIRole model) internal void Update(APIRole model, bool updatePermissions)
{ {
if (model.Name != null) if (model.Name != null)
Name = model.Name; Name = model.Name;
@@ -65,11 +65,15 @@ namespace Discord
if (model.Color != null) if (model.Color != null)
Color = new Color(model.Color.Value); Color = new Color(model.Color.Value);
if (model.Permissions != null) if (model.Permissions != null)
{
Permissions = new ServerPermissions(model.Permissions.Value); Permissions = new ServerPermissions(model.Permissions.Value);
if (updatePermissions) //Dont update these during READY
{
foreach (var member in Members) foreach (var member in Members)
Server.UpdatePermissions(member); Server.UpdatePermissions(member);
} }
}
}
public async Task Edit(string name = null, ServerPermissions? permissions = null, Color color = null, bool? isHoisted = null, int? position = null) public async Task Edit(string name = null, ServerPermissions? permissions = null, Color color = null, bool? isHoisted = null, int? position = null)
{ {

View File

@@ -57,10 +57,6 @@ namespace Discord
/// <summary> Gets the unique identifier for this server. </summary> /// <summary> Gets the unique identifier for this server. </summary>
public ulong Id { get; } public ulong Id { get; }
/// <summary> Gets the default channel for this server. </summary>
public Channel DefaultChannel { get; }
/// <summary> Gets the the role representing all users in a server. </summary>
public Role EveryoneRole { get; }
/// <summary> Gets the name of this server. </summary> /// <summary> Gets the name of this server. </summary>
public string Name { get; private set; } public string Name { get; private set; }
@@ -74,6 +70,10 @@ namespace Discord
public int AFKTimeout { get; private set; } public int AFKTimeout { get; private set; }
/// <summary> Gets the date and time you joined this server. </summary> /// <summary> Gets the date and time you joined this server. </summary>
public DateTime JoinedAt { get; private set; } public DateTime JoinedAt { get; private set; }
/// <summary> Gets the default channel for this server. </summary>
public Channel DefaultChannel { get; private set; }
/// <summary> Gets the the role representing all users in a server. </summary>
public Role EveryoneRole { get; private set; }
/// <summary> Gets all extra features added to this server. </summary> /// <summary> Gets all extra features added to this server. </summary>
public IEnumerable<string> Features { get; private set; } public IEnumerable<string> Features { get; private set; }
/// <summary> Gets all custom emojis on this server. </summary> /// <summary> Gets all custom emojis on this server. </summary>
@@ -116,20 +116,12 @@ namespace Discord
{ {
Client = client; Client = client;
Id = id; Id = id;
DefaultChannel = AddChannel(id);
EveryoneRole = AddRole(id);
} }
internal void Update(GuildReference model) internal void Update(Guild model)
{ {
if (model.Name != null) if (model.Name != null)
Name = model.Name; Name = model.Name;
}
internal void Update(Guild model)
{
Update(model as GuildReference);
if (model.AFKTimeout != null) if (model.AFKTimeout != null)
AFKTimeout = model.AFKTimeout.Value; AFKTimeout = model.AFKTimeout.Value;
if (model.JoinedAt != null) if (model.JoinedAt != null)
@@ -142,7 +134,17 @@ namespace Discord
IconId = model.Icon; IconId = model.Icon;
if (model.Features != null) if (model.Features != null)
Features = model.Features; Features = model.Features;
if (model.Emojis != null) if (model.Roles != null)
{
_roles = new ConcurrentDictionary<ulong, Role>(2, model.Roles.Length);
foreach (var x in model.Roles)
{
var role = AddRole(x.Id);
role.Update(x, false);
}
EveryoneRole = _roles[Id];
}
if (model.Emojis != null) //Needs Roles
{ {
CustomEmojis = model.Emojis.Select(x => new Emoji(x.Id) CustomEmojis = model.Emojis.Select(x => new Emoji(x.Id)
{ {
@@ -152,12 +154,6 @@ namespace Discord
Roles = x.RoleIds.Select(y => GetRole(y)).Where(y => y != null).ToArray() Roles = x.RoleIds.Select(y => GetRole(y)).Where(y => y != null).ToArray()
}).ToArray(); }).ToArray();
} }
if (model.Roles != null)
{
_roles = new ConcurrentDictionary<ulong, Role>(2, model.Roles.Length);
foreach (var x in model.Roles)
AddRole(x.Id).Update(x);
}
//Can be null //Can be null
_afkChannelId = model.AFKChannelId; _afkChannelId = model.AFKChannelId;
@@ -165,14 +161,15 @@ namespace Discord
} }
internal void Update(ExtendedGuild model) internal void Update(ExtendedGuild model)
{ {
Update(model as Guild);
if (model.Channels != null) if (model.Channels != null)
{ {
_channels = new ConcurrentDictionary<ulong, Channel>(2, (int)(model.Channels.Length * 1.05)); _channels = new ConcurrentDictionary<ulong, Channel>(2, (int)(model.Channels.Length * 1.05));
foreach (var subModel in model.Channels) foreach (var subModel in model.Channels)
AddChannel(subModel.Id).Update(subModel); AddChannel(subModel.Id).Update(subModel);
DefaultChannel = _channels[Id];
} }
Update(model as Guild); //Needs channels
if (model.Members != null) if (model.Members != null)
{ {
_users = new ConcurrentDictionary<ulong, Member>(2, (int)(model.Members.Length * 1.05)); _users = new ConcurrentDictionary<ulong, Member>(2, (int)(model.Members.Length * 1.05));
@@ -368,7 +365,7 @@ namespace Discord
var createRequest = new CreateRoleRequest(Id); var createRequest = new CreateRoleRequest(Id);
var createResponse = await Client.ClientAPI.Send(createRequest).ConfigureAwait(false); var createResponse = await Client.ClientAPI.Send(createRequest).ConfigureAwait(false);
var role = AddRole(createResponse.Id); var role = AddRole(createResponse.Id);
role.Update(createResponse); role.Update(createResponse, false);
var editRequest = new UpdateRoleRequest(role.Server.Id, role.Id) var editRequest = new UpdateRoleRequest(role.Server.Id, role.Id)
{ {
@@ -378,7 +375,7 @@ namespace Discord
IsHoisted = isHoisted IsHoisted = isHoisted
}; };
var editResponse = await Client.ClientAPI.Send(editRequest).ConfigureAwait(false); var editResponse = await Client.ClientAPI.Send(editRequest).ConfigureAwait(false);
role.Update(editResponse); role.Update(editResponse, true);
return role; return role;
} }