From e601cea2555a0aa4e41ddcc73e8f7ac4dab39b8e Mon Sep 17 00:00:00 2001 From: Christopher F Date: Wed, 15 Feb 2017 15:59:23 -0500 Subject: [PATCH 1/2] Add Roles property to SocketGuildUser there's a few different ways to select a user's roles from their role IDs, and this one seems to be the most efficient. doesn't seem like there's any reason this shouldn't be included. --- src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs index 3d827bca5..55c676901 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; +using System.Linq; using System.Threading.Tasks; using Model = Discord.API.GuildMember; using PresenceModel = Discord.API.Presence; @@ -32,6 +33,7 @@ namespace Discord.WebSocket public bool IsDeafened => VoiceState?.IsDeafened ?? false; public bool IsMuted => VoiceState?.IsMuted ?? false; public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks); + public IEnumerable Roles => _roleIds.Select(id => Guild.GetRole(id)); public IReadOnlyCollection RoleIds => _roleIds; public SocketVoiceChannel VoiceChannel => VoiceState?.VoiceChannel; public string VoiceSessionId => VoiceState?.VoiceSessionId ?? ""; From bb9f144eae13794463af2cabff4f4554aee2b826 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Tue, 21 Feb 2017 16:19:33 -0500 Subject: [PATCH 2/2] Remove implicit SocketGuildUser.RoleIds; refactor Roles to ReadOnly --- src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs index 55c676901..5162839d7 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs @@ -33,8 +33,7 @@ namespace Discord.WebSocket public bool IsDeafened => VoiceState?.IsDeafened ?? false; public bool IsMuted => VoiceState?.IsMuted ?? false; public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks); - public IEnumerable Roles => _roleIds.Select(id => Guild.GetRole(id)); - public IReadOnlyCollection RoleIds => _roleIds; + public IEnumerable Roles => _roleIds.Select(id => Guild.GetRole(id)).ToReadOnlyCollection(() => _roleIds.Count()); public SocketVoiceChannel VoiceChannel => VoiceState?.VoiceChannel; public string VoiceSessionId => VoiceState?.VoiceSessionId ?? ""; public SocketVoiceState? VoiceState => Guild.GetVoiceState(Id); @@ -117,7 +116,7 @@ namespace Discord.WebSocket //IGuildUser IGuild IGuildUser.Guild => Guild; ulong IGuildUser.GuildId => Guild.Id; - IReadOnlyCollection IGuildUser.RoleIds => RoleIds; + IReadOnlyCollection IGuildUser.RoleIds => _roleIds; //IUser Task IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options)