From 3e5fd7ed26b4e096af0399f02c612ab1d63d15c4 Mon Sep 17 00:00:00 2001 From: Casino Boyale Date: Wed, 13 Mar 2019 20:19:23 +0000 Subject: [PATCH] Made the client public on socket entities --- .../Audio/AudioClient.cs | 2 +- .../Channels/SocketCategoryChannel.cs | 2 +- .../Entities/Channels/SocketDMChannel.cs | 48 ++++----- .../Entities/Channels/SocketGroupChannel.cs | 48 ++++----- .../Entities/Channels/SocketGuildChannel.cs | 14 +-- .../Entities/Channels/SocketTextChannel.cs | 60 ++++++------ .../Entities/Channels/SocketVoiceChannel.cs | 10 +- .../Entities/Guilds/SocketGuild.cs | 98 +++++++++---------- .../Entities/Messages/SocketMessage.cs | 2 +- .../Entities/Messages/SocketUserMessage.cs | 18 ++-- .../Entities/Roles/SocketRole.cs | 6 +- .../Entities/SocketEntity.cs | 4 +- .../Entities/Users/SocketGroupUser.cs | 4 +- .../Entities/Users/SocketGuildUser.cs | 16 +-- .../Entities/Users/SocketSelfUser.cs | 2 +- .../Entities/Users/SocketUser.cs | 4 +- .../Entities/Users/SocketWebhookUser.cs | 2 +- 17 files changed, 170 insertions(+), 170 deletions(-) diff --git a/src/Discord.Net.WebSocket/Audio/AudioClient.cs b/src/Discord.Net.WebSocket/Audio/AudioClient.cs index 2210e019f..dfaa3478b 100644 --- a/src/Discord.Net.WebSocket/Audio/AudioClient.cs +++ b/src/Discord.Net.WebSocket/Audio/AudioClient.cs @@ -53,7 +53,7 @@ namespace Discord.Audio public ulong ChannelId { get; internal set; } internal byte[] SecretKey { get; private set; } - private DiscordSocketClient Discord => Guild.Discord; + private DiscordSocketClient Discord => Guild.Client; public ConnectionState ConnectionState => _connection.State; /// Creates a new REST/WebSocket discord client. diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs index b90c1976a..c1e97c516 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs @@ -37,7 +37,7 @@ namespace Discord.WebSocket } internal new static SocketCategoryChannel Create(SocketGuild guild, ClientState state, Model model) { - var entity = new SocketCategoryChannel(guild.Discord, model.Id, guild); + var entity = new SocketCategoryChannel(guild.Client, model.Id, guild); entity.Update(state, model); return entity; } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs index cd03505ef..a4ffaf9bd 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs @@ -29,15 +29,15 @@ namespace Discord.WebSocket /// /// Gets a collection that is the current logged-in user and the recipient. /// - public new IReadOnlyCollection Users => ImmutableArray.Create(Discord.CurrentUser, Recipient); + public new IReadOnlyCollection Users => ImmutableArray.Create(Client.CurrentUser, Recipient); internal SocketDMChannel(DiscordSocketClient discord, ulong id, SocketGlobalUser recipient) : base(discord, id) { Recipient = recipient; recipient.GlobalUser.AddRef(); - if (Discord.MessageCacheSize > 0) - _messages = new MessageCache(Discord); + if (Client.MessageCacheSize > 0) + _messages = new MessageCache(Client); } internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, Model model) { @@ -52,7 +52,7 @@ namespace Discord.WebSocket /// public Task CloseAsync(RequestOptions options = null) - => ChannelHelper.DeleteAsync(this, Discord, options); + => ChannelHelper.DeleteAsync(this, Client, options); //Messages /// @@ -70,7 +70,7 @@ namespace Discord.WebSocket { IMessage msg = _messages?.Get(id); if (msg == null) - msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options).ConfigureAwait(false); + msg = await ChannelHelper.GetMessageAsync(this, Client, id, options).ConfigureAwait(false); return msg; } @@ -87,7 +87,7 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); /// /// Gets a collection of messages in this channel. /// @@ -103,7 +103,7 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload, options); /// /// Gets a collection of messages in this channel. /// @@ -119,45 +119,45 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload, options); /// public IReadOnlyCollection GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, null, Direction.Before, limit); + => SocketChannelHelper.GetCachedMessages(this, Client, _messages, null, Direction.Before, limit); /// public IReadOnlyCollection GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessageId, dir, limit); + => SocketChannelHelper.GetCachedMessages(this, Client, _messages, fromMessageId, dir, limit); /// public IReadOnlyCollection GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessage.Id, dir, limit); + => SocketChannelHelper.GetCachedMessages(this, Client, _messages, fromMessage.Id, dir, limit); /// public Task> GetPinnedMessagesAsync(RequestOptions options = null) - => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); + => ChannelHelper.GetPinnedMessagesAsync(this, Client, options); /// /// Message content is too long, length must be less or equal to . public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); + => ChannelHelper.SendMessageAsync(this, Client, text, isTTS, embed, options); /// public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options); + => ChannelHelper.SendFileAsync(this, Client, filePath, text, isTTS, embed, options); /// /// Message content is too long, length must be less or equal to . public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); + => ChannelHelper.SendFileAsync(this, Client, stream, filename, text, isTTS, embed, options); /// public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) - => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); + => ChannelHelper.DeleteMessageAsync(this, messageId, Client, options); /// public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) - => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); + => ChannelHelper.DeleteMessageAsync(this, message.Id, Client, options); /// public Task TriggerTypingAsync(RequestOptions options = null) - => ChannelHelper.TriggerTypingAsync(this, Discord, options); + => ChannelHelper.TriggerTypingAsync(this, Client, options); /// public IDisposable EnterTypingState(RequestOptions options = null) - => ChannelHelper.EnterTypingState(this, Discord, options); + => ChannelHelper.EnterTypingState(this, Client, options); internal void AddMessage(SocketMessage msg) => _messages?.Add(msg); @@ -176,8 +176,8 @@ namespace Discord.WebSocket { if (id == Recipient.Id) return Recipient; - else if (id == Discord.CurrentUser.Id) - return Discord.CurrentUser; + else if (id == Client.CurrentUser.Id) + return Client.CurrentUser; else return null; } @@ -218,13 +218,13 @@ namespace Discord.WebSocket } /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, null, Direction.Before, limit, mode, options); /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessageId, dir, limit, mode, options); /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessage.Id, dir, limit, mode, options); /// async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) => await GetPinnedMessagesAsync(options).ConfigureAwait(false); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs index 07b7066b9..e6cbb3f4f 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs @@ -33,13 +33,13 @@ namespace Discord.WebSocket public IReadOnlyCollection CachedMessages => _messages?.Messages ?? ImmutableArray.Create(); public new IReadOnlyCollection Users => _users.ToReadOnlyCollection(); public IReadOnlyCollection Recipients - => _users.Select(x => x.Value).Where(x => x.Id != Discord.CurrentUser.Id).ToReadOnlyCollection(() => _users.Count - 1); + => _users.Select(x => x.Value).Where(x => x.Id != Client.CurrentUser.Id).ToReadOnlyCollection(() => _users.Count - 1); internal SocketGroupChannel(DiscordSocketClient discord, ulong id) : base(discord, id) { - if (Discord.MessageCacheSize > 0) - _messages = new MessageCache(Discord); + if (Client.MessageCacheSize > 0) + _messages = new MessageCache(Client); _voiceStates = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, 5); _users = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, 5); } @@ -69,7 +69,7 @@ namespace Discord.WebSocket /// public Task LeaveAsync(RequestOptions options = null) - => ChannelHelper.DeleteAsync(this, Discord, options); + => ChannelHelper.DeleteAsync(this, Client, options); /// Voice is not yet supported for group channels. public Task ConnectAsync() @@ -98,7 +98,7 @@ namespace Discord.WebSocket { IMessage msg = _messages?.Get(id); if (msg == null) - msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options).ConfigureAwait(false); + msg = await ChannelHelper.GetMessageAsync(this, Client, id, options).ConfigureAwait(false); return msg; } @@ -115,7 +115,7 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); /// /// Gets a collection of messages in this channel. /// @@ -131,7 +131,7 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload, options); /// /// Gets a collection of messages in this channel. /// @@ -147,45 +147,45 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload, options); /// public IReadOnlyCollection GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, null, Direction.Before, limit); + => SocketChannelHelper.GetCachedMessages(this, Client, _messages, null, Direction.Before, limit); /// public IReadOnlyCollection GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessageId, dir, limit); + => SocketChannelHelper.GetCachedMessages(this, Client, _messages, fromMessageId, dir, limit); /// public IReadOnlyCollection GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessage.Id, dir, limit); + => SocketChannelHelper.GetCachedMessages(this, Client, _messages, fromMessage.Id, dir, limit); /// public Task> GetPinnedMessagesAsync(RequestOptions options = null) - => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); + => ChannelHelper.GetPinnedMessagesAsync(this, Client, options); /// /// Message content is too long, length must be less or equal to . public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); + => ChannelHelper.SendMessageAsync(this, Client, text, isTTS, embed, options); /// public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options); + => ChannelHelper.SendFileAsync(this, Client, filePath, text, isTTS, embed, options); /// public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); + => ChannelHelper.SendFileAsync(this, Client, stream, filename, text, isTTS, embed, options); /// public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) - => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); + => ChannelHelper.DeleteMessageAsync(this, messageId, Client, options); /// public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) - => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); + => ChannelHelper.DeleteMessageAsync(this, message.Id, Client, options); /// public Task TriggerTypingAsync(RequestOptions options = null) - => ChannelHelper.TriggerTypingAsync(this, Discord, options); + => ChannelHelper.TriggerTypingAsync(this, Client, options); /// public IDisposable EnterTypingState(RequestOptions options = null) - => ChannelHelper.EnterTypingState(this, Discord, options); + => ChannelHelper.EnterTypingState(this, Client, options); internal void AddMessage(SocketMessage msg) => _messages?.Add(msg); @@ -212,7 +212,7 @@ namespace Discord.WebSocket return user; else { - var privateUser = SocketGroupUser.Create(this, Discord.State, model); + var privateUser = SocketGroupUser.Create(this, Client.State, model); privateUser.GlobalUser.AddRef(); _users[privateUser.Id] = privateUser; return privateUser; @@ -222,7 +222,7 @@ namespace Discord.WebSocket { if (_users.TryRemove(id, out SocketGroupUser user)) { - user.GlobalUser.RemoveRef(Discord); + user.GlobalUser.RemoveRef(Client); return user; } return null; @@ -281,13 +281,13 @@ namespace Discord.WebSocket } /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, null, Direction.Before, limit, mode, options); /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessageId, dir, limit, mode, options); /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessage.Id, dir, limit, mode, options); /// async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) => await GetPinnedMessagesAsync(options).ConfigureAwait(false); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index 18401c593..0348549d7 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -56,7 +56,7 @@ namespace Discord.WebSocket return SocketCategoryChannel.Create(guild, state, model); default: // TODO: Proper implementation for channel categories - return new SocketGuildChannel(guild.Discord, model.Id, guild); + return new SocketGuildChannel(guild.Client, model.Id, guild); } } /// @@ -74,10 +74,10 @@ namespace Discord.WebSocket /// public Task ModifyAsync(Action func, RequestOptions options = null) - => ChannelHelper.ModifyAsync(this, Discord, func, options); + => ChannelHelper.ModifyAsync(this, Client, func, options); /// public Task DeleteAsync(RequestOptions options = null) - => ChannelHelper.DeleteAsync(this, Discord, options); + => ChannelHelper.DeleteAsync(this, Client, options); /// /// Gets the permission overwrite for a specific user. @@ -123,7 +123,7 @@ namespace Discord.WebSocket /// public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null) { - await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, permissions, options).ConfigureAwait(false); + await ChannelHelper.AddPermissionOverwriteAsync(this, Client, user, permissions, options).ConfigureAwait(false); _overwrites = _overwrites.Add(new Overwrite(user.Id, PermissionTarget.User, new OverwritePermissions(permissions.AllowValue, permissions.DenyValue))); } @@ -138,7 +138,7 @@ namespace Discord.WebSocket /// public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null) { - await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, permissions, options).ConfigureAwait(false); + await ChannelHelper.AddPermissionOverwriteAsync(this, Client, role, permissions, options).ConfigureAwait(false); _overwrites = _overwrites.Add(new Overwrite(role.Id, PermissionTarget.Role, new OverwritePermissions(permissions.AllowValue, permissions.DenyValue))); } /// @@ -151,7 +151,7 @@ namespace Discord.WebSocket /// public async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) { - await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false); + await ChannelHelper.RemovePermissionOverwriteAsync(this, Client, user, options).ConfigureAwait(false); for (int i = 0; i < _overwrites.Length; i++) { @@ -172,7 +172,7 @@ namespace Discord.WebSocket /// public async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) { - await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false); + await ChannelHelper.RemovePermissionOverwriteAsync(this, Client, role, options).ConfigureAwait(false); for (int i = 0; i < _overwrites.Length; i++) { diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs index 496b96d30..9d02da072 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -34,7 +34,7 @@ namespace Discord.WebSocket => CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null; /// public Task SyncPermissionsAsync(RequestOptions options = null) - => ChannelHelper.SyncPermissionsAsync(this, Discord, options); + => ChannelHelper.SyncPermissionsAsync(this, Client, options); private bool _nsfw; /// @@ -53,12 +53,12 @@ namespace Discord.WebSocket internal SocketTextChannel(DiscordSocketClient discord, ulong id, SocketGuild guild) : base(discord, id, guild) { - if (Discord.MessageCacheSize > 0) - _messages = new MessageCache(Discord); + if (Client.MessageCacheSize > 0) + _messages = new MessageCache(Client); } internal new static SocketTextChannel Create(SocketGuild guild, ClientState state, Model model) { - var entity = new SocketTextChannel(guild.Discord, model.Id, guild); + var entity = new SocketTextChannel(guild.Client, model.Id, guild); entity.Update(state, model); return entity; } @@ -73,7 +73,7 @@ namespace Discord.WebSocket /// public Task ModifyAsync(Action func, RequestOptions options = null) - => ChannelHelper.ModifyAsync(this, Discord, func, options); + => ChannelHelper.ModifyAsync(this, Client, func, options); //Messages /// @@ -96,7 +96,7 @@ namespace Discord.WebSocket { IMessage msg = _messages?.Get(id); if (msg == null) - msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options).ConfigureAwait(false); + msg = await ChannelHelper.GetMessageAsync(this, Client, id, options).ConfigureAwait(false); return msg; } @@ -113,7 +113,7 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); /// /// Gets a collection of messages in this channel. /// @@ -129,7 +129,7 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload, options); /// /// Gets a collection of messages in this channel. /// @@ -145,54 +145,54 @@ namespace Discord.WebSocket /// Paged collection of messages. /// public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload, options); /// public IReadOnlyCollection GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, null, Direction.Before, limit); + => SocketChannelHelper.GetCachedMessages(this, Client, _messages, null, Direction.Before, limit); /// public IReadOnlyCollection GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessageId, dir, limit); + => SocketChannelHelper.GetCachedMessages(this, Client, _messages, fromMessageId, dir, limit); /// public IReadOnlyCollection GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessage.Id, dir, limit); + => SocketChannelHelper.GetCachedMessages(this, Client, _messages, fromMessage.Id, dir, limit); /// public Task> GetPinnedMessagesAsync(RequestOptions options = null) - => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); + => ChannelHelper.GetPinnedMessagesAsync(this, Client, options); /// /// Message content is too long, length must be less or equal to . public Task SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options); + => ChannelHelper.SendMessageAsync(this, Client, text, isTTS, embed, options); /// public Task SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, embed, options); + => ChannelHelper.SendFileAsync(this, Client, filePath, text, isTTS, embed, options); /// /// Message content is too long, length must be less or equal to . public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); + => ChannelHelper.SendFileAsync(this, Client, stream, filename, text, isTTS, embed, options); /// public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) - => ChannelHelper.DeleteMessagesAsync(this, Discord, messages.Select(x => x.Id), options); + => ChannelHelper.DeleteMessagesAsync(this, Client, messages.Select(x => x.Id), options); /// public Task DeleteMessagesAsync(IEnumerable messageIds, RequestOptions options = null) - => ChannelHelper.DeleteMessagesAsync(this, Discord, messageIds, options); + => ChannelHelper.DeleteMessagesAsync(this, Client, messageIds, options); /// public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) - => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); + => ChannelHelper.DeleteMessageAsync(this, messageId, Client, options); /// public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) - => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); + => ChannelHelper.DeleteMessageAsync(this, message.Id, Client, options); /// public Task TriggerTypingAsync(RequestOptions options = null) - => ChannelHelper.TriggerTypingAsync(this, Discord, options); + => ChannelHelper.TriggerTypingAsync(this, Client, options); /// public IDisposable EnterTypingState(RequestOptions options = null) - => ChannelHelper.EnterTypingState(this, Discord, options); + => ChannelHelper.EnterTypingState(this, Client, options); internal void AddMessage(SocketMessage msg) => _messages?.Add(msg); @@ -226,7 +226,7 @@ namespace Discord.WebSocket /// webhook. /// public Task CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) - => ChannelHelper.CreateWebhookAsync(this, Discord, name, avatar, options); + => ChannelHelper.CreateWebhookAsync(this, Client, name, avatar, options); /// /// Gets a webhook available in this text channel. /// @@ -237,7 +237,7 @@ namespace Discord.WebSocket /// with the identifier; null if the webhook is not found. /// public Task GetWebhookAsync(ulong id, RequestOptions options = null) - => ChannelHelper.GetWebhookAsync(this, Discord, id, options); + => ChannelHelper.GetWebhookAsync(this, Client, id, options); /// /// Gets the webhooks available in this text channel. /// @@ -247,15 +247,15 @@ namespace Discord.WebSocket /// of webhooks that is available in this channel. /// public Task> GetWebhooksAsync(RequestOptions options = null) - => ChannelHelper.GetWebhooksAsync(this, Discord, options); + => ChannelHelper.GetWebhooksAsync(this, Client, options); //Invites /// public async Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) - => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); + => await ChannelHelper.CreateInviteAsync(this, Client, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); /// public async Task> GetInvitesAsync(RequestOptions options = null) - => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); + => await ChannelHelper.GetInvitesAsync(this, Client, options).ConfigureAwait(false); private string DebuggerDisplay => $"{Name} ({Id}, Text)"; internal new SocketTextChannel Clone() => MemberwiseClone() as SocketTextChannel; @@ -290,13 +290,13 @@ namespace Discord.WebSocket } /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, null, Direction.Before, limit, mode, options); /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessageId, dir, limit, mode, options); /// IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode, options); + => SocketChannelHelper.GetMessagesAsync(this, Client, _messages, fromMessage.Id, dir, limit, mode, options); /// async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) => await GetPinnedMessagesAsync(options).ConfigureAwait(false); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs index 9fff6c207..411b5fc5e 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs @@ -32,7 +32,7 @@ namespace Discord.WebSocket => CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null; /// public Task SyncPermissionsAsync(RequestOptions options = null) - => ChannelHelper.SyncPermissionsAsync(this, Discord, options); + => ChannelHelper.SyncPermissionsAsync(this, Client, options); /// public override IReadOnlyCollection Users @@ -44,7 +44,7 @@ namespace Discord.WebSocket } internal new static SocketVoiceChannel Create(SocketGuild guild, ClientState state, Model model) { - var entity = new SocketVoiceChannel(guild.Discord, model.Id, guild); + var entity = new SocketVoiceChannel(guild.Client, model.Id, guild); entity.Update(state, model); return entity; } @@ -59,7 +59,7 @@ namespace Discord.WebSocket /// public Task ModifyAsync(Action func, RequestOptions options = null) - => ChannelHelper.ModifyAsync(this, Discord, func, options); + => ChannelHelper.ModifyAsync(this, Client, func, options); /// public async Task ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false) @@ -83,10 +83,10 @@ namespace Discord.WebSocket //Invites /// public async Task CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) - => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); + => await ChannelHelper.CreateInviteAsync(this, Client, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); /// public async Task> GetInvitesAsync(RequestOptions options = null) - => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); + => await ChannelHelper.GetInvitesAsync(this, Client, options).ConfigureAwait(false); private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; internal new SocketVoiceChannel Clone() => MemberwiseClone() as SocketVoiceChannel; diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index ca2db1a77..b4c62e20f 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -197,7 +197,7 @@ namespace Discord.WebSocket /// /// Gets the current logged-in user. /// - public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null; + public SocketGuildUser CurrentUser => _members.TryGetValue(Client.CurrentUser.Id, out SocketGuildUser member) ? member : null; /// /// Gets the built-in role containing all users in this guild. /// @@ -216,7 +216,7 @@ namespace Discord.WebSocket get { var channels = _channels; - var state = Discord.State; + var state = Client.State; return channels.Select(x => state.GetChannel(x) as SocketGuildChannel).Where(x => x != null).ToReadOnlyCollection(channels); } } @@ -416,27 +416,27 @@ namespace Discord.WebSocket //General /// public Task DeleteAsync(RequestOptions options = null) - => GuildHelper.DeleteAsync(this, Discord, options); + => GuildHelper.DeleteAsync(this, Client, options); /// /// is null. public Task ModifyAsync(Action func, RequestOptions options = null) - => GuildHelper.ModifyAsync(this, Discord, func, options); + => GuildHelper.ModifyAsync(this, Client, func, options); /// /// is null. public Task ModifyEmbedAsync(Action func, RequestOptions options = null) - => GuildHelper.ModifyEmbedAsync(this, Discord, func, options); + => GuildHelper.ModifyEmbedAsync(this, Client, func, options); /// public Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null) - => GuildHelper.ReorderChannelsAsync(this, Discord, args, options); + => GuildHelper.ReorderChannelsAsync(this, Client, args, options); /// public Task ReorderRolesAsync(IEnumerable args, RequestOptions options = null) - => GuildHelper.ReorderRolesAsync(this, Discord, args, options); + => GuildHelper.ReorderRolesAsync(this, Client, args, options); /// public Task LeaveAsync(RequestOptions options = null) - => GuildHelper.LeaveAsync(this, Discord, options); + => GuildHelper.LeaveAsync(this, Client, options); //Bans /// @@ -449,7 +449,7 @@ namespace Discord.WebSocket /// behind the ban. /// public Task> GetBansAsync(RequestOptions options = null) - => GuildHelper.GetBansAsync(this, Discord, options); + => GuildHelper.GetBansAsync(this, Client, options); /// /// Gets a ban object for a banned user. /// @@ -460,7 +460,7 @@ namespace Discord.WebSocket /// contains the user information and the reason for the ban; null if the ban entry cannot be found. /// public Task GetBanAsync(IUser user, RequestOptions options = null) - => GuildHelper.GetBanAsync(this, Discord, user.Id, options); + => GuildHelper.GetBanAsync(this, Client, user.Id, options); /// /// Gets a ban object for a banned user. /// @@ -471,21 +471,21 @@ namespace Discord.WebSocket /// contains the user information and the reason for the ban; null if the ban entry cannot be found. /// public Task GetBanAsync(ulong userId, RequestOptions options = null) - => GuildHelper.GetBanAsync(this, Discord, userId, options); + => GuildHelper.GetBanAsync(this, Client, userId, options); /// public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) - => GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options); + => GuildHelper.AddBanAsync(this, Client, user.Id, pruneDays, reason, options); /// public Task AddBanAsync(ulong userId, int pruneDays = 0, string reason = null, RequestOptions options = null) - => GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, reason, options); + => GuildHelper.AddBanAsync(this, Client, userId, pruneDays, reason, options); /// public Task RemoveBanAsync(IUser user, RequestOptions options = null) - => GuildHelper.RemoveBanAsync(this, Discord, user.Id, options); + => GuildHelper.RemoveBanAsync(this, Client, user.Id, options); /// public Task RemoveBanAsync(ulong userId, RequestOptions options = null) - => GuildHelper.RemoveBanAsync(this, Discord, userId, options); + => GuildHelper.RemoveBanAsync(this, Client, userId, options); //Channels /// @@ -497,7 +497,7 @@ namespace Discord.WebSocket /// public SocketGuildChannel GetChannel(ulong id) { - var channel = Discord.State.GetChannel(id) as SocketGuildChannel; + var channel = Client.State.GetChannel(id) as SocketGuildChannel; if (channel?.Guild.Id == Id) return channel; return null; @@ -545,7 +545,7 @@ namespace Discord.WebSocket /// text channel. /// public Task CreateTextChannelAsync(string name, Action func = null, RequestOptions options = null) - => GuildHelper.CreateTextChannelAsync(this, Discord, name, options, func); + => GuildHelper.CreateTextChannelAsync(this, Client, name, options, func); /// /// Creates a new voice channel in this guild. /// @@ -558,7 +558,7 @@ namespace Discord.WebSocket /// voice channel. /// public Task CreateVoiceChannelAsync(string name, Action func = null, RequestOptions options = null) - => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options, func); + => GuildHelper.CreateVoiceChannelAsync(this, Client, name, options, func); /// /// Creates a new channel category in this guild. /// @@ -571,7 +571,7 @@ namespace Discord.WebSocket /// category channel. /// public Task CreateCategoryChannelAsync(string name, Action func = null, RequestOptions options = null) - => GuildHelper.CreateCategoryChannelAsync(this, Discord, name, options, func); + => GuildHelper.CreateCategoryChannelAsync(this, Client, name, options, func); internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) { @@ -597,13 +597,13 @@ namespace Discord.WebSocket /// voice regions the guild can access. /// public Task> GetVoiceRegionsAsync(RequestOptions options = null) - => GuildHelper.GetVoiceRegionsAsync(this, Discord, options); + => GuildHelper.GetVoiceRegionsAsync(this, Client, options); //Integrations public Task> GetIntegrationsAsync(RequestOptions options = null) - => GuildHelper.GetIntegrationsAsync(this, Discord, options); + => GuildHelper.GetIntegrationsAsync(this, Client, options); public Task CreateIntegrationAsync(ulong id, string type, RequestOptions options = null) - => GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options); + => GuildHelper.CreateIntegrationAsync(this, Client, id, type, options); //Invites /// @@ -615,7 +615,7 @@ namespace Discord.WebSocket /// invite metadata, each representing information for an invite found within this guild. /// public Task> GetInvitesAsync(RequestOptions options = null) - => GuildHelper.GetInvitesAsync(this, Discord, options); + => GuildHelper.GetInvitesAsync(this, Client, options); /// /// Gets the vanity invite URL of this guild. /// @@ -625,7 +625,7 @@ namespace Discord.WebSocket /// the vanity invite found within this guild; null if none is found. /// public Task GetVanityInviteAsync(RequestOptions options = null) - => GuildHelper.GetVanityInviteAsync(this, Discord, options); + => GuildHelper.GetVanityInviteAsync(this, Client, options); //Roles /// @@ -657,10 +657,10 @@ namespace Discord.WebSocket /// public Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), bool isHoisted = false, RequestOptions options = null) - => GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options); + => GuildHelper.CreateRoleAsync(this, Client, name, permissions, color, isHoisted, options); internal SocketRole AddRole(RoleModel model) { - var role = SocketRole.Create(this, Discord.State, model); + var role = SocketRole.Create(this, Client.State, model); _roles[model.Id] = role; return role; } @@ -674,7 +674,7 @@ namespace Discord.WebSocket //Users /// public Task AddGuildUserAsync(ulong id, string accessToken, Action func = null, RequestOptions options = null) - => GuildHelper.AddGuildUserAsync(this, Discord, id, accessToken, func, options); + => GuildHelper.AddGuildUserAsync(this, Client, id, accessToken, func, options); /// /// Gets a user from this guild. @@ -698,15 +698,15 @@ namespace Discord.WebSocket } /// public Task PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null) - => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); + => GuildHelper.PruneUsersAsync(this, Client, days, simulate, options); internal SocketGuildUser AddOrUpdateUser(UserModel model) { if (_members.TryGetValue(model.Id, out SocketGuildUser member)) - member.GlobalUser?.Update(Discord.State, model); + member.GlobalUser?.Update(Client.State, model); else { - member = SocketGuildUser.Create(this, Discord.State, model); + member = SocketGuildUser.Create(this, Client.State, model); member.GlobalUser.AddRef(); _members[member.Id] = member; DownloadedMemberCount++; @@ -716,10 +716,10 @@ namespace Discord.WebSocket internal SocketGuildUser AddOrUpdateUser(MemberModel model) { if (_members.TryGetValue(model.User.Id, out SocketGuildUser member)) - member.Update(Discord.State, model); + member.Update(Client.State, model); else { - member = SocketGuildUser.Create(this, Discord.State, model); + member = SocketGuildUser.Create(this, Client.State, model); member.GlobalUser.AddRef(); _members[member.Id] = member; DownloadedMemberCount++; @@ -729,10 +729,10 @@ namespace Discord.WebSocket internal SocketGuildUser AddOrUpdateUser(PresenceModel model) { if (_members.TryGetValue(model.User.Id, out SocketGuildUser member)) - member.Update(Discord.State, model, false); + member.Update(Client.State, model, false); else { - member = SocketGuildUser.Create(this, Discord.State, model); + member = SocketGuildUser.Create(this, Client.State, model); member.GlobalUser.AddRef(); _members[member.Id] = member; DownloadedMemberCount++; @@ -744,7 +744,7 @@ namespace Discord.WebSocket if (_members.TryRemove(id, out SocketGuildUser member)) { DownloadedMemberCount--; - member.GlobalUser.RemoveRef(Discord); + member.GlobalUser.RemoveRef(Client); return member; } return null; @@ -753,7 +753,7 @@ namespace Discord.WebSocket /// public async Task DownloadUsersAsync() { - await Discord.DownloadUsersAsync(new[] { this }).ConfigureAwait(false); + await Client.DownloadUsersAsync(new[] { this }).ConfigureAwait(false); } internal void CompleteDownloadUsers() { @@ -771,7 +771,7 @@ namespace Discord.WebSocket /// of the requested audit log entries. /// public IAsyncEnumerable> GetAuditLogsAsync(int limit, RequestOptions options = null) - => GuildHelper.GetAuditLogsAsync(this, Discord, null, limit, options); + => GuildHelper.GetAuditLogsAsync(this, Client, null, limit, options); //Webhooks /// @@ -784,7 +784,7 @@ namespace Discord.WebSocket /// specified ; null if none is found. /// public Task GetWebhookAsync(ulong id, RequestOptions options = null) - => GuildHelper.GetWebhookAsync(this, Discord, id, options); + => GuildHelper.GetWebhookAsync(this, Client, id, options); /// /// Gets a collection of all webhook from this guild. /// @@ -794,22 +794,22 @@ namespace Discord.WebSocket /// of webhooks found within the guild. /// public Task> GetWebhooksAsync(RequestOptions options = null) - => GuildHelper.GetWebhooksAsync(this, Discord, options); + => GuildHelper.GetWebhooksAsync(this, Client, options); //Emotes /// public Task GetEmoteAsync(ulong id, RequestOptions options = null) - => GuildHelper.GetEmoteAsync(this, Discord, id, options); + => GuildHelper.GetEmoteAsync(this, Client, id, options); /// public Task CreateEmoteAsync(string name, Image image, Optional> roles = default(Optional>), RequestOptions options = null) - => GuildHelper.CreateEmoteAsync(this, Discord, name, image, roles, options); + => GuildHelper.CreateEmoteAsync(this, Client, name, image, roles, options); /// /// is null. public Task ModifyEmoteAsync(GuildEmote emote, Action func, RequestOptions options = null) - => GuildHelper.ModifyEmoteAsync(this, Discord, emote.Id, func, options); + => GuildHelper.ModifyEmoteAsync(this, Client, emote.Id, func, options); /// public Task DeleteEmoteAsync(GuildEmote emote, RequestOptions options = null) - => GuildHelper.DeleteEmoteAsync(this, Discord, emote.Id, options); + => GuildHelper.DeleteEmoteAsync(this, Client, emote.Id, options); //Voice States internal async Task AddOrUpdateVoiceStateAsync(ClientState state, VoiceStateModel model) @@ -876,14 +876,14 @@ namespace Discord.WebSocket { #pragma warning disable IDISP001 var _ = promise.TrySetResultAsync(null); - await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false); + await Client.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false); return null; #pragma warning restore IDISP001 } if (_audioClient == null) { - var audioClient = new AudioClient(this, Discord.GetAudioId(), channelId); + var audioClient = new AudioClient(this, Client.GetAudioId(), channelId); audioClient.Disconnected += async ex => { if (!promise.Task.IsCompleted) @@ -911,7 +911,7 @@ namespace Discord.WebSocket #pragma warning restore IDISP003 } - await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false); + await Client.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false); } catch { @@ -955,14 +955,14 @@ namespace Discord.WebSocket _audioConnectPromise = null; if (_audioClient != null) await _audioClient.StopAsync().ConfigureAwait(false); - await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, null, false, false).ConfigureAwait(false); + await Client.ApiClient.SendVoiceStateUpdateAsync(Id, null, false, false).ConfigureAwait(false); _audioClient?.Dispose(); _audioClient = null; } internal async Task FinishConnectAudio(string url, string token) { //TODO: Mem Leak: Disconnected/Connected handlers arent cleaned up - var voiceState = GetVoiceState(Discord.CurrentUser.Id).Value; + var voiceState = GetVoiceState(Client.CurrentUser.Id).Value; await _audioLock.WaitAsync().ConfigureAwait(false); try @@ -970,7 +970,7 @@ namespace Discord.WebSocket if (_audioClient != null) { await RepopulateAudioStreamsAsync().ConfigureAwait(false); - await _audioClient.StartAsync(url, Discord.CurrentUser.Id, voiceState.VoiceSessionId, token).ConfigureAwait(false); + await _audioClient.StartAsync(url, Client.CurrentUser.Id, voiceState.VoiceSessionId, token).ConfigureAwait(false); } } catch (OperationCanceledException) diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs index 2cfcee270..307711bec 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs @@ -139,7 +139,7 @@ namespace Discord.WebSocket /// public Task DeleteAsync(RequestOptions options = null) - => MessageHelper.DeleteAsync(this, Discord, options); + => MessageHelper.DeleteAsync(this, Client, options); /// /// Gets the content of the message. diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs index 97754da56..79816747d 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs @@ -41,7 +41,7 @@ namespace Discord.WebSocket /// public override IReadOnlyCollection MentionedUsers => MessageHelper.FilterTagsByValue(TagType.UserMention, _tags); /// - public IReadOnlyDictionary Reactions => _reactions.GroupBy(r => r.Emote).ToDictionary(x => x.Key, x => new ReactionMetadata { ReactionCount = x.Count(), IsMe = x.Any(y => y.UserId == Discord.CurrentUser.Id) }); + public IReadOnlyDictionary Reactions => _reactions.GroupBy(r => r.Emote).ToDictionary(x => x.Key, x => new ReactionMetadata { ReactionCount = x.Count(), IsMe = x.Any(y => y.UserId == Client.CurrentUser.Id) }); internal SocketUserMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author, MessageSource source) : base(discord, id, channel, author, source) @@ -106,7 +106,7 @@ namespace Discord.WebSocket { var val = value[i]; if (val.Object != null) - newMentions.Add(SocketUnknownUser.Create(Discord, state, val.Object)); + newMentions.Add(SocketUnknownUser.Create(Client, state, val.Object)); } mentions = newMentions.ToImmutable(); } @@ -138,27 +138,27 @@ namespace Discord.WebSocket /// Only the author of a message may modify the message. /// Message content is too long, length must be less or equal to . public Task ModifyAsync(Action func, RequestOptions options = null) - => MessageHelper.ModifyAsync(this, Discord, func, options); + => MessageHelper.ModifyAsync(this, Client, func, options); /// public Task AddReactionAsync(IEmote emote, RequestOptions options = null) - => MessageHelper.AddReactionAsync(this, emote, Discord, options); + => MessageHelper.AddReactionAsync(this, emote, Client, options); /// public Task RemoveReactionAsync(IEmote emote, IUser user, RequestOptions options = null) - => MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options); + => MessageHelper.RemoveReactionAsync(this, user, emote, Client, options); /// public Task RemoveAllReactionsAsync(RequestOptions options = null) - => MessageHelper.RemoveAllReactionsAsync(this, Discord, options); + => MessageHelper.RemoveAllReactionsAsync(this, Client, options); /// public IAsyncEnumerable> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null) - => MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options); + => MessageHelper.GetReactionUsersAsync(this, emote, limit, Client, options); /// public Task PinAsync(RequestOptions options = null) - => MessageHelper.PinAsync(this, Discord, options); + => MessageHelper.PinAsync(this, Client, options); /// public Task UnpinAsync(RequestOptions options = null) - => MessageHelper.UnpinAsync(this, Discord, options); + => MessageHelper.UnpinAsync(this, Client, options); public string Resolve(int startIndex, TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name, TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name) diff --git a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs index b5e26ad78..230ba0ecf 100644 --- a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs +++ b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs @@ -52,7 +52,7 @@ namespace Discord.WebSocket => Guild.Users.Where(x => x.Roles.Any(r => r.Id == Id)); internal SocketRole(SocketGuild guild, ulong id) - : base(guild.Discord, id) + : base(guild.Client, id) { Guild = guild; } @@ -75,10 +75,10 @@ namespace Discord.WebSocket /// public Task ModifyAsync(Action func, RequestOptions options = null) - => RoleHelper.ModifyAsync(this, Discord, func, options); + => RoleHelper.ModifyAsync(this, Client, func, options); /// public Task DeleteAsync(RequestOptions options = null) - => RoleHelper.DeleteAsync(this, Discord, options); + => RoleHelper.DeleteAsync(this, Client, options); /// /// Gets the name of the role. diff --git a/src/Discord.Net.WebSocket/Entities/SocketEntity.cs b/src/Discord.Net.WebSocket/Entities/SocketEntity.cs index f76694e6f..0c80a2d5d 100644 --- a/src/Discord.Net.WebSocket/Entities/SocketEntity.cs +++ b/src/Discord.Net.WebSocket/Entities/SocketEntity.cs @@ -5,13 +5,13 @@ namespace Discord.WebSocket public abstract class SocketEntity : IEntity where T : IEquatable { - internal DiscordSocketClient Discord { get; } + public DiscordSocketClient Client { get; } /// public T Id { get; } internal SocketEntity(DiscordSocketClient discord, T id) { - Discord = discord; + Client = discord; Id = id; } } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs index f560aadbb..53b677d99 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs @@ -31,14 +31,14 @@ namespace Discord.WebSocket public override bool IsWebhook => false; internal SocketGroupUser(SocketGroupChannel channel, SocketGlobalUser globalUser) - : base(channel.Discord, globalUser.Id) + : base(channel.Client, globalUser.Id) { Channel = channel; GlobalUser = globalUser; } internal static SocketGroupUser Create(SocketGroupChannel channel, ClientState state, Model model) { - var entity = new SocketGroupUser(channel, channel.Discord.GetOrCreateUser(state, model)); + var entity = new SocketGroupUser(channel, channel.Client.GetOrCreateUser(state, model)); entity.Update(state, model); return entity; } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs index 659a2eeea..85736b617 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs @@ -102,27 +102,27 @@ namespace Discord.WebSocket } internal SocketGuildUser(SocketGuild guild, SocketGlobalUser globalUser) - : base(guild.Discord, globalUser.Id) + : base(guild.Client, globalUser.Id) { Guild = guild; GlobalUser = globalUser; } internal static SocketGuildUser Create(SocketGuild guild, ClientState state, UserModel model) { - var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model)); + var entity = new SocketGuildUser(guild, guild.Client.GetOrCreateUser(state, model)); entity.Update(state, model); entity.UpdateRoles(new ulong[0]); return entity; } internal static SocketGuildUser Create(SocketGuild guild, ClientState state, MemberModel model) { - var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User)); + var entity = new SocketGuildUser(guild, guild.Client.GetOrCreateUser(state, model.User)); entity.Update(state, model); return entity; } internal static SocketGuildUser Create(SocketGuild guild, ClientState state, PresenceModel model) { - var entity = new SocketGuildUser(guild, guild.Discord.GetOrCreateUser(state, model.User)); + var entity = new SocketGuildUser(guild, guild.Client.GetOrCreateUser(state, model.User)); entity.Update(state, model, false); return entity; } @@ -159,22 +159,22 @@ namespace Discord.WebSocket /// public Task ModifyAsync(Action func, RequestOptions options = null) - => UserHelper.ModifyAsync(this, Discord, func, options); + => UserHelper.ModifyAsync(this, Client, func, options); /// public Task KickAsync(string reason = null, RequestOptions options = null) - => UserHelper.KickAsync(this, Discord, reason, options); + => UserHelper.KickAsync(this, Client, reason, options); /// public Task AddRoleAsync(IRole role, RequestOptions options = null) => AddRolesAsync(new[] { role }, options); /// public Task AddRolesAsync(IEnumerable roles, RequestOptions options = null) - => UserHelper.AddRolesAsync(this, Discord, roles, options); + => UserHelper.AddRolesAsync(this, Client, roles, options); /// public Task RemoveRoleAsync(IRole role, RequestOptions options = null) => RemoveRolesAsync(new[] { role }, options); /// public Task RemoveRolesAsync(IEnumerable roles, RequestOptions options = null) - => UserHelper.RemoveRolesAsync(this, Discord, roles, options); + => UserHelper.RemoveRolesAsync(this, Client, roles, options); /// public ChannelPermissions GetPermissions(IGuildChannel channel) diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs index ae705109c..f3d04870e 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs @@ -68,7 +68,7 @@ namespace Discord.WebSocket /// public Task ModifyAsync(Action func, RequestOptions options = null) - => UserHelper.ModifyAsync(this, Discord, func, options); + => UserHelper.ModifyAsync(this, Client, func, options); private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Self)"; internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser; diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 4832e7311..4be88648f 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -42,7 +42,7 @@ namespace Discord.WebSocket /// Gets mutual guilds shared with this user. /// public IReadOnlyCollection MutualGuilds - => Discord.Guilds.Where(g => g.Users.Any(u => u.Id == Id)).ToImmutableArray(); + => Client.Guilds.Where(g => g.Users.Any(u => u.Id == Id)).ToImmutableArray(); internal SocketUser(DiscordSocketClient discord, ulong id) : base(discord, id) @@ -80,7 +80,7 @@ namespace Discord.WebSocket /// public async Task GetOrCreateDMChannelAsync(RequestOptions options = null) - => GlobalUser.DMChannel ?? await UserHelper.CreateDMChannelAsync(this, Discord, options).ConfigureAwait(false) as IDMChannel; + => GlobalUser.DMChannel ?? await UserHelper.CreateDMChannelAsync(this, Client, options).ConfigureAwait(false) as IDMChannel; /// public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs index 3169be682..1c252a7ba 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs @@ -35,7 +35,7 @@ namespace Discord.WebSocket throw new NotSupportedException(); internal SocketWebhookUser(SocketGuild guild, ulong id, ulong webhookId) - : base(guild.Discord, id) + : base(guild.Client, id) { Guild = guild; WebhookId = webhookId;