| @@ -69,6 +69,10 @@ namespace Discord.API | |||||
| public string Region; | public string Region; | ||||
| [JsonProperty("icon", NullValueHandling = NullValueHandling.Ignore)] | [JsonProperty("icon", NullValueHandling = NullValueHandling.Ignore)] | ||||
| public string Icon; | public string Icon; | ||||
| [JsonProperty("afk_channel_id", NullValueHandling = NullValueHandling.Ignore)] | |||||
| public string AFKChannelId; | |||||
| [JsonProperty("afk_timeout", NullValueHandling = NullValueHandling.Ignore)] | |||||
| public int AFKTimeout; | |||||
| } | } | ||||
| public sealed class EditServerResponse : GuildInfo { } | public sealed class EditServerResponse : GuildInfo { } | ||||
| @@ -9,7 +9,7 @@ namespace Discord.Collections | |||||
| internal Roles(DiscordClient client, object writerLock) | internal Roles(DiscordClient client, object writerLock) | ||||
| : base(client, writerLock) { } | : base(client, writerLock) { } | ||||
| internal Role GetOrAdd(string id, string serverId, bool isEveryone) => GetOrAdd(id, () => new Role(_client, id, serverId, isEveryone)); | |||||
| internal Role GetOrAdd(string id, string serverId) => GetOrAdd(id, () => new Role(_client, id, serverId)); | |||||
| internal new Role TryRemove(string id) => base.TryRemove(id); | internal new Role TryRemove(string id) => base.TryRemove(id); | ||||
| protected override void OnCreated(Role item) | protected override void OnCreated(Role item) | ||||
| @@ -632,7 +632,7 @@ namespace Discord | |||||
| if (serverId == null) throw new NullReferenceException(nameof(serverId)); | if (serverId == null) throw new NullReferenceException(nameof(serverId)); | ||||
| var response = await _api.CreateRole(serverId).ConfigureAwait(false); | var response = await _api.CreateRole(serverId).ConfigureAwait(false); | ||||
| var role = _roles.GetOrAdd(response.Id, serverId, false); | |||||
| var role = _roles.GetOrAdd(response.Id, serverId); | |||||
| role.Update(response); | role.Update(response); | ||||
| await EditRole(role, name: name); | await EditRole(role, name: name); | ||||
| @@ -508,7 +508,7 @@ namespace Discord | |||||
| case "GUILD_ROLE_CREATE": | case "GUILD_ROLE_CREATE": | ||||
| { | { | ||||
| var data = e.Payload.ToObject<RoleCreateEvent>(_serializer); | var data = e.Payload.ToObject<RoleCreateEvent>(_serializer); | ||||
| var role = _roles.GetOrAdd(data.Data.Id, data.GuildId, false); | |||||
| var role = _roles.GetOrAdd(data.Data.Id, data.GuildId); | |||||
| role.Update(data.Data); | role.Update(data.Data); | ||||
| var server = _servers[data.GuildId]; | var server = _servers[data.GuildId]; | ||||
| if (server != null) | if (server != null) | ||||
| @@ -32,7 +32,7 @@ namespace Discord | |||||
| public Server Server => _client.Servers[ServerId]; | public Server Server => _client.Servers[ServerId]; | ||||
| /// <summary> Returns true if this is the role representing all users in a server. </summary> | /// <summary> Returns true if this is the role representing all users in a server. </summary> | ||||
| public bool IsEveryone { get; } | |||||
| public bool IsEveryone => Id == ServerId; | |||||
| /// <summary> Returns a list of the ids of all members in this role. </summary> | /// <summary> Returns a list of the ids of all members in this role. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public IEnumerable<string> MemberIds => IsEveryone ? Server.UserIds : Server.Members.Where(x => x.RoleIds.Contains(Id)).Select(x => x.UserId); | public IEnumerable<string> MemberIds => IsEveryone ? Server.UserIds : Server.Members.Where(x => x.RoleIds.Contains(Id)).Select(x => x.UserId); | ||||
| @@ -40,18 +40,17 @@ namespace Discord | |||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public IEnumerable<Member> Members => IsEveryone ? Server.Members : Server.Members.Where(x => x.RoleIds.Contains(Id)); | public IEnumerable<Member> Members => IsEveryone ? Server.Members : Server.Members.Where(x => x.RoleIds.Contains(Id)); | ||||
| internal Role(DiscordClient client, string id, string serverId, bool isEveryone) | |||||
| internal Role(DiscordClient client, string id, string serverId) | |||||
| { | { | ||||
| _client = client; | _client = client; | ||||
| Id = id; | Id = id; | ||||
| ServerId = serverId; | ServerId = serverId; | ||||
| IsEveryone = isEveryone; | |||||
| Permissions = new PackedServerPermissions(0); | Permissions = new PackedServerPermissions(0); | ||||
| Permissions.Lock(); | Permissions.Lock(); | ||||
| Color = new PackedColor(0); | Color = new PackedColor(0); | ||||
| Color.Lock(); | Color.Lock(); | ||||
| if (isEveryone) | |||||
| if (IsEveryone) | |||||
| Position = int.MinValue; | Position = int.MinValue; | ||||
| } | } | ||||
| @@ -83,7 +83,7 @@ namespace Discord | |||||
| public IEnumerable<User> Users => _members.Select(x => _client.Users[x.Key]); | public IEnumerable<User> Users => _members.Select(x => _client.Users[x.Key]); | ||||
| /// <summary> Return the id of the role representing all users in a server. </summary> | /// <summary> Return the id of the role representing all users in a server. </summary> | ||||
| public string EveryoneRoleId { get; private set; } | |||||
| public string EveryoneRoleId => Id; | |||||
| /// <summary> Return the the role representing all users in a server. </summary> | /// <summary> Return the the role representing all users in a server. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public Role EveryoneRole => _client.Roles[EveryoneRoleId]; | public Role EveryoneRole => _client.Roles[EveryoneRoleId]; | ||||
| @@ -116,14 +116,10 @@ namespace Discord | |||||
| Region = model.Region; | Region = model.Region; | ||||
| var roles = _client.Roles; | var roles = _client.Roles; | ||||
| bool isEveryone = true; //Assumes first role is always everyone | |||||
| foreach (var subModel in model.Roles) | foreach (var subModel in model.Roles) | ||||
| { | { | ||||
| var role = roles.GetOrAdd(subModel.Id, Id, isEveryone); | |||||
| var role = roles.GetOrAdd(subModel.Id, Id); | |||||
| role.Update(subModel); | role.Update(subModel); | ||||
| if (isEveryone) | |||||
| EveryoneRoleId = subModel.Id; | |||||
| isEveryone = false; | |||||
| } | } | ||||
| } | } | ||||
| internal void Update(ExtendedGuildInfo model) | internal void Update(ExtendedGuildInfo model) | ||||