From f41df1f96694a3780cfd4b280240acce70cf8c9f Mon Sep 17 00:00:00 2001 From: RogueException Date: Thu, 6 Oct 2016 02:44:41 -0300 Subject: [PATCH] Exposed RequestOptions --- .../Entities/Channels/IChannel.cs | 4 +- .../Entities/Channels/IDMChannel.cs | 2 +- .../Entities/Channels/IGroupChannel.cs | 2 +- .../Entities/Channels/IGuildChannel.cs | 18 +-- .../Entities/Channels/IMessageChannel.cs | 23 +-- .../Entities/Channels/ITextChannel.cs | 2 +- .../Entities/Channels/IVoiceChannel.cs | 2 +- .../Entities/Guilds/IGuild.cs | 44 ++--- src/Discord.Net.Core/Entities/IDeletable.cs | 2 +- src/Discord.Net.Core/Entities/IUpdateable.cs | 2 +- .../Entities/Invites/IInvite.cs | 2 +- .../Entities/Messages/IUserMessage.cs | 6 +- src/Discord.Net.Core/Entities/Roles/IRole.cs | 8 +- .../Entities/Users/IGroupUser.cs | 2 +- .../Entities/Users/IGuildUser.cs | 4 +- .../Entities/Users/ISelfUser.cs | 4 +- src/Discord.Net.Core/Entities/Users/IUser.cs | 4 +- .../Entities/Channels/ChannelHelper.cs | 97 ++++++----- .../Entities/Channels/IRestMessageChannel.cs | 16 +- .../Entities/Channels/RestChannel.cs | 6 +- .../Entities/Channels/RestDMChannel.cs | 98 ++++++------ .../Entities/Channels/RestGroupChannel.cs | 103 ++++++------ .../Entities/Channels/RestGuildChannel.cs | 71 +++++---- .../Entities/Channels/RestTextChannel.cs | 96 +++++------ .../Entities/Channels/RestVoiceChannel.cs | 8 +- .../Entities/Guilds/GuildHelper.cs | 95 ++++++----- .../Entities/Guilds/RestGuild.cs | 150 +++++++++--------- .../Entities/Guilds/RestUserGuild.cs | 8 +- .../Entities/Invites/InviteHelper.cs | 14 +- .../Entities/Invites/RestInvite.cs | 17 +- .../Entities/Messages/MessageHelper.cs | 24 +-- .../Entities/Messages/RestMessage.cs | 4 +- .../Entities/Messages/RestUserMessage.cs | 16 +- .../Entities/Roles/RestRole.cs | 8 +- .../Entities/Roles/RoleHelper.cs | 9 +- .../Entities/Users/RestGuildUser.cs | 17 +- .../Entities/Users/RestSelfUser.cs | 20 ++- .../Entities/Users/RestUser.cs | 19 ++- .../Entities/Users/UserHelper.cs | 40 ++--- src/Discord.Net.Rest/Utils/TypingNotifier.cs | 4 +- .../Channels/ISocketMessageChannel.cs | 8 +- .../Entities/Channels/SocketChannel.cs | 4 +- .../Entities/Channels/SocketChannelHelper.cs | 4 +- .../Entities/Channels/SocketDMChannel.cs | 86 +++++----- .../Entities/Channels/SocketGroupChannel.cs | 85 +++++----- .../Entities/Channels/SocketGuildChannel.cs | 64 ++++---- .../Entities/Channels/SocketTextChannel.cs | 84 +++++----- .../Entities/Channels/SocketVoiceChannel.cs | 8 +- .../Entities/Guilds/SocketGuild.cs | 111 ++++++------- .../Entities/Messages/SocketUserMessage.cs | 18 +-- .../Entities/Roles/SocketRole.cs | 8 +- .../Entities/Users/SocketGuildUser.cs | 10 +- .../Entities/Users/SocketPresence.cs | 8 +- .../Entities/Users/SocketUser.cs | 10 +- 54 files changed, 803 insertions(+), 776 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Channels/IChannel.cs b/src/Discord.Net.Core/Entities/Channels/IChannel.cs index 6302e993c..97e58355c 100644 --- a/src/Discord.Net.Core/Entities/Channels/IChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IChannel.cs @@ -6,9 +6,9 @@ namespace Discord public interface IChannel : ISnowflakeEntity { /// Gets a collection of all users in this channel. - IAsyncEnumerable> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload); + IAsyncEnumerable> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Gets a user in this channel with the provided id. - Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); + Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Channels/IDMChannel.cs b/src/Discord.Net.Core/Entities/Channels/IDMChannel.cs index a5a3a4168..1608d1543 100644 --- a/src/Discord.Net.Core/Entities/Channels/IDMChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IDMChannel.cs @@ -8,6 +8,6 @@ namespace Discord IUser Recipient { get; } /// Closes this private channel, removing it from your channel list. - Task CloseAsync(); + Task CloseAsync(RequestOptions options = null); } } \ No newline at end of file diff --git a/src/Discord.Net.Core/Entities/Channels/IGroupChannel.cs b/src/Discord.Net.Core/Entities/Channels/IGroupChannel.cs index 23f5b4784..d6cb2c182 100644 --- a/src/Discord.Net.Core/Entities/Channels/IGroupChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IGroupChannel.cs @@ -5,6 +5,6 @@ namespace Discord public interface IGroupChannel : IMessageChannel, IPrivateChannel, IAudioChannel { /// Leaves this group. - Task LeaveAsync(); + Task LeaveAsync(RequestOptions options = null); } } \ No newline at end of file diff --git a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs index 085771fbf..bb9f39c71 100644 --- a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs @@ -21,29 +21,29 @@ namespace Discord /// The time (in seconds) until the invite expires. Set to null to never expire. /// The max amount of times this invite may be used. Set to null to have unlimited uses. /// If true, a user accepting this invite will be kicked from the guild after closing their client. - Task CreateInviteAsync(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false); + Task CreateInviteAsync(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, RequestOptions options = null); /// Returns a collection of all invites to this channel. - Task> GetInvitesAsync(); + Task> GetInvitesAsync(RequestOptions options = null); /// Modifies this guild channel. - Task ModifyAsync(Action func); + Task ModifyAsync(Action func, RequestOptions options = null); /// Gets the permission overwrite for a specific role, or null if one does not exist. OverwritePermissions? GetPermissionOverwrite(IRole role); /// Gets the permission overwrite for a specific user, or null if one does not exist. OverwritePermissions? GetPermissionOverwrite(IUser user); /// Removes the permission overwrite for the given role, if one exists. - Task RemovePermissionOverwriteAsync(IRole role); + Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null); /// Removes the permission overwrite for the given user, if one exists. - Task RemovePermissionOverwriteAsync(IUser user); + Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null); /// Adds or updates the permission overwrite for the given role. - Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions); + Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null); /// Adds or updates the permission overwrite for the given user. - Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions); + Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null); /// Gets a collection of all users in this channel. - new IAsyncEnumerable> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload); + new IAsyncEnumerable> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Gets a user in this channel with the provided id. - new Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); + new Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); } } \ No newline at end of file diff --git a/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs b/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs index 2fa09cd08..77ed811eb 100644 --- a/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs @@ -8,26 +8,29 @@ namespace Discord public interface IMessageChannel : IChannel { /// Sends a message to this message channel. - Task SendMessageAsync(string text, bool isTTS = false); + Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. - Task SendFileAsync(string filePath, string text = null, bool isTTS = false); + Task SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. - Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false); + Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, RequestOptions options = null); /// Gets a message from this message channel with the given id, or null if not found. - Task GetMessageAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); + Task GetMessageAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Gets the last N messages from this message channel. - IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, CacheMode mode = CacheMode.AllowDownload); + IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, + CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Gets a collection of messages in this channel. - IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, CacheMode mode = CacheMode.AllowDownload); + IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, + CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Gets a collection of messages in this channel. - IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, CacheMode mode = CacheMode.AllowDownload); + IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, + CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Gets a collection of pinned messages in this channel. - Task> GetPinnedMessagesAsync(); + Task> GetPinnedMessagesAsync(RequestOptions options = null); /// Bulk deletes multiple messages. - Task DeleteMessagesAsync(IEnumerable messages); + Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null); /// Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds. - IDisposable EnterTypingState(); + IDisposable EnterTypingState(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs index 3b4248b6e..7ecaf6d7b 100644 --- a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs @@ -10,6 +10,6 @@ namespace Discord string Topic { get; } /// Modifies this text channel. - Task ModifyAsync(Action func); + Task ModifyAsync(Action func, RequestOptions options = null); } } \ No newline at end of file diff --git a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs index 75f6a0190..d1be73072 100644 --- a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs @@ -13,7 +13,7 @@ namespace Discord int UserLimit { get; } /// Modifies this voice channel. - Task ModifyAsync(Action func); + Task ModifyAsync(Action func, RequestOptions options = null); /// Connects to this voice channel. Task ConnectAsync(); } diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index f1b1da6a1..2ff7afa3f 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -53,56 +53,56 @@ namespace Discord IReadOnlyCollection Roles { get; } /// Modifies this guild. - Task ModifyAsync(Action func); + Task ModifyAsync(Action func, RequestOptions options = null); /// Modifies this guild's embed. - Task ModifyEmbedAsync(Action func); + Task ModifyEmbedAsync(Action func, RequestOptions options = null); /// Bulk modifies the channels of this guild. - Task ModifyChannelsAsync(IEnumerable args); + Task ModifyChannelsAsync(IEnumerable args, RequestOptions options = null); /// Bulk modifies the roles of this guild. - Task ModifyRolesAsync(IEnumerable args); + Task ModifyRolesAsync(IEnumerable args, RequestOptions options = null); /// Leaves this guild. If you are the owner, use Delete instead. - Task LeaveAsync(); + Task LeaveAsync(RequestOptions options = null); /// Gets a collection of all users banned on this guild. - Task> GetBansAsync(); + Task> GetBansAsync(RequestOptions options = null); /// Bans the provided user from this guild and optionally prunes their recent messages. - Task AddBanAsync(IUser user, int pruneDays = 0); + Task AddBanAsync(IUser user, int pruneDays = 0, RequestOptions options = null); /// Bans the provided user id from this guild and optionally prunes their recent messages. - Task AddBanAsync(ulong userId, int pruneDays = 0); + Task AddBanAsync(ulong userId, int pruneDays = 0, RequestOptions options = null); /// Unbans the provided user if it is currently banned. - Task RemoveBanAsync(IUser user); + Task RemoveBanAsync(IUser user, RequestOptions options = null); /// Unbans the provided user id if it is currently banned. - Task RemoveBanAsync(ulong userId); + Task RemoveBanAsync(ulong userId, RequestOptions options = null); /// Gets a collection of all channels in this guild. - Task> GetChannelsAsync(CacheMode mode = CacheMode.AllowDownload); + Task> GetChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Gets the channel in this guild with the provided id, or null if not found. - Task GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); + Task GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Creates a new text channel. - Task CreateTextChannelAsync(string name); + Task CreateTextChannelAsync(string name, RequestOptions options = null); /// Creates a new voice channel. - Task CreateVoiceChannelAsync(string name); + Task CreateVoiceChannelAsync(string name, RequestOptions options = null); - Task> GetIntegrationsAsync(); - Task CreateIntegrationAsync(ulong id, string type); + Task> GetIntegrationsAsync(RequestOptions options = null); + Task CreateIntegrationAsync(ulong id, string type, RequestOptions options = null); /// Gets a collection of all invites to this guild. - Task> GetInvitesAsync(); + Task> GetInvitesAsync(RequestOptions options = null); /// Gets the role in this guild with the provided id, or null if not found. IRole GetRole(ulong id); /// Creates a new role. - Task CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false); + Task CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false, RequestOptions options = null); /// Gets a collection of all users in this guild. - Task> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload); //TODO: shouldnt this be paged? + Task> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); //TODO: shouldnt this be paged? /// Gets the user in this guild with the provided id, or null if not found. - Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); + Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Gets the current user for this guild. - Task GetCurrentUserAsync(CacheMode mode = CacheMode.AllowDownload); + Task GetCurrentUserAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Downloads all users for this guild if the current list is incomplete. Task DownloadUsersAsync(); /// Removes all users from this guild if they have not logged on in a provided number of days or, if simulate is true, returns the number of users that would be removed. - Task PruneUsersAsync(int days = 30, bool simulate = false); + Task PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null); } } \ No newline at end of file diff --git a/src/Discord.Net.Core/Entities/IDeletable.cs b/src/Discord.Net.Core/Entities/IDeletable.cs index f35f8ad88..ba22a537a 100644 --- a/src/Discord.Net.Core/Entities/IDeletable.cs +++ b/src/Discord.Net.Core/Entities/IDeletable.cs @@ -5,6 +5,6 @@ namespace Discord public interface IDeletable { /// Deletes this object and all its children. - Task DeleteAsync(); + Task DeleteAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/IUpdateable.cs b/src/Discord.Net.Core/Entities/IUpdateable.cs index 50b23bb95..b0f51aee7 100644 --- a/src/Discord.Net.Core/Entities/IUpdateable.cs +++ b/src/Discord.Net.Core/Entities/IUpdateable.cs @@ -5,6 +5,6 @@ namespace Discord public interface IUpdateable { /// Updates this object's properties with its current state. - Task UpdateAsync(); + Task UpdateAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Invites/IInvite.cs b/src/Discord.Net.Core/Entities/Invites/IInvite.cs index 5e5ca40ae..081b57d76 100644 --- a/src/Discord.Net.Core/Entities/Invites/IInvite.cs +++ b/src/Discord.Net.Core/Entities/Invites/IInvite.cs @@ -15,6 +15,6 @@ namespace Discord ulong GuildId { get; } /// Accepts this invite and joins the target guild. This will fail on bot accounts. - Task AcceptAsync(); + Task AcceptAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs b/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs index fd170dacb..3faa31419 100644 --- a/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs +++ b/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs @@ -7,11 +7,11 @@ namespace Discord public interface IUserMessage : IMessage, IDeletable { /// Modifies this message. - Task ModifyAsync(Action func); + Task ModifyAsync(Action func, RequestOptions options = null); /// Adds this message to its channel's pinned messages. - Task PinAsync(); + Task PinAsync(RequestOptions options = null); /// Removes this message from its channel's pinned messages. - Task UnpinAsync(); + Task UnpinAsync(RequestOptions options = null); /// Transforms this message's text into a human readable form, resolving mentions to that object's name. string Resolve(int startIndex, int length, diff --git a/src/Discord.Net.Core/Entities/Roles/IRole.cs b/src/Discord.Net.Core/Entities/Roles/IRole.cs index bcea9b17e..d7de45b88 100644 --- a/src/Discord.Net.Core/Entities/Roles/IRole.cs +++ b/src/Discord.Net.Core/Entities/Roles/IRole.cs @@ -1,4 +1,8 @@ -namespace Discord +using Discord.API.Rest; +using System; +using System.Threading.Tasks; + +namespace Discord { public interface IRole : ISnowflakeEntity, IDeletable, IMentionable { @@ -19,6 +23,6 @@ int Position { get; } ///// Modifies this role. - //Task ModifyAsync(Action func); + Task ModifyAsync(Action func, RequestOptions options = null); } } \ No newline at end of file diff --git a/src/Discord.Net.Core/Entities/Users/IGroupUser.cs b/src/Discord.Net.Core/Entities/Users/IGroupUser.cs index 3d18b7cd2..dd046a5a8 100644 --- a/src/Discord.Net.Core/Entities/Users/IGroupUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IGroupUser.cs @@ -3,6 +3,6 @@ public interface IGroupUser : IUser, IVoiceState { ///// Kicks this user from this group. - //Task KickAsync(); + //Task KickAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Users/IGuildUser.cs b/src/Discord.Net.Core/Entities/Users/IGuildUser.cs index 72cbabb30..7763a14ae 100644 --- a/src/Discord.Net.Core/Entities/Users/IGuildUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IGuildUser.cs @@ -23,8 +23,8 @@ namespace Discord ChannelPermissions GetPermissions(IGuildChannel channel); /// Kicks this user from this guild. - Task KickAsync(); + Task KickAsync(RequestOptions options = null); /// Modifies this user's properties in this guild. - Task ModifyAsync(Action func); + Task ModifyAsync(Action func, RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Users/ISelfUser.cs b/src/Discord.Net.Core/Entities/Users/ISelfUser.cs index dea95b566..a6e8f80e8 100644 --- a/src/Discord.Net.Core/Entities/Users/ISelfUser.cs +++ b/src/Discord.Net.Core/Entities/Users/ISelfUser.cs @@ -13,7 +13,7 @@ namespace Discord /// Returns true if this user has enabled MFA on their account. bool IsMfaEnabled { get; } - Task ModifyAsync(Action func); - Task ModifyStatusAsync(Action func); + Task ModifyAsync(Action func, RequestOptions options = null); + Task ModifyStatusAsync(Action func, RequestOptions options = null); } } \ No newline at end of file diff --git a/src/Discord.Net.Core/Entities/Users/IUser.cs b/src/Discord.Net.Core/Entities/Users/IUser.cs index 43f441e7e..c02f8aeca 100644 --- a/src/Discord.Net.Core/Entities/Users/IUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IUser.cs @@ -18,8 +18,8 @@ namespace Discord string Username { get; } /// Returns a private message channel to this user, creating one if it does not already exist. - Task GetDMChannelAsync(CacheMode mode = CacheMode.AllowDownload); + Task GetDMChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Returns a private message channel to this user, creating one if it does not already exist. - Task CreateDMChannelAsync(); + Task CreateDMChannelAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index 37c7ed6dd..319520386 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -12,67 +12,64 @@ namespace Discord.Rest internal static class ChannelHelper { //General - public static async Task GetAsync(IGuildChannel channel, BaseDiscordClient client) - { - return await client.ApiClient.GetChannelAsync(channel.GuildId, channel.Id).ConfigureAwait(false); - } - public static async Task GetAsync(IPrivateChannel channel, BaseDiscordClient client) - { - return await client.ApiClient.GetChannelAsync(channel.Id).ConfigureAwait(false); - } - public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client) + public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client, + RequestOptions options) { - await client.ApiClient.DeleteChannelAsync(channel.Id).ConfigureAwait(false); + await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false); } public static async Task ModifyAsync(IGuildChannel channel, BaseDiscordClient client, - Action func) + Action func, + RequestOptions options) { var args = new ModifyGuildChannelParams(); func(args); - await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args); + await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); } public static async Task ModifyAsync(ITextChannel channel, BaseDiscordClient client, - Action func) + Action func, + RequestOptions options) { var args = new ModifyTextChannelParams(); func(args); - await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args); + await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); } public static async Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client, - Action func) + Action func, + RequestOptions options) { var args = new ModifyVoiceChannelParams(); func(args); - await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args); + await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options); } //Invites - public static async Task> GetInvitesAsync(IChannel channel, BaseDiscordClient client) + public static async Task> GetInvitesAsync(IChannel channel, BaseDiscordClient client, + RequestOptions options) { - var models = await client.ApiClient.GetChannelInvitesAsync(channel.Id); + var models = await client.ApiClient.GetChannelInvitesAsync(channel.Id, options); return models.Select(x => RestInviteMetadata.Create(client, x)).ToImmutableArray(); } public static async Task CreateInviteAsync(IChannel channel, BaseDiscordClient client, - int? maxAge, int? maxUses, bool isTemporary) + int? maxAge, int? maxUses, bool isTemporary, RequestOptions options) { var args = new CreateChannelInviteParams { IsTemporary = isTemporary }; if (maxAge.HasValue) args.MaxAge = maxAge.Value; if (maxUses.HasValue) args.MaxUses = maxUses.Value; - var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args); + var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options); return RestInviteMetadata.Create(client, model); } //Messages public static async Task GetMessageAsync(IChannel channel, BaseDiscordClient client, - ulong id) + ulong id, RequestOptions options) { - var model = await client.ApiClient.GetChannelMessageAsync(channel.Id, id).ConfigureAwait(false); + var model = await client.ApiClient.GetChannelMessageAsync(channel.Id, id, options).ConfigureAwait(false); return RestMessage.Create(client, model); } public static IAsyncEnumerable> GetMessagesAsync(IChannel channel, BaseDiscordClient client, - ulong? fromMessageId = null, Direction dir = Direction.Before, int limit = DiscordConfig.MaxMessagesPerBatch) + ulong? fromMessageId, Direction dir, int limit, RequestOptions options) { //TODO: Test this with Around direction return new PagedAsyncEnumerable( @@ -86,7 +83,7 @@ namespace Discord.Rest }; if (info.Position != null) args.RelativeMessageId = info.Position.Value; - var models = await client.ApiClient.GetChannelMessagesAsync(channel.Id, args); + var models = await client.ApiClient.GetChannelMessagesAsync(channel.Id, args, options); return models.Select(x => RestMessage.Create(client, x)).ToImmutableArray(); ; }, nextPage: (info, lastPage) => @@ -102,71 +99,72 @@ namespace Discord.Rest count: limit ); } - public static async Task> GetPinnedMessagesAsync(IChannel channel, BaseDiscordClient client) + public static async Task> GetPinnedMessagesAsync(IChannel channel, BaseDiscordClient client, + RequestOptions options) { - var models = await client.ApiClient.GetPinsAsync(channel.Id).ConfigureAwait(false); + var models = await client.ApiClient.GetPinsAsync(channel.Id, options).ConfigureAwait(false); return models.Select(x => RestMessage.Create(client, x)).ToImmutableArray(); } public static async Task SendMessageAsync(IChannel channel, BaseDiscordClient client, - string text, bool isTTS) + string text, bool isTTS, RequestOptions options) { var args = new CreateMessageParams(text) { IsTTS = isTTS }; - var model = await client.ApiClient.CreateMessageAsync(channel.Id, args).ConfigureAwait(false); + var model = await client.ApiClient.CreateMessageAsync(channel.Id, args, options).ConfigureAwait(false); return RestUserMessage.Create(client, model); } public static Task SendFileAsync(IChannel channel, BaseDiscordClient client, - string filePath, string text, bool isTTS) + string filePath, string text, bool isTTS, RequestOptions options) { string filename = Path.GetFileName(filePath); using (var file = File.OpenRead(filePath)) - return SendFileAsync(channel, client, file, filename, text, isTTS); + return SendFileAsync(channel, client, file, filename, text, isTTS, options); } public static async Task SendFileAsync(IChannel channel, BaseDiscordClient client, - Stream stream, string filename, string text, bool isTTS) + Stream stream, string filename, string text, bool isTTS, RequestOptions options) { var args = new UploadFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS }; - var model = await client.ApiClient.UploadFileAsync(channel.Id, args).ConfigureAwait(false); + var model = await client.ApiClient.UploadFileAsync(channel.Id, args, options).ConfigureAwait(false); return RestUserMessage.Create(client, model); } public static async Task DeleteMessagesAsync(IChannel channel, BaseDiscordClient client, - IEnumerable messages) + IEnumerable messages, RequestOptions options) { var args = new DeleteMessagesParams(messages.Select(x => x.Id).ToArray()); - await client.ApiClient.DeleteMessagesAsync(channel.Id, args).ConfigureAwait(false); + await client.ApiClient.DeleteMessagesAsync(channel.Id, args, options).ConfigureAwait(false); } //Permission Overwrites public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, - IUser user, OverwritePermissions perms) + IUser user, OverwritePermissions perms, RequestOptions options) { var args = new ModifyChannelPermissionsParams("member", perms.AllowValue, perms.DenyValue); - await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args).ConfigureAwait(false); + await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args, options).ConfigureAwait(false); } public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, - IRole role, OverwritePermissions perms) + IRole role, OverwritePermissions perms, RequestOptions options) { var args = new ModifyChannelPermissionsParams("role", perms.AllowValue, perms.DenyValue); - await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args).ConfigureAwait(false); + await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args, options).ConfigureAwait(false); } public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, - IUser user) + IUser user, RequestOptions options) { - await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, user.Id).ConfigureAwait(false); + await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, user.Id, options).ConfigureAwait(false); } public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, - IRole role) + IRole role, RequestOptions options) { - await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id).ConfigureAwait(false); + await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id, options).ConfigureAwait(false); } //Users public static async Task GetUserAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client, - ulong id) + ulong id, RequestOptions options) { - var model = await client.ApiClient.GetGuildMemberAsync(channel.GuildId, id); + var model = await client.ApiClient.GetGuildMemberAsync(channel.GuildId, id, options); if (model == null) return null; var user = RestGuildUser.Create(client, guild, model); @@ -176,7 +174,7 @@ namespace Discord.Rest return user; } public static IAsyncEnumerable> GetUsersAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client, - ulong? froUserId = null, int? limit = DiscordConfig.MaxUsersPerBatch) + ulong? fromUserId, int? limit, RequestOptions options) { return new PagedAsyncEnumerable( DiscordConfig.MaxUsersPerBatch, @@ -188,7 +186,7 @@ namespace Discord.Rest }; if (info.Position != null) args.AfterUserId = info.Position.Value; - var models = await guild.Discord.ApiClient.GetGuildMembersAsync(guild.Id, args); + var models = await guild.Discord.ApiClient.GetGuildMembersAsync(guild.Id, args, options); return models .Select(x => RestGuildUser.Create(client, guild, x)) .Where(x => x.GetPermissions(channel).ReadMessages) @@ -200,13 +198,14 @@ namespace Discord.Rest if (lastPage.Count != DiscordConfig.MaxMessagesPerBatch) info.Remaining = 0; }, - start: froUserId, + start: fromUserId, count: limit ); } //Typing - public static IDisposable EnterTypingState(IChannel channel, BaseDiscordClient client) - => new TypingNotifier(client, channel); + public static IDisposable EnterTypingState(IChannel channel, BaseDiscordClient client, + RequestOptions options) + => new TypingNotifier(client, channel, options); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs index 3d1233cef..6d2b729dd 100644 --- a/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs @@ -7,21 +7,21 @@ namespace Discord.Rest public interface IRestMessageChannel : IMessageChannel { /// Sends a message to this message channel. - new Task SendMessageAsync(string text, bool isTTS = false); + new Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. - new Task SendFileAsync(string filePath, string text = null, bool isTTS = false); + new Task SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. - new Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false); + new Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, RequestOptions options = null); /// Gets a message from this message channel with the given id, or null if not found. - Task GetMessageAsync(ulong id); + Task GetMessageAsync(ulong id, RequestOptions options = null); /// Gets the last N messages from this message channel. - IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch); + IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null); /// Gets a collection of messages in this channel. - IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); + IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null); /// Gets a collection of messages in this channel. - IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); + IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null); /// Gets a collection of pinned messages in this channel. - new Task> GetPinnedMessagesAsync(); + new Task> GetPinnedMessagesAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs index 952a9e0fe..04305c6b8 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs @@ -41,12 +41,12 @@ namespace Discord.Rest } internal abstract void Update(Model model); - public abstract Task UpdateAsync(); + public abstract Task UpdateAsync(RequestOptions options = null); //IChannel - Task IChannel.GetUserAsync(ulong id, CacheMode mode) + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); //Overriden - IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); //Overriden } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs index 43f318abe..3adbd3fa4 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs @@ -34,10 +34,13 @@ namespace Discord.Rest Recipient.Update(model.Recipients.Value[0]); } - public override async Task UpdateAsync() - => Update(await ChannelHelper.GetAsync(this, Discord)); - public Task CloseAsync() - => ChannelHelper.DeleteAsync(this, Discord); + public override async Task UpdateAsync(RequestOptions options = null) + { + var model = await Discord.ApiClient.GetChannelAsync(Id, options); + Update(model); + } + public Task CloseAsync(RequestOptions options = null) + => ChannelHelper.DeleteAsync(this, Discord, options); public RestUser GetUser(ulong id) { @@ -49,29 +52,29 @@ namespace Discord.Rest return null; } - public Task GetMessageAsync(ulong id) - => ChannelHelper.GetMessageAsync(this, Discord, id); - public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) - => ChannelHelper.GetMessagesAsync(this, Discord, limit: limit); - public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit); - public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit); - public Task> GetPinnedMessagesAsync() - => ChannelHelper.GetPinnedMessagesAsync(this, Discord); - - public Task SendMessageAsync(string text, bool isTTS) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS); - public Task SendFileAsync(string filePath, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS); - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS); - - public Task DeleteMessagesAsync(IEnumerable messages) - => ChannelHelper.DeleteMessagesAsync(this, Discord, messages); - - public IDisposable EnterTypingState() - => ChannelHelper.EnterTypingState(this, Discord); + public Task GetMessageAsync(ulong id, RequestOptions options = null) + => ChannelHelper.GetMessageAsync(this, Discord, id, options); + public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options); + public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options); + public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options); + public Task> GetPinnedMessagesAsync(RequestOptions options = null) + => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); + + public Task SendMessageAsync(string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options); + public Task SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options); + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options); + + public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) + => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); + + public IDisposable EnterTypingState(RequestOptions options = null) + => ChannelHelper.EnterTypingState(this, Discord, options); public override string ToString() => $"@{Recipient}"; private string DebuggerDisplay => $"@{Recipient} ({Id}, DM)"; @@ -86,49 +89,50 @@ namespace Discord.Rest IReadOnlyCollection IPrivateChannel.Recipients => ImmutableArray.Create(Recipient); //IMessageChannel - async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode) + async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id); + return await GetMessageAsync(id, options); else return null; } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(limit); + return GetMessagesAsync(limit, options); else return AsyncEnumerable.Empty>(); } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode) + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(fromMessageId, dir, limit); + return GetMessagesAsync(fromMessageId, dir, limit, options); else return AsyncEnumerable.Empty>(); } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode) + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(fromMessage, dir, limit); + return GetMessagesAsync(fromMessage, dir, limit, options); else return AsyncEnumerable.Empty>(); } - async Task> IMessageChannel.GetPinnedMessagesAsync() - => await GetPinnedMessagesAsync().ConfigureAwait(false); - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS) - => await SendFileAsync(filePath, text, isTTS); - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => await SendFileAsync(stream, filename, text, isTTS); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS) - => await SendMessageAsync(text, isTTS); - IDisposable IMessageChannel.EnterTypingState() - => EnterTypingState(); + async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) + => await GetPinnedMessagesAsync(options); + + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(filePath, text, isTTS, options); + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(stream, filename, text, isTTS, options); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) + => await SendMessageAsync(text, isTTS, options); + IDisposable IMessageChannel.EnterTypingState(RequestOptions options) + => EnterTypingState(options); //IChannel - Task IChannel.GetUserAsync(ulong id, CacheMode mode) + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); - IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs index d06077a4a..4a1ea7b87 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs @@ -49,12 +49,15 @@ namespace Discord.Rest _users = users.ToImmutable(); } - public override async Task UpdateAsync() - => Update(await ChannelHelper.GetAsync(this, Discord)); - public Task LeaveAsync() - => ChannelHelper.DeleteAsync(this, Discord); + public override async Task UpdateAsync(RequestOptions options = null) + { + var model = await Discord.ApiClient.GetChannelAsync(Id, options); + Update(model); + } + public Task LeaveAsync(RequestOptions options = null) + => ChannelHelper.DeleteAsync(this, Discord, options); - public IUser GetUser(ulong id) + public RestUser GetUser(ulong id) { RestGroupUser user; if (_users.TryGetValue(id, out user)) @@ -62,29 +65,29 @@ namespace Discord.Rest return null; } - public Task GetMessageAsync(ulong id) - => ChannelHelper.GetMessageAsync(this, Discord, id); - public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) - => ChannelHelper.GetMessagesAsync(this, Discord, limit: limit); - public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit); - public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit); - public Task> GetPinnedMessagesAsync() - => ChannelHelper.GetPinnedMessagesAsync(this, Discord); - - public Task SendMessageAsync(string text, bool isTTS) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS); - public Task SendFileAsync(string filePath, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS); - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS); - - public Task DeleteMessagesAsync(IEnumerable messages) - => ChannelHelper.DeleteMessagesAsync(this, Discord, messages); - - public IDisposable EnterTypingState() - => ChannelHelper.EnterTypingState(this, Discord); + public Task GetMessageAsync(ulong id, RequestOptions options = null) + => ChannelHelper.GetMessageAsync(this, Discord, id, options); + public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options); + public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options); + public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options); + public Task> GetPinnedMessagesAsync(RequestOptions options = null) + => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); + + public Task SendMessageAsync(string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options); + public Task SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options); + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options); + + public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) + => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); + + public IDisposable EnterTypingState(RequestOptions options = null) + => ChannelHelper.EnterTypingState(this, Discord, options); public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id}, Group)"; @@ -96,50 +99,50 @@ namespace Discord.Rest IReadOnlyCollection IPrivateChannel.Recipients => Recipients; //IMessageChannel - async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode) + async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id); + return await GetMessageAsync(id, options); else return null; } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(limit); + return GetMessagesAsync(limit, options); else return AsyncEnumerable.Empty>(); } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode) + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(fromMessageId, dir, limit); + return GetMessagesAsync(fromMessageId, dir, limit, options); else return AsyncEnumerable.Empty>(); } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode) + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(fromMessage, dir, limit); + return GetMessagesAsync(fromMessage, dir, limit, options); else return AsyncEnumerable.Empty>(); } - async Task> IMessageChannel.GetPinnedMessagesAsync() - => await GetPinnedMessagesAsync(); - - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS) - => await SendFileAsync(filePath, text, isTTS); - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => await SendFileAsync(stream, filename, text, isTTS); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS) - => await SendMessageAsync(text, isTTS); - IDisposable IMessageChannel.EnterTypingState() - => EnterTypingState(); + async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) + => await GetPinnedMessagesAsync(options); + + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(filePath, text, isTTS, options); + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(stream, filename, text, isTTS, options); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) + => await SendMessageAsync(text, isTTS, options); + IDisposable IMessageChannel.EnterTypingState(RequestOptions options) + => EnterTypingState(options); //IChannel - Task IChannel.GetUserAsync(ulong id, CacheMode mode) - => Task.FromResult(GetUser(id)); - IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode) + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) + => Task.FromResult(GetUser(id)); + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index 72dd4a48b..08ef88d46 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -49,12 +49,15 @@ namespace Discord.Rest _overwrites = newOverwrites.ToImmutable(); } - public override async Task UpdateAsync() - => Update(await ChannelHelper.GetAsync(this, Discord)); - public Task ModifyAsync(Action func) - => ChannelHelper.ModifyAsync(this, Discord, func); - public Task DeleteAsync() - => ChannelHelper.DeleteAsync(this, Discord); + public override async Task UpdateAsync(RequestOptions options = null) + { + var model = await Discord.ApiClient.GetChannelAsync(GuildId, Id, options); + Update(model); + } + public Task ModifyAsync(Action func, RequestOptions options = null) + => ChannelHelper.ModifyAsync(this, Discord, func, options); + public Task DeleteAsync(RequestOptions options = null) + => ChannelHelper.DeleteAsync(this, Discord, options); public OverwritePermissions? GetPermissionOverwrite(IUser user) { @@ -74,19 +77,19 @@ namespace Discord.Rest } return null; } - public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms) + public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null) { - await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms).ConfigureAwait(false); + await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options).ConfigureAwait(false); _overwrites = _overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = user.Id, TargetType = PermissionTarget.User })); } - public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms) + public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null) { - await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms).ConfigureAwait(false); + await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options).ConfigureAwait(false); _overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = role.Id, TargetType = PermissionTarget.Role })); } - public async Task RemovePermissionOverwriteAsync(IUser user) + public async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) { - await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user).ConfigureAwait(false); + await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false); for (int i = 0; i < _overwrites.Length; i++) { @@ -97,9 +100,9 @@ namespace Discord.Rest } } } - public async Task RemovePermissionOverwriteAsync(IRole role) + public async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) { - await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role).ConfigureAwait(false); + await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false); for (int i = 0; i < _overwrites.Length; i++) { @@ -111,41 +114,41 @@ namespace Discord.Rest } } - public async Task> GetInvitesAsync() - => await ChannelHelper.GetInvitesAsync(this, Discord); - public async Task CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true) - => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary); + public async Task> GetInvitesAsync(RequestOptions options = null) + => await ChannelHelper.GetInvitesAsync(this, Discord, options); + public async Task CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true, RequestOptions options = null) + => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options); public override string ToString() => Name; //IGuildChannel - async Task> IGuildChannel.GetInvitesAsync() - => await GetInvitesAsync(); - async Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary) - => await CreateInviteAsync(maxAge, maxUses, isTemporary); + async Task> IGuildChannel.GetInvitesAsync(RequestOptions options) + => await GetInvitesAsync(options); + async Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, RequestOptions options) + => await CreateInviteAsync(maxAge, maxUses, isTemporary, options); OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) => GetPermissionOverwrite(role); OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user) => GetPermissionOverwrite(user); - async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions) - => await AddPermissionOverwriteAsync(role, permissions); - async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions) - => await AddPermissionOverwriteAsync(user, permissions); - async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role) - => await RemovePermissionOverwriteAsync(role); - async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user) - => await RemovePermissionOverwriteAsync(user); + async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options) + => await AddPermissionOverwriteAsync(role, permissions, options); + async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options) + => await AddPermissionOverwriteAsync(user, permissions, options); + async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options) + => await RemovePermissionOverwriteAsync(role, options); + async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) + => await RemovePermissionOverwriteAsync(user, options); - IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); //Overriden //Overriden in Text/Voice //TODO: Does this actually override? - Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode) + Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); //Overriden in Text/Voice //TODO: Does this actually override? //IChannel - IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); //Overriden in Text/Voice //TODO: Does this actually override? - Task IChannel.GetUserAsync(ulong id, CacheMode mode) + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); //Overriden in Text/Voice //TODO: Does this actually override? } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs index 77677a5bf..b90fff58f 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs @@ -34,95 +34,95 @@ namespace Discord.Rest } - public Task ModifyAsync(Action func) - => ChannelHelper.ModifyAsync(this, Discord, func); + public Task ModifyAsync(Action func, RequestOptions options = null) + => ChannelHelper.ModifyAsync(this, Discord, func, options); - public Task GetUserAsync(ulong id) - => ChannelHelper.GetUserAsync(this, Guild, Discord, id); - public IAsyncEnumerable> GetUsersAsync() - => ChannelHelper.GetUsersAsync(this, Guild, Discord); + public Task GetUserAsync(ulong id, RequestOptions options = null) + => ChannelHelper.GetUserAsync(this, Guild, Discord, id, options); + public IAsyncEnumerable> GetUsersAsync(RequestOptions options = null) + => ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options); - public Task GetMessageAsync(ulong id) - => ChannelHelper.GetMessageAsync(this, Discord, id); - public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) - => ChannelHelper.GetMessagesAsync(this, Discord, limit: limit); - public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit); - public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit); - public Task> GetPinnedMessagesAsync() - => ChannelHelper.GetPinnedMessagesAsync(this, Discord); + public Task GetMessageAsync(ulong id, RequestOptions options = null) + => ChannelHelper.GetMessageAsync(this, Discord, id, options); + public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options); + public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options); + public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options); + public Task> GetPinnedMessagesAsync(RequestOptions options = null) + => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); - public Task SendMessageAsync(string text, bool isTTS) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS); - public Task SendFileAsync(string filePath, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS); - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS); + public Task SendMessageAsync(string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options); + public Task SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options); + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options); - public Task DeleteMessagesAsync(IEnumerable messages) - => ChannelHelper.DeleteMessagesAsync(this, Discord, messages); + public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) + => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); - public IDisposable EnterTypingState() - => ChannelHelper.EnterTypingState(this, Discord); + public IDisposable EnterTypingState(RequestOptions options = null) + => ChannelHelper.EnterTypingState(this, Discord, options); private string DebuggerDisplay => $"{Name} ({Id}, Text)"; //IGuildChannel - async Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode) + async Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetUserAsync(id); + return await GetUserAsync(id, options); else return null; } - IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetUsersAsync(); + return GetUsersAsync(options); else return AsyncEnumerable.Empty>(); //Overriden } //IMessageChannel - async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode) + async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id); + return await GetMessageAsync(id, options); else return null; } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(limit); + return GetMessagesAsync(limit, options); else return AsyncEnumerable.Empty>(); } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode) + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(fromMessageId, dir, limit); + return GetMessagesAsync(fromMessageId, dir, limit, options); else return AsyncEnumerable.Empty>(); } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode) + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return GetMessagesAsync(fromMessage, dir, limit); + return GetMessagesAsync(fromMessage, dir, limit, options); else return AsyncEnumerable.Empty>(); } - async Task> IMessageChannel.GetPinnedMessagesAsync() - => await GetPinnedMessagesAsync(); + async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) + => await GetPinnedMessagesAsync(options); - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS) - => await SendFileAsync(filePath, text, isTTS); - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => await SendFileAsync(stream, filename, text, isTTS); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS) - => await SendMessageAsync(text, isTTS); - IDisposable IMessageChannel.EnterTypingState() - => EnterTypingState(); + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(filePath, text, isTTS, options); + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(stream, filename, text, isTTS, options); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) + => await SendMessageAsync(text, isTTS, options); + IDisposable IMessageChannel.EnterTypingState(RequestOptions options) + => EnterTypingState(options); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs index 02eab4776..8abd3c911 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs @@ -33,8 +33,8 @@ namespace Discord.Rest UserLimit = model.UserLimit.Value; } - public Task ModifyAsync(Action func) - => ChannelHelper.ModifyAsync(this, Discord, func); + public Task ModifyAsync(Action func, RequestOptions options = null) + => ChannelHelper.ModifyAsync(this, Discord, func, options); private string DebuggerDisplay => $"{Name} ({Id}, Voice)"; @@ -42,9 +42,9 @@ namespace Discord.Rest Task IVoiceChannel.ConnectAsync() { throw new NotSupportedException(); } //IGuildChannel - Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode) + Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); - IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); } } diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index e6aec2f70..966914960 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -14,7 +14,7 @@ namespace Discord.Rest { //General public static async Task ModifyAsync(IGuild guild, BaseDiscordClient client, - Action func) + Action func, RequestOptions options) { if (func == null) throw new NullReferenceException(nameof(func)); @@ -26,116 +26,122 @@ namespace Discord.Rest if (args.Icon.IsSpecified && guild.IconId != null) args.Icon = new API.Image(guild.IconId); - return await client.ApiClient.ModifyGuildAsync(guild.Id, args).ConfigureAwait(false); + return await client.ApiClient.ModifyGuildAsync(guild.Id, args, options).ConfigureAwait(false); } public static async Task ModifyEmbedAsync(IGuild guild, BaseDiscordClient client, - Action func) + Action func, RequestOptions options) { if (func == null) throw new NullReferenceException(nameof(func)); var args = new ModifyGuildEmbedParams(); func(args); - return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, args).ConfigureAwait(false); + return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, args, options).ConfigureAwait(false); } public static async Task ModifyChannelsAsync(IGuild guild, BaseDiscordClient client, - IEnumerable args) + IEnumerable args, RequestOptions options) { - await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, args).ConfigureAwait(false); + await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, args, options).ConfigureAwait(false); } public static async Task> ModifyRolesAsync(IGuild guild, BaseDiscordClient client, - IEnumerable args) + IEnumerable args, RequestOptions options) { - return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, args).ConfigureAwait(false); + return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, args, options).ConfigureAwait(false); } - public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client) + public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client, + RequestOptions options) { - await client.ApiClient.LeaveGuildAsync(guild.Id).ConfigureAwait(false); + await client.ApiClient.LeaveGuildAsync(guild.Id, options).ConfigureAwait(false); } - public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client) + public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client, + RequestOptions options) { - await client.ApiClient.DeleteGuildAsync(guild.Id).ConfigureAwait(false); + await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false); } //Bans - public static async Task> GetBansAsync(IGuild guild, BaseDiscordClient client) + public static async Task> GetBansAsync(IGuild guild, BaseDiscordClient client, + RequestOptions options) { - var models = await client.ApiClient.GetGuildBansAsync(guild.Id); + var models = await client.ApiClient.GetGuildBansAsync(guild.Id, options); return models.Select(x => RestBan.Create(client, x)).ToImmutableArray(); } public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client, - ulong userId, int pruneDays) + ulong userId, int pruneDays, RequestOptions options) { var args = new CreateGuildBanParams { DeleteMessageDays = pruneDays }; - await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args); + await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options); } public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client, - ulong userId) + ulong userId, RequestOptions options) { - await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId); + await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options); } //Channels public static async Task GetChannelAsync(IGuild guild, BaseDiscordClient client, - ulong id) + ulong id, RequestOptions options) { - var model = await client.ApiClient.GetChannelAsync(guild.Id, id).ConfigureAwait(false); + var model = await client.ApiClient.GetChannelAsync(guild.Id, id, options).ConfigureAwait(false); if (model != null) return RestGuildChannel.Create(client, guild, model); return null; } - public static async Task> GetChannelsAsync(IGuild guild, BaseDiscordClient client) + public static async Task> GetChannelsAsync(IGuild guild, BaseDiscordClient client, + RequestOptions options) { - var models = await client.ApiClient.GetGuildChannelsAsync(guild.Id).ConfigureAwait(false); + var models = await client.ApiClient.GetGuildChannelsAsync(guild.Id, options).ConfigureAwait(false); return models.Select(x => RestGuildChannel.Create(client, guild, x)).ToImmutableArray(); } public static async Task CreateTextChannelAsync(IGuild guild, BaseDiscordClient client, - string name) + string name, RequestOptions options) { if (name == null) throw new ArgumentNullException(nameof(name)); var args = new CreateGuildChannelParams(name, ChannelType.Text); - var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args).ConfigureAwait(false); + var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestTextChannel.Create(client, guild, model); } public static async Task CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client, - string name) + string name, RequestOptions options) { if (name == null) throw new ArgumentNullException(nameof(name)); var args = new CreateGuildChannelParams(name, ChannelType.Voice); - var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args).ConfigureAwait(false); + var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false); return RestVoiceChannel.Create(client, guild, model); } //Integrations - public static async Task> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client) + public static async Task> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client, + RequestOptions options) { - var models = await client.ApiClient.GetGuildIntegrationsAsync(guild.Id).ConfigureAwait(false); + var models = await client.ApiClient.GetGuildIntegrationsAsync(guild.Id, options).ConfigureAwait(false); return models.Select(x => RestGuildIntegration.Create(client, x)).ToImmutableArray(); } public static async Task CreateIntegrationAsync(IGuild guild, BaseDiscordClient client, - ulong id, string type) + ulong id, string type, RequestOptions options) { var args = new CreateGuildIntegrationParams(id, type); - var model = await client.ApiClient.CreateGuildIntegrationAsync(guild.Id, args).ConfigureAwait(false); + var model = await client.ApiClient.CreateGuildIntegrationAsync(guild.Id, args, options).ConfigureAwait(false); return RestGuildIntegration.Create(client, model); } //Invites - public static async Task> GetInvitesAsync(IGuild guild, BaseDiscordClient client) + public static async Task> GetInvitesAsync(IGuild guild, BaseDiscordClient client, + RequestOptions options) { - var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id).ConfigureAwait(false); + var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id, options).ConfigureAwait(false); return models.Select(x => RestInviteMetadata.Create(client, x)).ToImmutableArray(); } //Roles public static async Task CreateRoleAsync(IGuild guild, BaseDiscordClient client, - string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false) + string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) { if (name == null) throw new ArgumentNullException(nameof(name)); - var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id).ConfigureAwait(false); + var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, options).ConfigureAwait(false); var role = RestRole.Create(client, model); await role.ModifyAsync(x => @@ -144,26 +150,27 @@ namespace Discord.Rest x.Permissions = (permissions ?? role.Permissions).RawValue; x.Color = (color ?? Color.Default).RawValue; x.Hoist = isHoisted; - }).ConfigureAwait(false); + }, options).ConfigureAwait(false); return role; } //Users public static async Task GetUserAsync(IGuild guild, BaseDiscordClient client, - ulong id) + ulong id, RequestOptions options) { - var model = await client.ApiClient.GetGuildMemberAsync(guild.Id, id).ConfigureAwait(false); + var model = await client.ApiClient.GetGuildMemberAsync(guild.Id, id, options).ConfigureAwait(false); if (model != null) return RestGuildUser.Create(client, guild, model); return null; } - public static async Task GetCurrentUserAsync(IGuild guild, BaseDiscordClient client) + public static async Task GetCurrentUserAsync(IGuild guild, BaseDiscordClient client, + RequestOptions options) { - return await GetUserAsync(guild, client, client.CurrentUser.Id).ConfigureAwait(false); + return await GetUserAsync(guild, client, client.CurrentUser.Id, options).ConfigureAwait(false); } public static IAsyncEnumerable> GetUsersAsync(IGuild guild, BaseDiscordClient client, - ulong? fromUserId = null, int limit = DiscordConfig.MaxMessagesPerBatch) + ulong? fromUserId, int? limit, RequestOptions options) { return new PagedAsyncEnumerable( DiscordConfig.MaxMessagesPerBatch, @@ -175,7 +182,7 @@ namespace Discord.Rest }; if (info.Position != null) args.AfterUserId = info.Position.Value; - var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args); + var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args, options); return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray(); }, nextPage: (info, lastPage) => @@ -189,14 +196,14 @@ namespace Discord.Rest ); } public static async Task PruneUsersAsync(IGuild guild, BaseDiscordClient client, - int days = 30, bool simulate = false) + int days, bool simulate, RequestOptions options) { var args = new GuildPruneParams(days); GetGuildPruneCountResponse model; if (simulate) - model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args).ConfigureAwait(false); + model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args, options).ConfigureAwait(false); else - model = await client.ApiClient.BeginGuildPruneAsync(guild.Id, args).ConfigureAwait(false); + model = await client.ApiClient.BeginGuildPruneAsync(guild.Id, args, options).ConfigureAwait(false); return model.Pruned; } } diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 8f5d269e5..a51f60d5a 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; -using System.Linq; using System.Threading.Tasks; using Model = Discord.API.Guild; @@ -93,56 +92,56 @@ namespace Discord.Rest } //General - public async Task UpdateAsync() - => Update(await Discord.ApiClient.GetGuildAsync(Id)); - public Task DeleteAsync() - => GuildHelper.DeleteAsync(this, Discord); - - public Task ModifyAsync(Action func) - => GuildHelper.ModifyAsync(this, Discord, func); - public Task ModifyEmbedAsync(Action func) - => GuildHelper.ModifyEmbedAsync(this, Discord, func); - public Task ModifyChannelsAsync(IEnumerable args) - => GuildHelper.ModifyChannelsAsync(this, Discord, args); - public Task ModifyRolesAsync(IEnumerable args) - => GuildHelper.ModifyRolesAsync(this, Discord, args); - - public Task LeaveAsync() - => GuildHelper.LeaveAsync(this, Discord); + public async Task UpdateAsync(RequestOptions options = null) + => Update(await Discord.ApiClient.GetGuildAsync(Id, options)); + public Task DeleteAsync(RequestOptions options = null) + => GuildHelper.DeleteAsync(this, Discord, options); + + public Task ModifyAsync(Action func, RequestOptions options = null) + => GuildHelper.ModifyAsync(this, Discord, func, options); + public Task ModifyEmbedAsync(Action func, RequestOptions options = null) + => GuildHelper.ModifyEmbedAsync(this, Discord, func, options); + public Task ModifyChannelsAsync(IEnumerable args, RequestOptions options = null) + => GuildHelper.ModifyChannelsAsync(this, Discord, args, options); + public Task ModifyRolesAsync(IEnumerable args, RequestOptions options = null) + => GuildHelper.ModifyRolesAsync(this, Discord, args, options); + + public Task LeaveAsync(RequestOptions options = null) + => GuildHelper.LeaveAsync(this, Discord, options); //Bans - public Task> GetBansAsync() - => GuildHelper.GetBansAsync(this, Discord); + public Task> GetBansAsync(RequestOptions options = null) + => GuildHelper.GetBansAsync(this, Discord, options); - public Task AddBanAsync(IUser user, int pruneDays = 0) - => GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays); - public Task AddBanAsync(ulong userId, int pruneDays = 0) - => GuildHelper.AddBanAsync(this, Discord, userId, pruneDays); + public Task AddBanAsync(IUser user, int pruneDays = 0, RequestOptions options = null) + => GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, options); + public Task AddBanAsync(ulong userId, int pruneDays = 0, RequestOptions options = null) + => GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, options); - public Task RemoveBanAsync(IUser user) - => GuildHelper.RemoveBanAsync(this, Discord, user.Id); - public Task RemoveBanAsync(ulong userId) - => GuildHelper.RemoveBanAsync(this, Discord, userId); + public Task RemoveBanAsync(IUser user, RequestOptions options = null) + => GuildHelper.RemoveBanAsync(this, Discord, user.Id, options); + public Task RemoveBanAsync(ulong userId, RequestOptions options = null) + => GuildHelper.RemoveBanAsync(this, Discord, userId, options); //Channels - public Task> GetChannelsAsync() - => GuildHelper.GetChannelsAsync(this, Discord); - public Task GetChannelAsync(ulong id) - => GuildHelper.GetChannelAsync(this, Discord, id); - public Task CreateTextChannelAsync(string name) - => GuildHelper.CreateTextChannelAsync(this, Discord, name); - public Task CreateVoiceChannelAsync(string name) - => GuildHelper.CreateVoiceChannelAsync(this, Discord, name); + public Task> GetChannelsAsync(RequestOptions options = null) + => GuildHelper.GetChannelsAsync(this, Discord, options); + public Task GetChannelAsync(ulong id, RequestOptions options = null) + => GuildHelper.GetChannelAsync(this, Discord, id, options); + public Task CreateTextChannelAsync(string name, RequestOptions options = null) + => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); + public Task CreateVoiceChannelAsync(string name, RequestOptions options = null) + => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); //Integrations - public Task> GetIntegrationsAsync() - => GuildHelper.GetIntegrationsAsync(this, Discord); - public Task CreateIntegrationAsync(ulong id, string type) - => GuildHelper.CreateIntegrationAsync(this, Discord, id, type); + public Task> GetIntegrationsAsync(RequestOptions options = null) + => GuildHelper.GetIntegrationsAsync(this, Discord, options); + public Task CreateIntegrationAsync(ulong id, string type, RequestOptions options = null) + => GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options); //Invites - public Task> GetInvitesAsync() - => GuildHelper.GetInvitesAsync(this, Discord); + public Task> GetInvitesAsync(RequestOptions options = null) + => GuildHelper.GetInvitesAsync(this, Discord, options); //Roles public RestRole GetRole(ulong id) @@ -153,23 +152,24 @@ namespace Discord.Rest return null; } - public async Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), bool isHoisted = false) + public async Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), + bool isHoisted = false, RequestOptions options = null) { - var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted); + var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options); _roles = _roles.Add(role.Id, role); return role; } //Users - public IAsyncEnumerable> GetUsersAsync() - => GuildHelper.GetUsersAsync(this, Discord); - public Task GetUserAsync(ulong id) - => GuildHelper.GetUserAsync(this, Discord, id); - public Task GetCurrentUserAsync() - => GuildHelper.GetUserAsync(this, Discord, Discord.CurrentUser.Id); + public IAsyncEnumerable> GetUsersAsync(RequestOptions options = null) + => GuildHelper.GetUsersAsync(this, Discord, null, null, options); + public Task GetUserAsync(ulong id, RequestOptions options = null) + => GuildHelper.GetUserAsync(this, Discord, id, options); + public Task GetCurrentUserAsync(RequestOptions options = null) + => GuildHelper.GetUserAsync(this, Discord, Discord.CurrentUser.Id, options); - public Task PruneUsersAsync(int days = 30, bool simulate = false) - => GuildHelper.PruneUsersAsync(this, Discord, days, simulate); + public Task PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null) + => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id})"; @@ -180,59 +180,59 @@ namespace Discord.Rest IRole IGuild.EveryoneRole => EveryoneRole; IReadOnlyCollection IGuild.Roles => Roles; - async Task> IGuild.GetBansAsync() - => await GetBansAsync(); + async Task> IGuild.GetBansAsync(RequestOptions options) + => await GetBansAsync(options); - async Task> IGuild.GetChannelsAsync(CacheMode mode) + async Task> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetChannelsAsync(); + return await GetChannelsAsync(options); else return ImmutableArray.Create(); } - async Task IGuild.GetChannelAsync(ulong id, CacheMode mode) + async Task IGuild.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetChannelAsync(id); + return await GetChannelAsync(id, options); else return null; } - async Task IGuild.CreateTextChannelAsync(string name) - => await CreateTextChannelAsync(name); - async Task IGuild.CreateVoiceChannelAsync(string name) - => await CreateVoiceChannelAsync(name); + async Task IGuild.CreateTextChannelAsync(string name, RequestOptions options) + => await CreateTextChannelAsync(name, options); + async Task IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) + => await CreateVoiceChannelAsync(name, options); - async Task> IGuild.GetIntegrationsAsync() - => await GetIntegrationsAsync(); - async Task IGuild.CreateIntegrationAsync(ulong id, string type) - => await CreateIntegrationAsync(id, type); + async Task> IGuild.GetIntegrationsAsync(RequestOptions options) + => await GetIntegrationsAsync(options); + async Task IGuild.CreateIntegrationAsync(ulong id, string type, RequestOptions options) + => await CreateIntegrationAsync(id, type, options); - async Task> IGuild.GetInvitesAsync() - => await GetInvitesAsync(); + async Task> IGuild.GetInvitesAsync(RequestOptions options) + => await GetInvitesAsync(options); IRole IGuild.GetRole(ulong id) => GetRole(id); - async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted) - => await CreateRoleAsync(name, permissions, color, isHoisted); + async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) + => await CreateRoleAsync(name, permissions, color, isHoisted, options); - async Task IGuild.GetUserAsync(ulong id, CacheMode mode) + async Task IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetUserAsync(id); + return await GetUserAsync(id, options); else return null; } - async Task IGuild.GetCurrentUserAsync(CacheMode mode) + async Task IGuild.GetCurrentUserAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetCurrentUserAsync(); + return await GetCurrentUserAsync(options); else return null; } - async Task> IGuild.GetUsersAsync(CacheMode mode) + async Task> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return (await GetUsersAsync().Flatten()).ToImmutableArray(); + return (await GetUsersAsync(options).Flatten()).ToImmutableArray(); else return ImmutableArray.Create(); } diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestUserGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestUserGuild.cs index d222c2d1d..c6334bfb1 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestUserGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestUserGuild.cs @@ -34,13 +34,13 @@ namespace Discord.Rest Permissions = new GuildPermissions(model.Permissions); } - public async Task LeaveAsync() + public async Task LeaveAsync(RequestOptions options = null) { - await Discord.ApiClient.LeaveGuildAsync(Id).ConfigureAwait(false); + await Discord.ApiClient.LeaveGuildAsync(Id, options).ConfigureAwait(false); } - public async Task DeleteAsync() + public async Task DeleteAsync(RequestOptions options = null) { - await Discord.ApiClient.DeleteGuildAsync(Id).ConfigureAwait(false); + await Discord.ApiClient.DeleteGuildAsync(Id, options).ConfigureAwait(false); } public override string ToString() => Name; diff --git a/src/Discord.Net.Rest/Entities/Invites/InviteHelper.cs b/src/Discord.Net.Rest/Entities/Invites/InviteHelper.cs index 23e0ddab7..8ec428178 100644 --- a/src/Discord.Net.Rest/Entities/Invites/InviteHelper.cs +++ b/src/Discord.Net.Rest/Entities/Invites/InviteHelper.cs @@ -5,17 +5,15 @@ namespace Discord.Rest { internal static class InviteHelper { - public static async Task GetAsync(IInvite invite, BaseDiscordClient client) + public static async Task AcceptAsync(IInvite invite, BaseDiscordClient client, + RequestOptions options) { - return await client.ApiClient.GetInviteAsync(invite.Code).ConfigureAwait(false); + await client.ApiClient.AcceptInviteAsync(invite.Code, options).ConfigureAwait(false); } - public static async Task AcceptAsync(IInvite invite, BaseDiscordClient client) + public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client, + RequestOptions options) { - await client.ApiClient.AcceptInviteAsync(invite.Code).ConfigureAwait(false); - } - public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client) - { - await client.ApiClient.DeleteInviteAsync(invite.Code).ConfigureAwait(false); + await client.ApiClient.DeleteInviteAsync(invite.Code, options).ConfigureAwait(false); } } } diff --git a/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs b/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs index 983b2986b..4c07ea9ac 100644 --- a/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs +++ b/src/Discord.Net.Rest/Entities/Invites/RestInvite.cs @@ -32,14 +32,17 @@ namespace Discord.Rest GuildName = model.Guild.Name; ChannelName = model.Channel.Name; } + + public async Task UpdateAsync(RequestOptions options = null) + { + var model = await Discord.ApiClient.GetInviteAsync(Code, options); + Update(model); + } + public Task DeleteAsync(RequestOptions options = null) + => InviteHelper.DeleteAsync(this, Discord, options); - public async Task UpdateAsync() - => Update(await InviteHelper.GetAsync(this, Discord).ConfigureAwait(false)); - public Task DeleteAsync() - => InviteHelper.DeleteAsync(this, Discord); - - public Task AcceptAsync() - => InviteHelper.AcceptAsync(this, Discord); + public Task AcceptAsync(RequestOptions options = null) + => InviteHelper.AcceptAsync(this, Discord, options); public override string ToString() => Url; private string DebuggerDisplay => $"{Url} ({GuildName} / {ChannelName})"; diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs index 28338635b..6918dfb27 100644 --- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs +++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs @@ -6,28 +6,28 @@ namespace Discord.Rest { internal static class MessageHelper { - public static async Task GetAsync(IMessage msg, BaseDiscordClient client) - { - await client.ApiClient.GetChannelMessageAsync(msg.ChannelId, msg.Id); - } - public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action func) + public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action func, + RequestOptions options) { var args = new ModifyMessageParams(); func(args); - await client.ApiClient.ModifyMessageAsync(msg.ChannelId, msg.Id, args); + await client.ApiClient.ModifyMessageAsync(msg.ChannelId, msg.Id, args, options); } - public static async Task DeleteAsync(IMessage msg, BaseDiscordClient client) + public static async Task DeleteAsync(IMessage msg, BaseDiscordClient client, + RequestOptions options) { - await client.ApiClient.DeleteMessageAsync(msg.ChannelId, msg.Id); + await client.ApiClient.DeleteMessageAsync(msg.ChannelId, msg.Id, options); } - public static async Task PinAsync(IMessage msg, BaseDiscordClient client) + public static async Task PinAsync(IMessage msg, BaseDiscordClient client, + RequestOptions options) { - await client.ApiClient.AddPinAsync(msg.ChannelId, msg.Id); + await client.ApiClient.AddPinAsync(msg.ChannelId, msg.Id, options); } - public static async Task UnpinAsync(IMessage msg, BaseDiscordClient client) + public static async Task UnpinAsync(IMessage msg, BaseDiscordClient client, + RequestOptions options) { - await client.ApiClient.RemovePinAsync(msg.ChannelId, msg.Id); + await client.ApiClient.RemovePinAsync(msg.ChannelId, msg.Id, options); } } } diff --git a/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs index bf1a1e2a6..7096d6198 100644 --- a/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs +++ b/src/Discord.Net.Rest/Entities/Messages/RestMessage.cs @@ -48,9 +48,9 @@ namespace Discord.Rest Content = model.Content.Value; } - public async Task UpdateAsync() + public async Task UpdateAsync(RequestOptions options) { - var model = await Discord.ApiClient.GetChannelMessageAsync(ChannelId, Id).ConfigureAwait(false); + var model = await Discord.ApiClient.GetChannelMessageAsync(ChannelId, Id, options).ConfigureAwait(false); Update(model); } diff --git a/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs index e21295a92..b28b321bf 100644 --- a/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs +++ b/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs @@ -109,15 +109,15 @@ namespace Discord.Rest } } - public Task ModifyAsync(Action func) - => MessageHelper.ModifyAsync(this, Discord, func); - public Task DeleteAsync() - => MessageHelper.DeleteAsync(this, Discord); + public Task ModifyAsync(Action func, RequestOptions options) + => MessageHelper.ModifyAsync(this, Discord, func, options); + public Task DeleteAsync(RequestOptions options) + => MessageHelper.DeleteAsync(this, Discord, options); - public Task PinAsync() - => MessageHelper.PinAsync(this, Discord); - public Task UnpinAsync() - => MessageHelper.UnpinAsync(this, Discord); + public Task PinAsync(RequestOptions options) + => MessageHelper.PinAsync(this, Discord, options); + public Task UnpinAsync(RequestOptions options) + => MessageHelper.UnpinAsync(this, Discord, options); public string Resolve(UserMentionHandling userHandling = UserMentionHandling.Name, ChannelMentionHandling channelHandling = ChannelMentionHandling.Name, RoleMentionHandling roleHandling = RoleMentionHandling.Name, EveryoneMentionHandling everyoneHandling = EveryoneMentionHandling.Ignore) diff --git a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs index d2c3e01bd..e8aaaa772 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs @@ -40,10 +40,10 @@ namespace Discord.Rest Permissions = new GuildPermissions(model.Permissions); } - public Task ModifyAsync(Action func) - => RoleHelper.ModifyAsync(this, Discord, func); - public Task DeleteAsync() - => RoleHelper.DeleteAsync(this, Discord); + public Task ModifyAsync(Action func, RequestOptions options) + => RoleHelper.ModifyAsync(this, Discord, func, options); + public Task DeleteAsync(RequestOptions options) + => RoleHelper.DeleteAsync(this, Discord, options); public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id})"; diff --git a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs index c9438f10d..8ecc63893 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs @@ -7,16 +7,17 @@ namespace Discord.Rest internal static class RoleHelper { //General - public static async Task DeleteAsync(IRole role, BaseDiscordClient client) + public static async Task DeleteAsync(IRole role, BaseDiscordClient client, + RequestOptions options) { - await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id).ConfigureAwait(false); + await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false); } public static async Task ModifyAsync(IRole role, BaseDiscordClient client, - Action func) + Action func, RequestOptions options) { var args = new ModifyGuildRoleParams(); func(args); - await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args); + await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args, options); } } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs index dd6056f41..1ea4e2117 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs @@ -57,13 +57,16 @@ namespace Discord.Rest roles.Add(roleIds[i]); _roleIds = roles.ToImmutable(); } - - public override async Task UpdateAsync() - => Update(await UserHelper.GetAsync(this, Discord)); - public Task ModifyAsync(Action func) - => UserHelper.ModifyAsync(this, Discord, func); - public Task KickAsync() - => UserHelper.KickAsync(this, Discord); + + public override async Task UpdateAsync(RequestOptions options = null) + { + var model = await Discord.ApiClient.GetGuildMemberAsync(GuildId, Id, options); + Update(model); + } + public Task ModifyAsync(Action func, RequestOptions options = null) + => UserHelper.ModifyAsync(this, Discord, func, options); + public Task KickAsync(RequestOptions options = null) + => UserHelper.KickAsync(this, Discord, options); public ChannelPermissions GetPermissions(IGuildChannel channel) { diff --git a/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs b/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs index 17c24e7d2..4dabfaa1c 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs @@ -35,11 +35,21 @@ namespace Discord.Rest IsMfaEnabled = model.MfaEnabled.Value; } - public override async Task UpdateAsync() - => Update(await UserHelper.GetAsync(this, Discord)); - public Task ModifyAsync(Action func) - => UserHelper.ModifyAsync(this, Discord, func); + public override async Task UpdateAsync(RequestOptions options = null) + { + var model = await Discord.ApiClient.GetMyUserAsync(options); + if (model.Id != Id) + throw new InvalidOperationException("Unable to update this object using a different token."); + Update(model); + } + + public async Task ModifyAsync(Action func, RequestOptions options = null) + { + if (Id != Discord.CurrentUser.Id) + throw new InvalidOperationException("Unable to modify this object using a different token."); + await UserHelper.ModifyAsync(this, Discord, func, options); + } - Task ISelfUser.ModifyStatusAsync(Action func) { throw new NotSupportedException(); } + Task ISelfUser.ModifyStatusAsync(Action func, RequestOptions options) { throw new NotSupportedException(); } } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestUser.cs b/src/Discord.Net.Rest/Entities/Users/RestUser.cs index 46cd246bf..5e085b821 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestUser.cs @@ -39,20 +39,23 @@ namespace Discord.Rest if (model.Username.IsSpecified) Username = model.Username.Value; } - - public virtual async Task UpdateAsync() - => Update(await UserHelper.GetAsync(this, Discord)); - public Task CreateDMChannelAsync() - => UserHelper.CreateDMChannelAsync(this, Discord); + public virtual async Task UpdateAsync(RequestOptions options = null) + { + var model = await Discord.ApiClient.GetUserAsync(Id, options); + Update(model); + } + + public Task CreateDMChannelAsync(RequestOptions options = null) + => UserHelper.CreateDMChannelAsync(this, Discord, options); public override string ToString() => $"{Username}#{Discriminator}"; internal string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; //IUser - Task IUser.GetDMChannelAsync(CacheMode mode) + Task IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(null); - async Task IUser.CreateDMChannelAsync() - => await CreateDMChannelAsync(); + async Task IUser.CreateDMChannelAsync(RequestOptions options) + => await CreateDMChannelAsync(options); } } diff --git a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs index a7ee241f5..fee3fd876 100644 --- a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs +++ b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs @@ -1,53 +1,37 @@ using Discord.API.Rest; using System; using System.Threading.Tasks; -using MemberModel = Discord.API.GuildMember; -using Model = Discord.API.User; namespace Discord.Rest { internal static class UserHelper { - public static async Task GetAsync(IUser user, BaseDiscordClient client) + public static async Task ModifyAsync(ISelfUser user, BaseDiscordClient client, Action func, + RequestOptions options) { - return await client.ApiClient.GetUserAsync(user.Id); - } - public static async Task GetAsync(ISelfUser user, BaseDiscordClient client) - { - var model = await client.ApiClient.GetMyUserAsync(); - if (model.Id != user.Id) - throw new InvalidOperationException("Unable to update this object using a different token."); - return model; - } - public static async Task GetAsync(IGuildUser user, BaseDiscordClient client) - { - return await client.ApiClient.GetGuildMemberAsync(user.GuildId, user.Id); - } - public static async Task ModifyAsync(ISelfUser user, BaseDiscordClient client, Action func) - { - if (user.Id != client.CurrentUser.Id) - throw new InvalidOperationException("Unable to modify this object using a different token."); - var args = new ModifyCurrentUserParams(); func(args); - await client.ApiClient.ModifySelfAsync(args); + await client.ApiClient.ModifySelfAsync(args, options); } - public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, Action func) + public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, Action func, + RequestOptions options) { var args = new ModifyGuildMemberParams(); func(args); - await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args); + await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args, options); } - public static async Task KickAsync(IGuildUser user, BaseDiscordClient client) + public static async Task KickAsync(IGuildUser user, BaseDiscordClient client, + RequestOptions options) { - await client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id); + await client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id, options); } - public static async Task CreateDMChannelAsync(IUser user, BaseDiscordClient client) + public static async Task CreateDMChannelAsync(IUser user, BaseDiscordClient client, + RequestOptions options) { var args = new CreateDMChannelParams(user.Id); - return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args)); + return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args, options)); } } } diff --git a/src/Discord.Net.Rest/Utils/TypingNotifier.cs b/src/Discord.Net.Rest/Utils/TypingNotifier.cs index 28da4fb75..62d19b5a1 100644 --- a/src/Discord.Net.Rest/Utils/TypingNotifier.cs +++ b/src/Discord.Net.Rest/Utils/TypingNotifier.cs @@ -9,12 +9,14 @@ namespace Discord.Rest private readonly BaseDiscordClient _client; private readonly CancellationTokenSource _cancelToken; private readonly ulong _channelId; + private readonly RequestOptions _options; - public TypingNotifier(BaseDiscordClient discord, IChannel channel) + public TypingNotifier(BaseDiscordClient discord, IChannel channel, RequestOptions options) { _client = discord; _cancelToken = new CancellationTokenSource(); _channelId = channel.Id; + _options = options; var _ = Run(); } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs index 00833717a..7ba08544b 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs @@ -11,11 +11,11 @@ namespace Discord.WebSocket IReadOnlyCollection CachedMessages { get; } /// Sends a message to this message channel. - new Task SendMessageAsync(string text, bool isTTS = false); + new Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. - new Task SendFileAsync(string filePath, string text = null, bool isTTS = false); + new Task SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. - new Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false); + new Task SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, RequestOptions options = null); SocketMessage GetCachedMessage(ulong id); /// Gets the last N messages from this message channel. @@ -25,6 +25,6 @@ namespace Discord.WebSocket /// Gets a collection of messages in this channel. IReadOnlyCollection GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); /// Gets a collection of pinned messages in this channel. - new Task> GetPinnedMessagesAsync(); + new Task> GetPinnedMessagesAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs index 86a649367..998e576f2 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs @@ -39,9 +39,9 @@ namespace Discord.WebSocket internal SocketChannel Clone() => MemberwiseClone() as SocketChannel; //IChannel - Task IChannel.GetUserAsync(ulong id, CacheMode mode) + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); //Overridden - IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => AsyncEnumerable.Empty>(); //Overridden } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs index 47c290452..887499c59 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs @@ -9,7 +9,7 @@ namespace Discord.WebSocket internal static class SocketChannelHelper { public static IAsyncEnumerable> GetMessagesAsync(SocketChannel channel, DiscordSocketClient discord, MessageCache messages, - ulong? fromMessageId, Direction dir, int limit, CacheMode mode) + ulong? fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options) { IReadOnlyCollection cachedMessages; IAsyncEnumerable> result; @@ -28,7 +28,7 @@ namespace Discord.WebSocket fromMessageId = cachedMessages.Min(x => x.Id); else fromMessageId = cachedMessages.Max(x => x.Id); - var downloadedMessages = ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit); + var downloadedMessages = ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit, options); return result.Concat(downloadedMessages); } public static IReadOnlyCollection GetCachedMessages(SocketChannel channel, DiscordSocketClient discord, MessageCache messages, diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs index 872973627..375dce605 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs @@ -38,46 +38,46 @@ namespace Discord.WebSocket Recipient.Update(state, model.Recipients.Value[0]); } - public Task CloseAsync() - => ChannelHelper.DeleteAsync(this, Discord); + public Task CloseAsync(RequestOptions options = null) + => ChannelHelper.DeleteAsync(this, Discord, options); //Messages public SocketMessage GetCachedMessage(ulong id) => _messages?.Get(id); - public async Task GetMessageAsync(ulong id) + public async Task GetMessageAsync(ulong id, RequestOptions options = null) { IMessage msg = _messages?.Get(id); if (msg == null) - msg = await ChannelHelper.GetMessageAsync(this, Discord, id); + msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options); return msg; } - public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload); - public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload); - public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload); + public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); + 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); + 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); public IReadOnlyCollection GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch) => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, null, Direction.Before, limit); public IReadOnlyCollection GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessageId, dir, limit); public IReadOnlyCollection GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessage.Id, dir, limit); - public Task> GetPinnedMessagesAsync() - => ChannelHelper.GetPinnedMessagesAsync(this, Discord); + public Task> GetPinnedMessagesAsync(RequestOptions options = null) + => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); - public Task SendMessageAsync(string text, bool isTTS) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS); - public Task SendFileAsync(string filePath, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS); - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS); + public Task SendMessageAsync(string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options); + public Task SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options); + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options); - public Task DeleteMessagesAsync(IEnumerable messages) - => ChannelHelper.DeleteMessagesAsync(this, Discord, messages); + public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) + => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); - public IDisposable EnterTypingState() - => ChannelHelper.EnterTypingState(this, Discord); + public IDisposable EnterTypingState(RequestOptions options = null) + => ChannelHelper.EnterTypingState(this, Discord, options); internal void AddMessage(SocketMessage msg) => _messages.Add(msg); @@ -111,36 +111,36 @@ namespace Discord.WebSocket //IPrivateChannel IReadOnlyCollection IPrivateChannel.Recipients => ImmutableArray.Create(Recipient); - + //IMessageChannel - async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode) + async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id); + return await GetMessageAsync(id, options); else return GetCachedMessage(id); } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode); - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode); - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode); - async Task> IMessageChannel.GetPinnedMessagesAsync() - => await GetPinnedMessagesAsync().ConfigureAwait(false); - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS) - => await SendFileAsync(filePath, text, isTTS); - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => await SendFileAsync(stream, filename, text, isTTS); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS) - => await SendMessageAsync(text, isTTS); - IDisposable IMessageChannel.EnterTypingState() - => EnterTypingState(); + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) + => SocketChannelHelper.GetMessagesAsync(this, Discord, _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); + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) + => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode, options); + async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) + => await GetPinnedMessagesAsync(options).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(filePath, text, isTTS, options); + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(stream, filename, text, isTTS, options); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) + => await SendMessageAsync(text, isTTS, options); + IDisposable IMessageChannel.EnterTypingState(RequestOptions options) + => EnterTypingState(options); //IChannel - Task IChannel.GetUserAsync(ulong id, CacheMode mode) + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); - IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs index a096e169e..732296ff0 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs @@ -61,46 +61,46 @@ namespace Discord.WebSocket _users = users; } - public Task LeaveAsync() - => ChannelHelper.DeleteAsync(this, Discord); + public Task LeaveAsync(RequestOptions options = null) + => ChannelHelper.DeleteAsync(this, Discord, options); //Messages public SocketMessage GetCachedMessage(ulong id) => _messages?.Get(id); - public async Task GetMessageAsync(ulong id) + public async Task GetMessageAsync(ulong id, RequestOptions options = null) { IMessage msg = _messages?.Get(id); if (msg == null) - msg = await ChannelHelper.GetMessageAsync(this, Discord, id); + msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options); return msg; } - public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload); - public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload); - public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload); + public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); + 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); + 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); public IReadOnlyCollection GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch) => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, null, Direction.Before, limit); public IReadOnlyCollection GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessageId, dir, limit); public IReadOnlyCollection GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessage.Id, dir, limit); - public Task> GetPinnedMessagesAsync() - => ChannelHelper.GetPinnedMessagesAsync(this, Discord); + public Task> GetPinnedMessagesAsync(RequestOptions options = null) + => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); - public Task SendMessageAsync(string text, bool isTTS) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS); - public Task SendFileAsync(string filePath, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS); - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS); + public Task SendMessageAsync(string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options); + public Task SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options); + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options); - public Task DeleteMessagesAsync(IEnumerable messages) - => ChannelHelper.DeleteMessagesAsync(this, Discord, messages); + public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) + => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); - public IDisposable EnterTypingState() - => ChannelHelper.EnterTypingState(this, Discord); + public IDisposable EnterTypingState(RequestOptions options = null) + => ChannelHelper.EnterTypingState(this, Discord, options); internal void AddMessage(SocketMessage msg) => _messages.Add(msg); @@ -176,35 +176,34 @@ namespace Discord.WebSocket IReadOnlyCollection IPrivateChannel.Recipients => Recipients; //IMessageChannel - async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode) + async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id); + return await GetMessageAsync(id, options); else return GetCachedMessage(id); } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode); - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode); - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode); - async Task> IMessageChannel.GetPinnedMessagesAsync() - => await GetPinnedMessagesAsync(); - - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS) - => await SendFileAsync(filePath, text, isTTS); - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => await SendFileAsync(stream, filename, text, isTTS); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS) - => await SendMessageAsync(text, isTTS); - IDisposable IMessageChannel.EnterTypingState() - => EnterTypingState(); + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) + => SocketChannelHelper.GetMessagesAsync(this, Discord, _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); + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) + => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode, options); + async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) + => await GetPinnedMessagesAsync(options).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(filePath, text, isTTS, options); + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(stream, filename, text, isTTS, options); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) + => await SendMessageAsync(text, isTTS, options); + IDisposable IMessageChannel.EnterTypingState(RequestOptions options) + => EnterTypingState(options); //IChannel - Task IChannel.GetUserAsync(ulong id, CacheMode mode) + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); - IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index c3a33c3ea..637f7c8ff 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -51,10 +51,10 @@ namespace Discord.WebSocket _overwrites = newOverwrites.ToImmutable(); } - public Task ModifyAsync(Action func) - => ChannelHelper.ModifyAsync(this, Discord, func); - public Task DeleteAsync() - => ChannelHelper.DeleteAsync(this, Discord); + public Task ModifyAsync(Action func, RequestOptions options = null) + => ChannelHelper.ModifyAsync(this, Discord, func, options); + public Task DeleteAsync(RequestOptions options = null) + => ChannelHelper.DeleteAsync(this, Discord, options); public OverwritePermissions? GetPermissionOverwrite(IUser user) { @@ -74,19 +74,19 @@ namespace Discord.WebSocket } return null; } - public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms) + public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null) { - await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms).ConfigureAwait(false); + await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options).ConfigureAwait(false); _overwrites = _overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = user.Id, TargetType = PermissionTarget.User })); } - public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms) + public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null) { - await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms).ConfigureAwait(false); + await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options).ConfigureAwait(false); _overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = role.Id, TargetType = PermissionTarget.Role })); } - public async Task RemovePermissionOverwriteAsync(IUser user) + public async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) { - await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user).ConfigureAwait(false); + await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false); for (int i = 0; i < _overwrites.Length; i++) { @@ -97,9 +97,9 @@ namespace Discord.WebSocket } } } - public async Task RemovePermissionOverwriteAsync(IRole role) + public async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) { - await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role).ConfigureAwait(false); + await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false); for (int i = 0; i < _overwrites.Length; i++) { @@ -111,10 +111,10 @@ namespace Discord.WebSocket } } - public async Task> GetInvitesAsync() - => await ChannelHelper.GetInvitesAsync(this, Discord); - public async Task CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true) - => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary); + public async Task> GetInvitesAsync(RequestOptions options = null) + => await ChannelHelper.GetInvitesAsync(this, Discord, options); + public async Task CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true, RequestOptions options = null) + => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options); public new abstract SocketGuildUser GetUser(ulong id); @@ -128,33 +128,33 @@ namespace Discord.WebSocket //IGuildChannel ulong IGuildChannel.GuildId => Guild.Id; - async Task> IGuildChannel.GetInvitesAsync() - => await GetInvitesAsync(); - async Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary) - => await CreateInviteAsync(maxAge, maxUses, isTemporary); + async Task> IGuildChannel.GetInvitesAsync(RequestOptions options) + => await GetInvitesAsync(options); + async Task IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, RequestOptions options) + => await CreateInviteAsync(maxAge, maxUses, isTemporary, options); OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role) => GetPermissionOverwrite(role); OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user) => GetPermissionOverwrite(user); - async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions) - => await AddPermissionOverwriteAsync(role, permissions); - async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions) - => await AddPermissionOverwriteAsync(user, permissions); - async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role) - => await RemovePermissionOverwriteAsync(role); - async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user) - => await RemovePermissionOverwriteAsync(user); + async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options) + => await AddPermissionOverwriteAsync(role, permissions, options); + async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options) + => await AddPermissionOverwriteAsync(user, permissions, options); + async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options) + => await RemovePermissionOverwriteAsync(role, options); + async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options) + => await RemovePermissionOverwriteAsync(user, options); - IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); - Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode) + Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); //IChannel - IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); //Overriden in Text/Voice //TODO: Does this actually override? - Task IChannel.GetUserAsync(ulong id, CacheMode mode) + Task IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); //Overriden in Text/Voice //TODO: Does this actually override? } } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs index 2e894afde..079ddfd10 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -44,46 +44,46 @@ namespace Discord.WebSocket Topic = model.Topic.Value; } - public Task ModifyAsync(Action func) - => ChannelHelper.ModifyAsync(this, Discord, func); + public Task ModifyAsync(Action func, RequestOptions options = null) + => ChannelHelper.ModifyAsync(this, Discord, func, options); //Messages public SocketMessage GetCachedMessage(ulong id) => _messages?.Get(id); - public async Task GetMessageAsync(ulong id) + public async Task GetMessageAsync(ulong id, RequestOptions options = null) { IMessage msg = _messages?.Get(id); if (msg == null) - msg = await ChannelHelper.GetMessageAsync(this, Discord, id); + msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options); return msg; } - public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload); - public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload); - public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload); + public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) + => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); + 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); + 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); public IReadOnlyCollection GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch) => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, null, Direction.Before, limit); public IReadOnlyCollection GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessageId, dir, limit); public IReadOnlyCollection GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) => SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessage.Id, dir, limit); - public Task> GetPinnedMessagesAsync() - => ChannelHelper.GetPinnedMessagesAsync(this, Discord); + public Task> GetPinnedMessagesAsync(RequestOptions options = null) + => ChannelHelper.GetPinnedMessagesAsync(this, Discord, options); - public Task SendMessageAsync(string text, bool isTTS) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS); - public Task SendFileAsync(string filePath, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS); - public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS); + public Task SendMessageAsync(string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options); + public Task SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options); + public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null) + => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options); - public Task DeleteMessagesAsync(IEnumerable messages) - => ChannelHelper.DeleteMessagesAsync(this, Discord, messages); + public Task DeleteMessagesAsync(IEnumerable messages, RequestOptions options = null) + => ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options); - public IDisposable EnterTypingState() - => ChannelHelper.EnterTypingState(this, Discord); + public IDisposable EnterTypingState(RequestOptions options = null) + => ChannelHelper.EnterTypingState(this, Discord, options); internal void AddMessage(SocketMessage msg) => _messages.Add(msg); @@ -108,34 +108,34 @@ namespace Discord.WebSocket internal new SocketTextChannel Clone() => MemberwiseClone() as SocketTextChannel; //IGuildChannel - Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode) + Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); - IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); //IMessageChannel - async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode) + async Task IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetMessageAsync(id); + return await GetMessageAsync(id, options); else return GetCachedMessage(id); } - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode); - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode); - IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode) - => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode); - async Task> IMessageChannel.GetPinnedMessagesAsync() - => await GetPinnedMessagesAsync().ConfigureAwait(false); - async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS) - => await SendFileAsync(filePath, text, isTTS); - async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS) - => await SendFileAsync(stream, filename, text, isTTS); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS) - => await SendMessageAsync(text, isTTS); - IDisposable IMessageChannel.EnterTypingState() - => EnterTypingState(); + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options) + => SocketChannelHelper.GetMessagesAsync(this, Discord, _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); + IAsyncEnumerable> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options) + => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode, options); + async Task> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) + => await GetPinnedMessagesAsync(options).ConfigureAwait(false); + async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(filePath, text, isTTS, options); + async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) + => await SendFileAsync(stream, filename, text, isTTS, options); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) + => await SendMessageAsync(text, isTTS, options); + IDisposable IMessageChannel.EnterTypingState(RequestOptions options) + => EnterTypingState(options); } } \ No newline at end of file diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs index 62f46cf60..b311f3c01 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs @@ -38,8 +38,8 @@ namespace Discord.WebSocket UserLimit = model.UserLimit.Value; } - public Task ModifyAsync(Action func) - => ChannelHelper.ModifyAsync(this, Discord, func); + public Task ModifyAsync(Action func, RequestOptions options = null) + => ChannelHelper.ModifyAsync(this, Discord, func, options); public override SocketGuildUser GetUser(ulong id) { @@ -56,9 +56,9 @@ namespace Discord.WebSocket Task IVoiceChannel.ConnectAsync() { throw new NotSupportedException(); } //IGuildChannel - Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode) + Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); - IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode) + IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) => ImmutableArray.Create>(Users).ToAsyncEnumerable(); } } diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index 3ac802434..f5a24c536 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -241,34 +241,34 @@ namespace Discord.WebSocket } //General - public Task DeleteAsync() - => GuildHelper.DeleteAsync(this, Discord); + public Task DeleteAsync(RequestOptions options) + => GuildHelper.DeleteAsync(this, Discord, options); - public Task ModifyAsync(Action func) - => GuildHelper.ModifyAsync(this, Discord, func); - public Task ModifyEmbedAsync(Action func) - => GuildHelper.ModifyEmbedAsync(this, Discord, func); - public Task ModifyChannelsAsync(IEnumerable args) - => GuildHelper.ModifyChannelsAsync(this, Discord, args); - public Task ModifyRolesAsync(IEnumerable args) - => GuildHelper.ModifyRolesAsync(this, Discord, args); + public Task ModifyAsync(Action func, RequestOptions options = null) + => GuildHelper.ModifyAsync(this, Discord, func, options); + public Task ModifyEmbedAsync(Action func, RequestOptions options = null) + => GuildHelper.ModifyEmbedAsync(this, Discord, func, options); + public Task ModifyChannelsAsync(IEnumerable args, RequestOptions options = null) + => GuildHelper.ModifyChannelsAsync(this, Discord, args, options); + public Task ModifyRolesAsync(IEnumerable args, RequestOptions options = null) + => GuildHelper.ModifyRolesAsync(this, Discord, args, options); - public Task LeaveAsync() - => GuildHelper.LeaveAsync(this, Discord); + public Task LeaveAsync(RequestOptions options = null) + => GuildHelper.LeaveAsync(this, Discord, options); //Bans - public Task> GetBansAsync() - => GuildHelper.GetBansAsync(this, Discord); + public Task> GetBansAsync(RequestOptions options = null) + => GuildHelper.GetBansAsync(this, Discord, options); - public Task AddBanAsync(IUser user, int pruneDays = 0) - => GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays); - public Task AddBanAsync(ulong userId, int pruneDays = 0) - => GuildHelper.AddBanAsync(this, Discord, userId, pruneDays); + public Task AddBanAsync(IUser user, int pruneDays = 0, RequestOptions options = null) + => GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, options); + public Task AddBanAsync(ulong userId, int pruneDays = 0, RequestOptions options = null) + => GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, options); - public Task RemoveBanAsync(IUser user) - => GuildHelper.RemoveBanAsync(this, Discord, user.Id); - public Task RemoveBanAsync(ulong userId) - => GuildHelper.RemoveBanAsync(this, Discord, userId); + public Task RemoveBanAsync(IUser user, RequestOptions options = null) + => GuildHelper.RemoveBanAsync(this, Discord, user.Id, options); + public Task RemoveBanAsync(ulong userId, RequestOptions options = null) + => GuildHelper.RemoveBanAsync(this, Discord, userId, options); //Channels public SocketGuildChannel GetChannel(ulong id) @@ -278,10 +278,10 @@ namespace Discord.WebSocket return channel; return null; } - public Task CreateTextChannelAsync(string name) - => GuildHelper.CreateTextChannelAsync(this, Discord, name); - public Task CreateVoiceChannelAsync(string name) - => GuildHelper.CreateVoiceChannelAsync(this, Discord, name); + public Task CreateTextChannelAsync(string name, RequestOptions options = null) + => GuildHelper.CreateTextChannelAsync(this, Discord, name, options); + public Task CreateVoiceChannelAsync(string name, RequestOptions options = null) + => GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options); internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model) { var channel = SocketGuildChannel.Create(this, state, model); @@ -297,14 +297,14 @@ namespace Discord.WebSocket } //Integrations - public Task> GetIntegrationsAsync() - => GuildHelper.GetIntegrationsAsync(this, Discord); - public Task CreateIntegrationAsync(ulong id, string type) - => GuildHelper.CreateIntegrationAsync(this, Discord, id, type); + public Task> GetIntegrationsAsync(RequestOptions options = null) + => GuildHelper.GetIntegrationsAsync(this, Discord, options); + public Task CreateIntegrationAsync(ulong id, string type, RequestOptions options = null) + => GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options); //Invites - public Task> GetInvitesAsync() - => GuildHelper.GetInvitesAsync(this, Discord); + public Task> GetInvitesAsync(RequestOptions options = null) + => GuildHelper.GetInvitesAsync(this, Discord, options); //Roles public SocketRole GetRole(ulong id) @@ -314,8 +314,9 @@ namespace Discord.WebSocket return value; return null; } - public Task CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), bool isHoisted = false) - => GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted); + 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); internal SocketRole AddRole(RoleModel model) { var role = SocketRole.Create(this, Discord.State, model); @@ -345,8 +346,8 @@ namespace Discord.WebSocket return member; return null; } - public Task PruneUsersAsync(int days = 30, bool simulate = false) - => GuildHelper.PruneUsersAsync(this, Discord, days, simulate); + public Task PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null) + => GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options); internal SocketGuildUser AddOrUpdateUser(MemberModel model) { @@ -532,36 +533,36 @@ namespace Discord.WebSocket IRole IGuild.EveryoneRole => EveryoneRole; IReadOnlyCollection IGuild.Roles => Roles; - async Task> IGuild.GetBansAsync() - => await GetBansAsync(); + async Task> IGuild.GetBansAsync(RequestOptions options) + => await GetBansAsync(options); - Task> IGuild.GetChannelsAsync(CacheMode mode) + Task> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(Channels); - Task IGuild.GetChannelAsync(ulong id, CacheMode mode) + Task IGuild.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetChannel(id)); - async Task IGuild.CreateTextChannelAsync(string name) - => await CreateTextChannelAsync(name); - async Task IGuild.CreateVoiceChannelAsync(string name) - => await CreateVoiceChannelAsync(name); + async Task IGuild.CreateTextChannelAsync(string name, RequestOptions options) + => await CreateTextChannelAsync(name, options); + async Task IGuild.CreateVoiceChannelAsync(string name, RequestOptions options) + => await CreateVoiceChannelAsync(name, options); - async Task> IGuild.GetIntegrationsAsync() - => await GetIntegrationsAsync(); - async Task IGuild.CreateIntegrationAsync(ulong id, string type) - => await CreateIntegrationAsync(id, type); + async Task> IGuild.GetIntegrationsAsync(RequestOptions options) + => await GetIntegrationsAsync(options); + async Task IGuild.CreateIntegrationAsync(ulong id, string type, RequestOptions options) + => await CreateIntegrationAsync(id, type, options); - async Task> IGuild.GetInvitesAsync() - => await GetInvitesAsync(); + async Task> IGuild.GetInvitesAsync(RequestOptions options) + => await GetInvitesAsync(options); IRole IGuild.GetRole(ulong id) => GetRole(id); - async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted) - => await CreateRoleAsync(name, permissions, color, isHoisted); + async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) + => await CreateRoleAsync(name, permissions, color, isHoisted, options); - Task> IGuild.GetUsersAsync(CacheMode mode) + Task> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(Users); - Task IGuild.GetUserAsync(ulong id, CacheMode mode) + Task IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); - Task IGuild.GetCurrentUserAsync(CacheMode mode) + Task IGuild.GetCurrentUserAsync(CacheMode mode, RequestOptions options) => Task.FromResult(GetCurrentUser()); Task IGuild.DownloadUsersAsync() { throw new NotSupportedException(); } } diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs index 683f6ec3d..cb88f0430 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs @@ -112,15 +112,15 @@ namespace Discord.WebSocket } } - public Task ModifyAsync(Action func) - => MessageHelper.ModifyAsync(this, Discord, func); - public Task DeleteAsync() - => MessageHelper.DeleteAsync(this, Discord); - - public Task PinAsync() - => MessageHelper.PinAsync(this, Discord); - public Task UnpinAsync() - => MessageHelper.UnpinAsync(this, Discord); + public Task ModifyAsync(Action func, RequestOptions options = null) + => MessageHelper.ModifyAsync(this, Discord, func, options); + public Task DeleteAsync(RequestOptions options = null) + => MessageHelper.DeleteAsync(this, Discord, options); + + public Task PinAsync(RequestOptions options = null) + => MessageHelper.PinAsync(this, Discord, options); + public Task UnpinAsync(RequestOptions options = null) + => MessageHelper.UnpinAsync(this, Discord, options); public string Resolve(UserMentionHandling userHandling = UserMentionHandling.Name, ChannelMentionHandling channelHandling = ChannelMentionHandling.Name, RoleMentionHandling roleHandling = RoleMentionHandling.Name, EveryoneMentionHandling everyoneHandling = EveryoneMentionHandling.Ignore) diff --git a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs index 1cb2e2812..7a1f0b3bb 100644 --- a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs +++ b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs @@ -43,10 +43,10 @@ namespace Discord.WebSocket Permissions = new GuildPermissions(model.Permissions); } - public Task ModifyAsync(Action func) - => RoleHelper.ModifyAsync(this, Discord, func); - public Task DeleteAsync() - => RoleHelper.DeleteAsync(this, Discord); + public Task ModifyAsync(Action func, RequestOptions options) + => RoleHelper.ModifyAsync(this, Discord, func, options); + public Task DeleteAsync(RequestOptions options) + => RoleHelper.DeleteAsync(this, Discord, options); public override string ToString() => Name; private string DebuggerDisplay => $"{Name} ({Id})"; diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs index 6573e6d0d..00972f51a 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs @@ -82,10 +82,10 @@ namespace Discord.WebSocket _roleIds = roles.ToImmutable(); } - public Task ModifyAsync(Action func) - => UserHelper.ModifyAsync(this, Discord, func); - public Task KickAsync() - => UserHelper.KickAsync(this, Discord); + public Task ModifyAsync(Action func, RequestOptions options = null) + => UserHelper.ModifyAsync(this, Discord, func, options); + public Task KickAsync(RequestOptions options = null) + => UserHelper.KickAsync(this, Discord, options); public ChannelPermissions GetPermissions(IGuildChannel channel) => new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, GuildPermissions.RawValue)); @@ -97,7 +97,7 @@ namespace Discord.WebSocket IReadOnlyCollection IGuildUser.RoleIds => RoleIds; //IUser - Task IUser.GetDMChannelAsync(CacheMode mode) + Task IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(GlobalUser.DMChannel); //IVoiceState diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketPresence.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketPresence.cs index 8dfae8d49..629aa2093 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketPresence.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketPresence.cs @@ -7,17 +7,17 @@ namespace Discord.WebSocket [DebuggerDisplay(@"{DebuggerDisplay,nq}")] public struct SocketPresence : IPresence { - public Game? Game { get; } public UserStatus Status { get; } + public Game? Game { get; } - internal SocketPresence(Game? game, UserStatus status) + internal SocketPresence(UserStatus status, Game? game) { - Game = game; Status = status; + Game = game; } internal static SocketPresence Create(Model model) { - return new SocketPresence(model.Game != null ? Discord.Game.Create(model.Game) : (Game?)null, model.Status); + return new SocketPresence(model.Status, model.Game != null ? Discord.Game.Create(model.Game) : (Game?)null); } public override string ToString() => Status.ToString(); diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 574b508ea..76af76022 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -40,17 +40,17 @@ namespace Discord.WebSocket Presence = SocketPresence.Create(model); } - public Task CreateDMChannelAsync() - => UserHelper.CreateDMChannelAsync(this, Discord); + public Task CreateDMChannelAsync(RequestOptions options = null) + => UserHelper.CreateDMChannelAsync(this, Discord, options); public override string ToString() => $"{Username}#{Discriminator}"; internal string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; internal SocketUser Clone() => MemberwiseClone() as SocketUser; //IUser - Task IUser.GetDMChannelAsync(CacheMode mode) + Task IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) => Task.FromResult(GlobalUser.DMChannel); - async Task IUser.CreateDMChannelAsync() - => await CreateDMChannelAsync(); + async Task IUser.CreateDMChannelAsync(RequestOptions options) + => await CreateDMChannelAsync(options); } }