| @@ -12,7 +12,7 @@ namespace Discord.Commands | |||||
| public int? Permissions { get; } | public int? Permissions { get; } | ||||
| public string[] Args { get; } | public string[] Args { get; } | ||||
| public User Member => Message.Member; | |||||
| public User Member => Message.User; | |||||
| public Channel Channel => Message.Channel; | public Channel Channel => Message.Channel; | ||||
| public Server Server => Message.Channel.Server; | public Server Server => Message.Channel.Server; | ||||
| @@ -96,7 +96,7 @@ namespace Discord.Commands | |||||
| argText = msg.Substring(args[cmd.Parts.Length].Index); | argText = msg.Substring(args[cmd.Parts.Length].Index); | ||||
| //Check Permissions | //Check Permissions | ||||
| int permissions = _getPermissions != null ? _getPermissions(e.Message.Member) : 0; | |||||
| int permissions = _getPermissions != null ? _getPermissions(e.Message.User) : 0; | |||||
| var eventArgs = new CommandEventArgs(e.Message, cmd, msg, argText, permissions, newArgs); | var eventArgs = new CommandEventArgs(e.Message, cmd, msg, argText, permissions, newArgs); | ||||
| if (permissions < cmd.MinPerms) | if (permissions < cmd.MinPerms) | ||||
| { | { | ||||
| @@ -5,7 +5,7 @@ | |||||
| /// <summary> A text-only channel. </summary> | /// <summary> A text-only channel. </summary> | ||||
| public static readonly PermissionTarget Role = new PermissionTarget("role"); | public static readonly PermissionTarget Role = new PermissionTarget("role"); | ||||
| /// <summary> A voice-only channel. </summary> | /// <summary> A voice-only channel. </summary> | ||||
| public static readonly PermissionTarget Member = new PermissionTarget("member"); | |||||
| public static readonly PermissionTarget User = new PermissionTarget("member"); | |||||
| private PermissionTarget(string value) | private PermissionTarget(string value) | ||||
| : base(value) { } | : base(value) { } | ||||
| @@ -19,7 +19,7 @@ | |||||
| case "role": | case "role": | ||||
| return PermissionTarget.Role; | return PermissionTarget.Role; | ||||
| case "member": | case "member": | ||||
| return PermissionTarget.Member; | |||||
| return PermissionTarget.User; | |||||
| default: | default: | ||||
| return new PermissionTarget(value); | return new PermissionTarget(value); | ||||
| } | } | ||||
| @@ -106,7 +106,7 @@ namespace Discord | |||||
| if (channel == null) | if (channel == null) | ||||
| { | { | ||||
| var response = await _api.CreatePMChannel(_userId, member.Id).ConfigureAwait(false); | var response = await _api.CreatePMChannel(_userId, member.Id).ConfigureAwait(false); | ||||
| var recipient = _members.GetOrAdd(response.Recipient?.Id, null); | |||||
| var recipient = _users.GetOrAdd(response.Recipient?.Id, null); | |||||
| recipient.Update(response.Recipient); | recipient.Update(response.Recipient); | ||||
| channel = _channels.GetOrAdd(response.Id, response.GuildId, response.Recipient?.Id); | channel = _channels.GetOrAdd(response.Id, response.GuildId, response.Recipient?.Id); | ||||
| channel.Update(response); | channel.Update(response); | ||||
| @@ -5,9 +5,9 @@ using System.Threading.Tasks; | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| internal sealed class Members : AsyncCollection<User> | |||||
| internal sealed class Users : AsyncCollection<User> | |||||
| { | { | ||||
| public Members(DiscordClient client, object writerLock) | |||||
| public Users(DiscordClient client, object writerLock) | |||||
| : base(client, writerLock, x => x.OnCached(), x => x.OnUncached()) { } | : base(client, writerLock, x => x.OnCached(), x => x.OnUncached()) { } | ||||
| private string GetKey(string userId, string serverId) | private string GetKey(string userId, string serverId) | ||||
| => User.GetId(userId, serverId); | => User.GetId(userId, serverId); | ||||
| @@ -22,25 +22,23 @@ namespace Discord | |||||
| public class MemberEventArgs : EventArgs | public class MemberEventArgs : EventArgs | ||||
| { | { | ||||
| public User Member { get; } | |||||
| public string UserId => Member.Id; | |||||
| public Server Server => Member.Server; | |||||
| public string ServerId => Member.ServerId; | |||||
| public User User { get; } | |||||
| public Server Server => User.Server; | |||||
| internal MemberEventArgs(User member) { Member = member; } | |||||
| internal MemberEventArgs(User user) { User = user; } | |||||
| } | } | ||||
| public class MemberChannelEventArgs : MemberEventArgs | |||||
| public class UserChannelEventArgs : MemberEventArgs | |||||
| { | { | ||||
| public Channel Channel { get; } | public Channel Channel { get; } | ||||
| public string ChannelId => Channel.Id; | public string ChannelId => Channel.Id; | ||||
| internal MemberChannelEventArgs(User member, Channel channel) | |||||
| : base(member) | |||||
| internal UserChannelEventArgs(User user, Channel channel) | |||||
| : base(user) | |||||
| { | { | ||||
| Channel = channel; | Channel = channel; | ||||
| } | } | ||||
| } | } | ||||
| public class MemberIsSpeakingEventArgs : MemberChannelEventArgs | |||||
| public class MemberIsSpeakingEventArgs : UserChannelEventArgs | |||||
| { | { | ||||
| public bool IsSpeaking { get; } | public bool IsSpeaking { get; } | ||||
| @@ -53,11 +51,11 @@ namespace Discord | |||||
| public partial class DiscordClient | public partial class DiscordClient | ||||
| { | { | ||||
| public event EventHandler<MemberChannelEventArgs> UserIsTyping; | |||||
| public event EventHandler<UserChannelEventArgs> UserIsTyping; | |||||
| private void RaiseUserIsTyping(User member, Channel channel) | private void RaiseUserIsTyping(User member, Channel channel) | ||||
| { | { | ||||
| if (UserIsTyping != null) | if (UserIsTyping != null) | ||||
| RaiseEvent(nameof(UserIsTyping), () => UserIsTyping(this, new MemberChannelEventArgs(member, channel))); | |||||
| RaiseEvent(nameof(UserIsTyping), () => UserIsTyping(this, new UserChannelEventArgs(member, channel))); | |||||
| } | } | ||||
| public event EventHandler<MemberIsSpeakingEventArgs> UserIsSpeaking; | public event EventHandler<MemberIsSpeakingEventArgs> UserIsSpeaking; | ||||
| private void RaiseUserIsSpeaking(User member, Channel channel, bool isSpeaking) | private void RaiseUserIsSpeaking(User member, Channel channel, bool isSpeaking) | ||||
| @@ -68,8 +66,8 @@ namespace Discord | |||||
| private User _currentUser; | private User _currentUser; | ||||
| internal Members Members => _members; | |||||
| private readonly Members _members; | |||||
| internal Users Users => _users; | |||||
| private readonly Users _users; | |||||
| /// <summary> Returns the user with the specified id, along with their server-specific data, or null if none was found. </summary> | /// <summary> Returns the user with the specified id, along with their server-specific data, or null if none was found. </summary> | ||||
| public User GetMember(Server server, string userId) | public User GetMember(Server server, string userId) | ||||
| @@ -78,7 +76,7 @@ namespace Discord | |||||
| if (userId == null) throw new ArgumentNullException(nameof(userId)); | if (userId == null) throw new ArgumentNullException(nameof(userId)); | ||||
| CheckReady(); | CheckReady(); | ||||
| return _members[userId, server.Id]; | |||||
| return _users[userId, server.Id]; | |||||
| } | } | ||||
| /// <summary> Returns the user with the specified name and discriminator, along withtheir server-specific data, or null if they couldn't be found. </summary> | /// <summary> Returns the user with the specified name and discriminator, along withtheir server-specific data, or null if they couldn't be found. </summary> | ||||
| /// <remarks> Name formats supported: Name and @Name. Search is case-insensitive. </remarks> | /// <remarks> Name formats supported: Name and @Name. Search is case-insensitive. </remarks> | ||||
| @@ -90,7 +88,7 @@ namespace Discord | |||||
| CheckReady(); | CheckReady(); | ||||
| User member = FindMembers(server, username, discriminator, true).FirstOrDefault(); | User member = FindMembers(server, username, discriminator, true).FirstOrDefault(); | ||||
| return _members[member?.Id, server.Id]; | |||||
| return _users[member?.Id, server.Id]; | |||||
| } | } | ||||
| /// <summary> Returns all users in with the specified server and name, along with their server-specific data. </summary> | /// <summary> Returns all users in with the specified server and name, along with their server-specific data. </summary> | ||||
| @@ -34,7 +34,7 @@ namespace Discord | |||||
| public class MessageEventArgs : EventArgs | public class MessageEventArgs : EventArgs | ||||
| { | { | ||||
| public Message Message { get; } | public Message Message { get; } | ||||
| public User Member => Message.Member; | |||||
| public User Member => Message.User; | |||||
| public Channel Channel => Message.Channel; | public Channel Channel => Message.Channel; | ||||
| public Server Server => Message.Server; | public Server Server => Message.Server; | ||||
| @@ -118,7 +118,7 @@ namespace Discord | |||||
| { | { | ||||
| var nonce = GenerateNonce(); | var nonce = GenerateNonce(); | ||||
| msg = _messages.GetOrAdd("nonce_" + nonce, channel.Id, _userId); | msg = _messages.GetOrAdd("nonce_" + nonce, channel.Id, _userId); | ||||
| var currentUser = msg.Member; | |||||
| var currentUser = msg.User; | |||||
| msg.Update(new MessageInfo | msg.Update(new MessageInfo | ||||
| { | { | ||||
| Content = text, | Content = text, | ||||
| @@ -127,7 +127,7 @@ namespace Discord | |||||
| ChannelId = channel.Id, | ChannelId = channel.Id, | ||||
| IsTextToSpeech = isTextToSpeech | IsTextToSpeech = isTextToSpeech | ||||
| }); | }); | ||||
| msg.Mentions = userIds.Select(x => _members[x, channel.Server.Id]).Where(x => x != null).ToArray(); | |||||
| msg.Mentions = userIds.Select(x => _users[x, channel.Server.Id]).Where(x => x != null).ToArray(); | |||||
| msg.IsQueued = true; | msg.IsQueued = true; | ||||
| msg.Nonce = nonce; | msg.Nonce = nonce; | ||||
| _pendingMessages.Enqueue(msg); | _pendingMessages.Enqueue(msg); | ||||
| @@ -218,7 +218,7 @@ namespace Discord | |||||
| { | { | ||||
| if (!channel.IsPrivate) | if (!channel.IsPrivate) | ||||
| { | { | ||||
| var member = msg.Member; | |||||
| var member = msg.User; | |||||
| if (member != null) | if (member != null) | ||||
| member.UpdateActivity(msg.EditedTimestamp ?? msg.Timestamp); | member.UpdateActivity(msg.EditedTimestamp ?? msg.Timestamp); | ||||
| } | } | ||||
| @@ -13,7 +13,7 @@ namespace Discord | |||||
| if (member == null) throw new ArgumentNullException(nameof(member)); | if (member == null) throw new ArgumentNullException(nameof(member)); | ||||
| CheckReady(); | CheckReady(); | ||||
| return SetChannelPermissions(channel, member?.Id, PermissionTarget.Member, allow, deny); | |||||
| return SetChannelPermissions(channel, member?.Id, PermissionTarget.User, allow, deny); | |||||
| } | } | ||||
| public Task SetChannelUserPermissions(Channel channel, User member, DualChannelPermissions permissions = null) | public Task SetChannelUserPermissions(Channel channel, User member, DualChannelPermissions permissions = null) | ||||
| { | { | ||||
| @@ -21,7 +21,7 @@ namespace Discord | |||||
| if (member == null) throw new ArgumentNullException(nameof(member)); | if (member == null) throw new ArgumentNullException(nameof(member)); | ||||
| CheckReady(); | CheckReady(); | ||||
| return SetChannelPermissions(channel, member?.Id, PermissionTarget.Member, permissions?.Allow, permissions?.Deny); | |||||
| return SetChannelPermissions(channel, member?.Id, PermissionTarget.User, permissions?.Allow, permissions?.Deny); | |||||
| } | } | ||||
| public Task SetChannelRolePermissions(Channel channel, Role role, ChannelPermissions allow = null, ChannelPermissions deny = null) | public Task SetChannelRolePermissions(Channel channel, Role role, ChannelPermissions allow = null, ChannelPermissions deny = null) | ||||
| { | { | ||||
| @@ -82,7 +82,7 @@ namespace Discord | |||||
| { | { | ||||
| if (targetType == PermissionTarget.Role) | if (targetType == PermissionTarget.Role) | ||||
| channel.InvalidatePermissionsCache(); | channel.InvalidatePermissionsCache(); | ||||
| else if (targetType == PermissionTarget.Member) | |||||
| else if (targetType == PermissionTarget.User) | |||||
| channel.InvalidatePermissionsCache(targetId); | channel.InvalidatePermissionsCache(targetId); | ||||
| } | } | ||||
| } | } | ||||
| @@ -93,7 +93,7 @@ namespace Discord | |||||
| if (member == null) throw new ArgumentNullException(nameof(member)); | if (member == null) throw new ArgumentNullException(nameof(member)); | ||||
| CheckReady(); | CheckReady(); | ||||
| return RemoveChannelPermissions(channel, member?.Id, PermissionTarget.Member); | |||||
| return RemoveChannelPermissions(channel, member?.Id, PermissionTarget.User); | |||||
| } | } | ||||
| public Task RemoveChannelRolePermissions(Channel channel, Role role) | public Task RemoveChannelRolePermissions(Channel channel, Role role) | ||||
| { | { | ||||
| @@ -115,7 +115,7 @@ namespace Discord | |||||
| if (targetType == PermissionTarget.Role) | if (targetType == PermissionTarget.Role) | ||||
| channel.InvalidatePermissionsCache(); | channel.InvalidatePermissionsCache(); | ||||
| else if (targetType == PermissionTarget.Member) | |||||
| else if (targetType == PermissionTarget.User) | |||||
| channel.InvalidatePermissionsCache(userOrRoleId); | channel.InvalidatePermissionsCache(userOrRoleId); | ||||
| } | } | ||||
| } | } | ||||
| @@ -6,9 +6,9 @@ using System.Threading.Tasks; | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| internal sealed class Users : AsyncCollection<GlobalUser> | |||||
| internal sealed class GlobalUsers : AsyncCollection<GlobalUser> | |||||
| { | { | ||||
| public Users(DiscordClient client, object writerLock) | |||||
| public GlobalUsers(DiscordClient client, object writerLock) | |||||
| : base(client, writerLock, x => x.OnCached(), x => x.OnUncached()) { } | : base(client, writerLock, x => x.OnCached(), x => x.OnUncached()) { } | ||||
| public GlobalUser GetOrAdd(string id) => GetOrAdd(id, () => new GlobalUser(_client, id)); | public GlobalUser GetOrAdd(string id) => GetOrAdd(id, () => new GlobalUser(_client, id)); | ||||
| @@ -54,8 +54,8 @@ namespace Discord | |||||
| } | } | ||||
| /// <summary> Returns a collection of all users this client can currently see. </summary> | /// <summary> Returns a collection of all users this client can currently see. </summary> | ||||
| internal Users Users => _users; | |||||
| private readonly Users _users; | |||||
| internal GlobalUsers GlobalUsers => _globalUsers; | |||||
| private readonly GlobalUsers _globalUsers; | |||||
| public Task<EditUserResponse> EditProfile(string currentPassword = "", | public Task<EditUserResponse> EditProfile(string currentPassword = "", | ||||
| string username = null, string email = null, string password = null, | string username = null, string email = null, string password = null, | ||||
| @@ -43,11 +43,11 @@ namespace Discord | |||||
| object cacheLock = new object(); | object cacheLock = new object(); | ||||
| _channels = new Channels(this, cacheLock); | _channels = new Channels(this, cacheLock); | ||||
| _members = new Members(this, cacheLock); | |||||
| _users = new Users(this, cacheLock); | |||||
| _messages = new Messages(this, cacheLock, Config.MessageCacheLength > 0); | _messages = new Messages(this, cacheLock, Config.MessageCacheLength > 0); | ||||
| _roles = new Roles(this, cacheLock); | _roles = new Roles(this, cacheLock); | ||||
| _servers = new Servers(this, cacheLock); | _servers = new Servers(this, cacheLock); | ||||
| _users = new Users(this, cacheLock); | |||||
| _globalUsers = new GlobalUsers(this, cacheLock); | |||||
| _status = UserStatus.Online; | _status = UserStatus.Online; | ||||
| @@ -59,7 +59,7 @@ namespace Discord | |||||
| VoiceDisconnected += (s, e) => | VoiceDisconnected += (s, e) => | ||||
| { | { | ||||
| foreach (var member in _members) | |||||
| foreach (var member in _users) | |||||
| { | { | ||||
| if (member.ServerId == e.ServerId && member.IsSpeaking) | if (member.ServerId == e.ServerId && member.IsSpeaking) | ||||
| { | { | ||||
| @@ -117,13 +117,13 @@ namespace Discord | |||||
| if (_config.LogLevel >= LogMessageSeverity.Verbose) | if (_config.LogLevel >= LogMessageSeverity.Verbose) | ||||
| { | { | ||||
| UserIsTyping += (s, e) => RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, | UserIsTyping += (s, e) => RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, | ||||
| $"Updated User (Is Typing): {e.Server?.Name ?? "[Private]"}/{e.Channel?.Name}/{e.Member?.Name}"); | |||||
| $"Updated User (Is Typing): {e.Server?.Name ?? "[Private]"}/{e.Channel?.Name}/{e.User?.Name}"); | |||||
| MessageReadRemotely += (s, e) => RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, | MessageReadRemotely += (s, e) => RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, | ||||
| $"Read Message (Remotely): {e.Server?.Name ?? "[Private]"}/{e.Channel?.Name}/{e.Message?.Id}"); | $"Read Message (Remotely): {e.Server?.Name ?? "[Private]"}/{e.Channel?.Name}/{e.Message?.Id}"); | ||||
| MessageSent += (s, e) => RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, | MessageSent += (s, e) => RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, | ||||
| $"Sent Message: {e.Server?.Name ?? "[Private]"}/{e.Channel?.Name}/{e.Message?.Id}"); | $"Sent Message: {e.Server?.Name ?? "[Private]"}/{e.Channel?.Name}/{e.Message?.Id}"); | ||||
| UserPresenceUpdated += (s, e) => RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, | UserPresenceUpdated += (s, e) => RaiseOnLog(LogMessageSeverity.Verbose, LogMessageSource.Client, | ||||
| $"Updated Member (Presence): {e.Server?.Name ?? "[Private]"}/{e.Member?.Name}"); | |||||
| $"Updated Member (Presence): {e.Server?.Name ?? "[Private]"}/{e.User?.Name}"); | |||||
| _api.RestClient.OnRequest += (s, e) => | _api.RestClient.OnRequest += (s, e) => | ||||
| { | { | ||||
| @@ -138,9 +138,9 @@ namespace Discord | |||||
| _channels.ItemCreated += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Created Channel {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Id}"); | _channels.ItemCreated += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Created Channel {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Id}"); | ||||
| _channels.ItemDestroyed += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Destroyed Channel {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Id}"); | _channels.ItemDestroyed += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Destroyed Channel {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Id}"); | ||||
| _channels.Cleared += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Cleared Channels"); | _channels.Cleared += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Cleared Channels"); | ||||
| _members.ItemCreated += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Created Member {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Id}"); | |||||
| _members.ItemDestroyed += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Destroyed Member {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Id}"); | |||||
| _members.Cleared += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Cleared Members"); | |||||
| _users.ItemCreated += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Created Member {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Id}"); | |||||
| _users.ItemDestroyed += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Destroyed Member {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Id}"); | |||||
| _users.Cleared += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Cleared Members"); | |||||
| _messages.ItemCreated += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Created Message {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Channel.Id}/{e.Item.Id}"); | _messages.ItemCreated += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Created Message {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Channel.Id}/{e.Item.Id}"); | ||||
| _messages.ItemDestroyed += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Destroyed Message {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Channel.Id}/{e.Item.Id}"); | _messages.ItemDestroyed += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Destroyed Message {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Channel.Id}/{e.Item.Id}"); | ||||
| _messages.ItemRemapped += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Remapped Message {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Channel.Id}/[{e.OldId} -> {e.NewId}]"); | _messages.ItemRemapped += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Remapped Message {e.Item.Server?.Id ?? "[Private]"}/{e.Item.Channel.Id}/[{e.OldId} -> {e.NewId}]"); | ||||
| @@ -151,9 +151,9 @@ namespace Discord | |||||
| _servers.ItemCreated += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Created Server {e.Item.Id}"); | _servers.ItemCreated += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Created Server {e.Item.Id}"); | ||||
| _servers.ItemDestroyed += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Destroyed Server {e.Item.Id}"); | _servers.ItemDestroyed += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Destroyed Server {e.Item.Id}"); | ||||
| _servers.Cleared += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Cleared Servers"); | _servers.Cleared += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Cleared Servers"); | ||||
| _users.ItemCreated += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Created User {e.Item.Id}"); | |||||
| _users.ItemDestroyed += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Destroyed User {e.Item.Id}"); | |||||
| _users.Cleared += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Cleared Users"); | |||||
| _globalUsers.ItemCreated += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Created User {e.Item.Id}"); | |||||
| _globalUsers.ItemDestroyed += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Destroyed User {e.Item.Id}"); | |||||
| _globalUsers.Cleared += (s, e) => RaiseOnLog(LogMessageSeverity.Debug, LogMessageSource.Cache, $"Cleared Users"); | |||||
| } | } | ||||
| if (Config.UseMessageQueue) | if (Config.UseMessageQueue) | ||||
| @@ -173,7 +173,7 @@ namespace Discord | |||||
| { | { | ||||
| if (_voiceSocket.State == WebSocketState.Connected) | if (_voiceSocket.State == WebSocketState.Connected) | ||||
| { | { | ||||
| var member = _members[e.UserId, socket.CurrentServerId]; | |||||
| var member = _users[e.UserId, socket.CurrentServerId]; | |||||
| bool value = e.IsSpeaking; | bool value = e.IsSpeaking; | ||||
| if (member.IsSpeaking != value) | if (member.IsSpeaking != value) | ||||
| { | { | ||||
| @@ -260,11 +260,11 @@ namespace Discord | |||||
| await _api.Logout(); | await _api.Logout(); | ||||
| _channels.Clear(); | _channels.Clear(); | ||||
| _members.Clear(); | |||||
| _users.Clear(); | |||||
| _messages.Clear(); | _messages.Clear(); | ||||
| _roles.Clear(); | _roles.Clear(); | ||||
| _servers.Clear(); | _servers.Clear(); | ||||
| _users.Clear(); | |||||
| _globalUsers.Clear(); | |||||
| _currentUser = null; | _currentUser = null; | ||||
| } | } | ||||
| @@ -289,7 +289,7 @@ namespace Discord | |||||
| case "READY": //Resync | case "READY": //Resync | ||||
| { | { | ||||
| var data = e.Payload.ToObject<ReadyEvent>(_serializer); | var data = e.Payload.ToObject<ReadyEvent>(_serializer); | ||||
| _currentUser = _members.GetOrAdd(data.User.Id, null); | |||||
| _currentUser = _users.GetOrAdd(data.User.Id, null); | |||||
| _currentUser.Update(data.User); | _currentUser.Update(data.User); | ||||
| foreach (var model in data.Guilds) | foreach (var model in data.Guilds) | ||||
| { | { | ||||
| @@ -301,7 +301,7 @@ namespace Discord | |||||
| } | } | ||||
| foreach (var model in data.PrivateChannels) | foreach (var model in data.PrivateChannels) | ||||
| { | { | ||||
| var user = _members.GetOrAdd(model.Recipient.Id, null); | |||||
| var user = _users.GetOrAdd(model.Recipient.Id, null); | |||||
| user.Update(model.Recipient); | user.Update(model.Recipient); | ||||
| var channel = _channels.GetOrAdd(model.Id, null, user.Id); | var channel = _channels.GetOrAdd(model.Id, null, user.Id); | ||||
| channel.Update(model); | channel.Update(model); | ||||
| @@ -356,7 +356,7 @@ namespace Discord | |||||
| Channel channel; | Channel channel; | ||||
| if (data.IsPrivate) | if (data.IsPrivate) | ||||
| { | { | ||||
| var member = _members.GetOrAdd(data.Recipient.Id, null); | |||||
| var member = _users.GetOrAdd(data.Recipient.Id, null); | |||||
| member.Update(data.Recipient); | member.Update(data.Recipient); | ||||
| channel = _channels.GetOrAdd(data.Id, null, member.Id); | channel = _channels.GetOrAdd(data.Id, null, member.Id); | ||||
| } | } | ||||
| @@ -390,7 +390,7 @@ namespace Discord | |||||
| case "GUILD_MEMBER_ADD": | case "GUILD_MEMBER_ADD": | ||||
| { | { | ||||
| var data = e.Payload.ToObject<MemberAddEvent>(_serializer); | var data = e.Payload.ToObject<MemberAddEvent>(_serializer); | ||||
| var member = _members.GetOrAdd(data.User.Id, data.GuildId); | |||||
| var member = _users.GetOrAdd(data.User.Id, data.GuildId); | |||||
| member.Update(data); | member.Update(data); | ||||
| if (Config.TrackActivity) | if (Config.TrackActivity) | ||||
| member.UpdateActivity(); | member.UpdateActivity(); | ||||
| @@ -400,7 +400,7 @@ namespace Discord | |||||
| case "GUILD_MEMBER_UPDATE": | case "GUILD_MEMBER_UPDATE": | ||||
| { | { | ||||
| var data = e.Payload.ToObject<MemberUpdateEvent>(_serializer); | var data = e.Payload.ToObject<MemberUpdateEvent>(_serializer); | ||||
| var member = _members[data.User.Id, data.GuildId]; | |||||
| var member = _users[data.User.Id, data.GuildId]; | |||||
| if (member != null) | if (member != null) | ||||
| { | { | ||||
| member.Update(data); | member.Update(data); | ||||
| @@ -411,7 +411,7 @@ namespace Discord | |||||
| case "GUILD_MEMBER_REMOVE": | case "GUILD_MEMBER_REMOVE": | ||||
| { | { | ||||
| var data = e.Payload.ToObject<MemberRemoveEvent>(_serializer); | var data = e.Payload.ToObject<MemberRemoveEvent>(_serializer); | ||||
| var member = _members.TryRemove(data.UserId, data.GuildId); | |||||
| var member = _users.TryRemove(data.UserId, data.GuildId); | |||||
| if (member != null) | if (member != null) | ||||
| RaiseUserRemoved(member); | RaiseUserRemoved(member); | ||||
| } | } | ||||
| @@ -491,7 +491,7 @@ namespace Discord | |||||
| var channel = msg.Channel; | var channel = msg.Channel; | ||||
| if (channel?.IsPrivate == false) | if (channel?.IsPrivate == false) | ||||
| { | { | ||||
| var member = msg.Member; | |||||
| var member = msg.User; | |||||
| if (member != null) | if (member != null) | ||||
| member.UpdateActivity(data.Timestamp); | member.UpdateActivity(data.Timestamp); | ||||
| } | } | ||||
| @@ -535,7 +535,7 @@ namespace Discord | |||||
| case "PRESENCE_UPDATE": | case "PRESENCE_UPDATE": | ||||
| { | { | ||||
| var data = e.Payload.ToObject<PresenceUpdateEvent>(_serializer); | var data = e.Payload.ToObject<PresenceUpdateEvent>(_serializer); | ||||
| var member = _members.GetOrAdd(data.User.Id, data.GuildId); | |||||
| var member = _users.GetOrAdd(data.User.Id, data.GuildId); | |||||
| if (member != null) | if (member != null) | ||||
| { | { | ||||
| member.Update(data); | member.Update(data); | ||||
| @@ -549,7 +549,7 @@ namespace Discord | |||||
| var channel = _channels[data.ChannelId]; | var channel = _channels[data.ChannelId]; | ||||
| if (channel != null) | if (channel != null) | ||||
| { | { | ||||
| var user = _members[data.UserId, channel.Server?.Id]; | |||||
| var user = _users[data.UserId, channel.Server?.Id]; | |||||
| if (user != null) | if (user != null) | ||||
| { | { | ||||
| @@ -560,7 +560,7 @@ namespace Discord | |||||
| { | { | ||||
| if (!channel.IsPrivate) | if (!channel.IsPrivate) | ||||
| { | { | ||||
| var member = _members[data.UserId, channel.Server.Id]; | |||||
| var member = _users[data.UserId, channel.Server.Id]; | |||||
| if (member != null) | if (member != null) | ||||
| member.UpdateActivity(); | member.UpdateActivity(); | ||||
| } | } | ||||
| @@ -573,7 +573,7 @@ namespace Discord | |||||
| case "VOICE_STATE_UPDATE": | case "VOICE_STATE_UPDATE": | ||||
| { | { | ||||
| var data = e.Payload.ToObject<MemberVoiceStateUpdateEvent>(_serializer); | var data = e.Payload.ToObject<MemberVoiceStateUpdateEvent>(_serializer); | ||||
| var member = _members[data.UserId, data.GuildId]; | |||||
| var member = _users[data.UserId, data.GuildId]; | |||||
| if (member != null) | if (member != null) | ||||
| { | { | ||||
| if (data.ChannelId != member.VoiceChannelId && member.IsSpeaking) | if (data.ChannelId != member.VoiceChannelId && member.IsSpeaking) | ||||
| @@ -591,7 +591,7 @@ namespace Discord | |||||
| case "USER_UPDATE": | case "USER_UPDATE": | ||||
| { | { | ||||
| var data = e.Payload.ToObject<UserUpdateEvent>(_serializer); | var data = e.Payload.ToObject<UserUpdateEvent>(_serializer); | ||||
| var user = _users[data.Id]; | |||||
| var user = _globalUsers[data.Id]; | |||||
| if (user != null) | if (user != null) | ||||
| { | { | ||||
| user.Update(data); | user.Update(data); | ||||
| @@ -10,8 +10,8 @@ namespace Discord | |||||
| private static readonly Regex _channelRegex = new Regex(@"<#(\d+?)>", RegexOptions.Compiled); | private static readonly Regex _channelRegex = new Regex(@"<#(\d+?)>", RegexOptions.Compiled); | ||||
| /// <summary> Returns the string used to create a user mention. </summary> | /// <summary> Returns the string used to create a user mention. </summary> | ||||
| public static string User(User member) | |||||
| => $"<@{member.Id}>"; | |||||
| public static string User(User user) | |||||
| => $"<@{user.Id}>"; | |||||
| /// <summary> Returns the string used to create a channel mention. </summary> | /// <summary> Returns the string used to create a channel mention. </summary> | ||||
| public static string Channel(Channel channel) | public static string Channel(Channel channel) | ||||
| => $"<#{channel.Id}>"; | => $"<#{channel.Id}>"; | ||||
| @@ -24,7 +24,7 @@ namespace Discord | |||||
| text = _userRegex.Replace(text, new MatchEvaluator(e => | text = _userRegex.Replace(text, new MatchEvaluator(e => | ||||
| { | { | ||||
| string id = e.Value.Substring(2, e.Value.Length - 3); | string id = e.Value.Substring(2, e.Value.Length - 3); | ||||
| var user = client.Members[id, server.Id]; | |||||
| var user = client.Users[id, server.Id]; | |||||
| if (user != null) | if (user != null) | ||||
| return '@' + user.Name; | return '@' + user.Name; | ||||
| else //User not found | else //User not found | ||||
| @@ -54,14 +54,14 @@ namespace Discord | |||||
| get | get | ||||
| { | { | ||||
| if (!_areMembersStale) | if (!_areMembersStale) | ||||
| return _members; | |||||
| return _members.Select(x => x.Value); | |||||
| _members = Server.Members.Where(x => x.GetPermissions(this)?.ReadMessages ?? false).ToArray(); | |||||
| _members = Server.Members.Where(x => x.GetPermissions(this)?.ReadMessages ?? false).ToDictionary(x => x.Id, x => x); | |||||
| _areMembersStale = false; | _areMembersStale = false; | ||||
| return _members; | |||||
| return _members.Select(x => x.Value); | |||||
| } | } | ||||
| } | } | ||||
| private User[] _members; | |||||
| private Dictionary<string, User> _members; | |||||
| private bool _areMembersStale; | private bool _areMembersStale; | ||||
| /// <summary> Returns a collection of all messages the client has seen posted in this channel. This collection does not guarantee any ordering. </summary> | /// <summary> Returns a collection of all messages the client has seen posted in this channel. This collection does not guarantee any ordering. </summary> | ||||
| @@ -90,7 +90,7 @@ namespace Discord | |||||
| if (IsPrivate) | if (IsPrivate) | ||||
| { | { | ||||
| var recipient = _client.Members[_recipientId, _serverId]; | |||||
| var recipient = _client.Users[_recipientId, _serverId]; | |||||
| Name = "@" + recipient.Name; | Name = "@" + recipient.Name; | ||||
| Recipient = recipient; | Recipient = recipient; | ||||
| } | } | ||||
| @@ -170,9 +170,9 @@ namespace Discord | |||||
| internal void InvalidatePermissionsCache(string userId) | internal void InvalidatePermissionsCache(string userId) | ||||
| { | { | ||||
| _areMembersStale = true; | _areMembersStale = true; | ||||
| var member = _client.Members[userId, _serverId]; | |||||
| if (member != null) | |||||
| member.UpdateChannelPermissions(this); | |||||
| var user = _members[userId] | |||||
| if (user != null) | |||||
| user.UpdateChannelPermissions(this); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -26,7 +26,7 @@ namespace Discord | |||||
| /// <summary> Returns a collection of all server-specific data for every server this user is a member of. </summary> | /// <summary> Returns a collection of all server-specific data for every server this user is a member of. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public IEnumerable<User> Memberships => _users.Select(x => _client.Members[Id, x.Key]); | |||||
| public IEnumerable<User> Memberships => _users.Select(x => _client.Users[Id, x.Key]); | |||||
| internal GlobalUser(DiscordClient client, string id) | internal GlobalUser(DiscordClient client, string id) | ||||
| : base(client, id) | : base(client, id) | ||||
| @@ -50,7 +50,7 @@ namespace Discord | |||||
| if (_users.TryRemove(user.Id, out user)) | if (_users.TryRemove(user.Id, out user)) | ||||
| { | { | ||||
| if (_users.Count == 0) | if (_users.Count == 0) | ||||
| _client.Users.TryRemove(Id); | |||||
| _client.GlobalUsers.TryRemove(Id); | |||||
| } | } | ||||
| } | } | ||||
| @@ -27,7 +27,7 @@ namespace Discord | |||||
| /// <summary> Returns the user that created this invite. </summary> | /// <summary> Returns the user that created this invite. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public User Inviter => _client.Members[_inviterId, _serverId]; | |||||
| public User Inviter => _client.Users[_inviterId, _serverId]; | |||||
| /// <summary> Returns the server this invite is to. </summary> | /// <summary> Returns the server this invite is to. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| @@ -144,7 +144,7 @@ namespace Discord | |||||
| public string UserId { get; } | public string UserId { get; } | ||||
| /// <summary> Returns the author of this message. </summary> | /// <summary> Returns the author of this message. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public User Member => _client.Members[_userId, Channel.Server.Id]; | |||||
| public User User => _client.Users[_userId, Channel.Server.Id]; | |||||
| internal Message(DiscordClient client, string id, string channelId, string userId) | internal Message(DiscordClient client, string id, string channelId, string userId) | ||||
| : base(client, id) | : base(client, id) | ||||
| @@ -214,6 +214,6 @@ namespace Discord | |||||
| } | } | ||||
| } | } | ||||
| public override string ToString() => Member.Name + ": " + RawText; | |||||
| public override string ToString() => User.Name + ": " + RawText; | |||||
| } | } | ||||
| } | } | ||||
| @@ -71,7 +71,7 @@ namespace Discord | |||||
| /// <summary> Returns a collection of all users within this server with their server-specific data. </summary> | /// <summary> Returns a collection of all users within this server with their server-specific data. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public IEnumerable<User> Members => _members.Select(x => _client.Members[x.Key, Id]); | |||||
| public IEnumerable<User> Members => _members.Select(x => _client.Users[x.Key, Id]); | |||||
| /// <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 => Id; | public string EveryoneRoleId => Id; | ||||
| @@ -102,7 +102,7 @@ namespace Discord | |||||
| foreach (var channel in _channels) | foreach (var channel in _channels) | ||||
| channels.TryRemove(channel.Key); | channels.TryRemove(channel.Key); | ||||
| var members = _client.Members; | |||||
| var members = _client.Users; | |||||
| foreach (var user in _members) | foreach (var user in _members) | ||||
| members.TryRemove(user.Key, Id); | members.TryRemove(user.Key, Id); | ||||
| @@ -132,7 +132,7 @@ namespace Discord | |||||
| if (model.OwnerId != null && _ownerId != model.OwnerId) | if (model.OwnerId != null && _ownerId != model.OwnerId) | ||||
| { | { | ||||
| _ownerId = model.OwnerId; | _ownerId = model.OwnerId; | ||||
| Owner = _client.Members[_ownerId, Id]; | |||||
| Owner = _client.Users[_ownerId, Id]; | |||||
| } | } | ||||
| if (model.Region != null) | if (model.Region != null) | ||||
| Region = model.Region; | Region = model.Region; | ||||
| @@ -158,8 +158,8 @@ namespace Discord | |||||
| channel.Update(subModel); | channel.Update(subModel); | ||||
| } | } | ||||
| var users = _client.Users; | |||||
| var members = _client.Members; | |||||
| var users = _client.GlobalUsers; | |||||
| var members = _client.Users; | |||||
| foreach (var subModel in model.Members) | foreach (var subModel in model.Members) | ||||
| { | { | ||||
| var member = members.GetOrAdd(subModel.User.Id, Id); | var member = members.GetOrAdd(subModel.User.Id, Id); | ||||
| @@ -52,7 +52,7 @@ namespace Discord | |||||
| private DateTime _lastOnline; | private DateTime _lastOnline; | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| internal GlobalUser GlobalUser => _client.Users[Id]; | |||||
| internal GlobalUser GlobalUser => _client.GlobalUsers[Id]; | |||||
| public string ServerId { get; } | public string ServerId { get; } | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| @@ -213,9 +213,9 @@ namespace Discord | |||||
| newPermissions &= ~denyRole.Deny.RawValue; | newPermissions &= ~denyRole.Deny.RawValue; | ||||
| foreach (var allowRole in channelOverwrites.Where(x => x.TargetType == PermissionTarget.Role && x.Allow.RawValue != 0 && roles.Any(y => y.Id == x.TargetId))) | foreach (var allowRole in channelOverwrites.Where(x => x.TargetType == PermissionTarget.Role && x.Allow.RawValue != 0 && roles.Any(y => y.Id == x.TargetId))) | ||||
| newPermissions |= allowRole.Allow.RawValue; | newPermissions |= allowRole.Allow.RawValue; | ||||
| foreach (var denyMembers in channelOverwrites.Where(x => x.TargetType == PermissionTarget.Member && x.TargetId == Id && x.Deny.RawValue != 0)) | |||||
| foreach (var denyMembers in channelOverwrites.Where(x => x.TargetType == PermissionTarget.User && x.TargetId == Id && x.Deny.RawValue != 0)) | |||||
| newPermissions &= ~denyMembers.Deny.RawValue; | newPermissions &= ~denyMembers.Deny.RawValue; | ||||
| foreach (var allowMembers in channelOverwrites.Where(x => x.TargetType == PermissionTarget.Member && x.TargetId == Id && x.Allow.RawValue != 0)) | |||||
| foreach (var allowMembers in channelOverwrites.Where(x => x.TargetType == PermissionTarget.User && x.TargetId == Id && x.Allow.RawValue != 0)) | |||||
| newPermissions |= allowMembers.Allow.RawValue; | newPermissions |= allowMembers.Allow.RawValue; | ||||
| } | } | ||||