diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index a295cfc97..42bb86214 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -714,7 +714,7 @@ namespace Discord if (server != null) { var role = server.AddRole(data.Data.Id); - role.Update(data.Data); + role.Update(data.Data, false); Logger.Debug($"GUILD_ROLE_CREATE: {role.Path}"); OnRoleCreated(role); } @@ -732,7 +732,7 @@ namespace Discord if (role != null) { var before = Config.EnablePreUpdateEvents ? role.Clone() : null; - role.Update(data.Data); + role.Update(data.Data, true); Logger.Debug($"GUILD_ROLE_UPDATE: {role.Path}"); OnRoleUpdated(before, role); } diff --git a/src/Discord.Net/Models/Channel.cs b/src/Discord.Net/Models/Channel.cs index a461035e5..ddf85dd0b 100644 --- a/src/Discord.Net/Models/Channel.cs +++ b/src/Discord.Net/Models/Channel.cs @@ -141,18 +141,13 @@ namespace Discord if (client.Config.MessageCacheSize > 0) _messages = new ConcurrentDictionary(2, (int)(client.Config.MessageCacheSize * 1.05)); } - - internal void Update(ChannelReference model) + + internal void Update(APIChannel model) { if (!IsPrivate && model.Name != null) Name = model.Name; if (model.Type != null) Type = model.Type; - } - internal void Update(APIChannel model) - { - Update(model as ChannelReference); - if (model.Position != null) Position = model.Position.Value; if (model.Topic != null) diff --git a/src/Discord.Net/Models/Role.cs b/src/Discord.Net/Models/Role.cs index 4fd5c4b7a..d3e9f9094 100644 --- a/src/Discord.Net/Models/Role.cs +++ b/src/Discord.Net/Models/Role.cs @@ -52,9 +52,9 @@ namespace Discord 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; if (model.Hoist != null) IsHoisted = model.Hoist.Value; @@ -64,11 +64,15 @@ namespace Discord Position = model.Position.Value; if (model.Color != null) Color = new Color(model.Color.Value); - if (model.Permissions != null) - Permissions = new ServerPermissions(model.Permissions.Value); - - foreach (var member in Members) - Server.UpdatePermissions(member); + if (model.Permissions != null) + { + Permissions = new ServerPermissions(model.Permissions.Value); + if (updatePermissions) //Dont update these during READY + { + foreach (var member in Members) + Server.UpdatePermissions(member); + } + } } public async Task Edit(string name = null, ServerPermissions? permissions = null, Color color = null, bool? isHoisted = null, int? position = null) diff --git a/src/Discord.Net/Models/Server.cs b/src/Discord.Net/Models/Server.cs index 5123d9bbc..2c0e9f288 100644 --- a/src/Discord.Net/Models/Server.cs +++ b/src/Discord.Net/Models/Server.cs @@ -57,10 +57,6 @@ namespace Discord /// Gets the unique identifier for this server. public ulong Id { get; } - /// Gets the default channel for this server. - public Channel DefaultChannel { get; } - /// Gets the the role representing all users in a server. - public Role EveryoneRole { get; } /// Gets the name of this server. public string Name { get; private set; } @@ -74,6 +70,10 @@ namespace Discord public int AFKTimeout { get; private set; } /// Gets the date and time you joined this server. public DateTime JoinedAt { get; private set; } + /// Gets the default channel for this server. + public Channel DefaultChannel { get; private set; } + /// Gets the the role representing all users in a server. + public Role EveryoneRole { get; private set; } /// Gets all extra features added to this server. public IEnumerable Features { get; private set; } /// Gets all custom emojis on this server. @@ -116,20 +116,12 @@ namespace Discord { Client = client; Id = id; - - DefaultChannel = AddChannel(id); - EveryoneRole = AddRole(id); } - internal void Update(GuildReference model) + internal void Update(Guild model) { if (model.Name != null) Name = model.Name; - } - internal void Update(Guild model) - { - Update(model as GuildReference); - if (model.AFKTimeout != null) AFKTimeout = model.AFKTimeout.Value; if (model.JoinedAt != null) @@ -142,7 +134,17 @@ namespace Discord IconId = model.Icon; if (model.Features != null) Features = model.Features; - if (model.Emojis != null) + if (model.Roles != null) + { + _roles = new ConcurrentDictionary(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) { @@ -152,12 +154,6 @@ namespace Discord Roles = x.RoleIds.Select(y => GetRole(y)).Where(y => y != null).ToArray() }).ToArray(); } - if (model.Roles != null) - { - _roles = new ConcurrentDictionary(2, model.Roles.Length); - foreach (var x in model.Roles) - AddRole(x.Id).Update(x); - } //Can be null _afkChannelId = model.AFKChannelId; @@ -165,14 +161,15 @@ namespace Discord } internal void Update(ExtendedGuild model) { - Update(model as Guild); - if (model.Channels != null) { _channels = new ConcurrentDictionary(2, (int)(model.Channels.Length * 1.05)); foreach (var subModel in model.Channels) AddChannel(subModel.Id).Update(subModel); + DefaultChannel = _channels[Id]; } + Update(model as Guild); //Needs channels + if (model.Members != null) { _users = new ConcurrentDictionary(2, (int)(model.Members.Length * 1.05)); @@ -368,7 +365,7 @@ namespace Discord var createRequest = new CreateRoleRequest(Id); var createResponse = await Client.ClientAPI.Send(createRequest).ConfigureAwait(false); var role = AddRole(createResponse.Id); - role.Update(createResponse); + role.Update(createResponse, false); var editRequest = new UpdateRoleRequest(role.Server.Id, role.Id) { @@ -378,7 +375,7 @@ namespace Discord IsHoisted = isHoisted }; var editResponse = await Client.ClientAPI.Send(editRequest).ConfigureAwait(false); - role.Update(editResponse); + role.Update(editResponse, true); return role; }