diff --git a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs index 992bd71fca..fc34c9981a 100644 --- a/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs @@ -57,6 +57,20 @@ public interface IGuildChannel : IChannel, IDeletable /// A task that represents the asynchronous modification operation. /// Task ModifyAsync(Action func, RequestOptions options = null); + /// + /// Modifies this guild channel. + /// + /// + /// This method modifies the current guild channel with the specified properties. To see an example of this + /// method and what properties are available, please refer to . + /// + /// The delegate containing the properties to modify the channel with. + /// An object to carry state into the delegate to prevent closures. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyAsync(Action func, TState state, RequestOptions options = null); /// /// Gets the permission overwrite for a specific role. diff --git a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs index 29c764e3f0..63fa1d5320 100644 --- a/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/ITextChannel.cs @@ -83,7 +83,18 @@ public interface ITextChannel : IMessageChannel, IMentionable, INestedChannel /// /// Task ModifyAsync(Action func, RequestOptions options = null); - + /// + /// Modifies this text channel. + /// + /// The delegate containing the properties to modify the channel with. + /// An object to carry state into the delegate to prevent closures. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + /// + Task ModifyAsync(Action func, TState state, RequestOptions options = null); + /// /// Creates a webhook in this text channel. /// diff --git a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs index 9c2d008eea..79eba796a1 100644 --- a/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs @@ -35,5 +35,16 @@ public interface IVoiceChannel : INestedChannel, IAudioChannel /// /// Task ModifyAsync(Action func, RequestOptions options = null); + /// + /// Modifies this voice channel. + /// + /// The properties to modify the channel with. + /// An object to carry state into the delegate to prevent closures. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + /// + Task ModifyAsync(Action func, TState state, RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index d463d86dff..1e7eaffa9f 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -259,6 +259,16 @@ public interface IGuild : IDeletable, ISnowflakeEntity /// Task ModifyAsync(Action func, RequestOptions options = null); /// + /// Modifies this guild. + /// + /// The delegate containing the properties to modify the guild with. + /// An object to carry state into the delegate to prevent closures. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyAsync(Action func, TState state, RequestOptions options = null); + /// /// Modifies this guild's embed channel. /// /// The delegate containing the properties to modify the guild widget with. @@ -268,6 +278,16 @@ public interface IGuild : IDeletable, ISnowflakeEntity /// Task ModifyEmbedAsync(Action func, RequestOptions options = null); /// + /// Modifies this guild's embed channel. + /// + /// The delegate containing the properties to modify the guild widget with. + /// An object to carry state into the delegate to prevent closures. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyEmbedAsync(Action func, TState state, RequestOptions options = null); + /// /// Bulk-modifies the order of channels in this guild. /// /// The properties used to modify the channel positions with. diff --git a/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs b/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs index be2523b215..47f3f755e6 100644 --- a/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs +++ b/src/Discord.Net.Core/Entities/Messages/IUserMessage.cs @@ -29,6 +29,26 @@ public interface IUserMessage : IMessage /// Task ModifyAsync(Action func, RequestOptions options = null); /// + /// Modifies this message. + /// + /// + /// This method modifies this message with the specified properties. To see an example of this + /// method and what properties are available, please refer to . + /// + /// + /// The following example replaces the content of the message with Hello World!. + /// + /// await msg.ModifyAsync((x, s) => x.Content = s, "Hello World!"); + /// + /// + /// A delegate containing the properties to modify the message with. + /// An object to carry state into the delegate to prevent closures. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyAsync(Action func, TState state, RequestOptions options = null); + /// /// Modifies the suppression of this message. /// /// diff --git a/src/Discord.Net.Core/Entities/Roles/IRole.cs b/src/Discord.Net.Core/Entities/Roles/IRole.cs index 66556fc2c3..6ffd4d2b2f 100644 --- a/src/Discord.Net.Core/Entities/Roles/IRole.cs +++ b/src/Discord.Net.Core/Entities/Roles/IRole.cs @@ -79,5 +79,19 @@ public interface IRole : ISnowflakeEntity, IDeletable, IMentionable, IComparable /// A task that represents the asynchronous modification operation. /// Task ModifyAsync(Action func, RequestOptions options = null); + /// + /// Modifies this role. + /// + /// + /// This method modifies this role with the specified properties. To see an example of this + /// method and what properties are available, please refer to . + /// + /// A delegate containing the properties to modify the role with. + /// An object to carry state into the delegate to prevent closures. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyAsync(Action func, TState state, RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Users/IGuildUser.cs b/src/Discord.Net.Core/Entities/Users/IGuildUser.cs index ae682afd58..9fea4fa3e4 100644 --- a/src/Discord.Net.Core/Entities/Users/IGuildUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IGuildUser.cs @@ -108,6 +108,20 @@ public interface IGuildUser : IUser, IVoiceState /// A task that represents the asynchronous modification operation. /// Task ModifyAsync(Action func, RequestOptions options = null); + /// + /// Modifies this user's properties in this guild. + /// + /// + /// This method modifies the current guild user with the specified properties. To see an example of this + /// method and what properties are available, please refer to . + /// + /// The delegate containing the properties to modify the user with. + /// An object to carry state into the delegate to prevent closures. + /// The options to be used when sending the request. + /// + /// A task that represents the asynchronous modification operation. + /// + Task ModifyAsync(Action func, TState state, RequestOptions options = null); /// /// Adds the specified role to this user in the guild. diff --git a/src/Discord.Net.Core/Entities/Users/ISelfUser.cs b/src/Discord.Net.Core/Entities/Users/ISelfUser.cs index 04c6552127..88cf31ce8f 100644 --- a/src/Discord.Net.Core/Entities/Users/ISelfUser.cs +++ b/src/Discord.Net.Core/Entities/Users/ISelfUser.cs @@ -59,5 +59,9 @@ public interface ISelfUser : IUser /// Modifies the user's properties. /// Task ModifyAsync(Action func, RequestOptions options = null); + /// + /// Modifies the user's properties. + /// + Task ModifyAsync(Action func, TState state, RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs b/src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs index b2d017316f..1f2fcfb852 100644 --- a/src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs +++ b/src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; namespace Discord @@ -53,5 +53,9 @@ public interface IWebhook : IDeletable, ISnowflakeEntity /// Modifies this webhook. /// Task ModifyAsync(Action func, RequestOptions options = null); + /// + /// Modifies this webhook. + /// + Task ModifyAsync(Action func, TState state, RequestOptions options = null); } } diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index 5fb150cda7..bb71343572 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -18,12 +18,13 @@ internal static class ChannelHelper { await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false); } - public static async Task ModifyAsync(IGuildChannel channel, BaseDiscordClient client, - Action func, + public static async Task ModifyAsync(IGuildChannel channel, BaseDiscordClient client, + Action func, + TState state, RequestOptions options) { var args = new GuildChannelProperties(); - func(args); + func(args, state); var apiArgs = new API.Rest.ModifyGuildChannelParams { Name = args.Name, @@ -32,12 +33,13 @@ internal static class ChannelHelper }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } - public static async Task ModifyAsync(ITextChannel channel, BaseDiscordClient client, - Action func, + public static async Task ModifyAsync(ITextChannel channel, BaseDiscordClient client, + Action func, + TState state, RequestOptions options) { var args = new TextChannelProperties(); - func(args); + func(args, state); var apiArgs = new API.Rest.ModifyTextChannelParams { Name = args.Name, @@ -49,12 +51,13 @@ internal static class ChannelHelper }; return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); } - public static async Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client, - Action func, + public static async Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client, + Action func, + TState state, RequestOptions options) { var args = new VoiceChannelProperties(); - func(args); + func(args, state); var apiArgs = new API.Rest.ModifyVoiceChannelParams { Bitrate = args.Bitrate, diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index fdfee39ea0..9d5be66f03 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -65,9 +65,12 @@ public override async Task UpdateAsync(RequestOptions options = null) Update(model); } /// - public async Task ModifyAsync(Action func, RequestOptions options = null) + public Task ModifyAsync(Action func, RequestOptions options = null) + => ModifyAsync((props, f) => f(props), func, options); + /// + public async Task ModifyAsync(Action func, TState state, RequestOptions options = null) { - var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); + var model = await ChannelHelper.ModifyAsync(this, Discord, func, state, options).ConfigureAwait(false); Update(model); } /// diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs index dc86327bd3..c6e4ad1e11 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs @@ -47,9 +47,12 @@ internal override void Update(Model model) } /// - public async Task ModifyAsync(Action func, RequestOptions options = null) + public Task ModifyAsync(Action func, RequestOptions options = null) + => ModifyAsync((props, f) => f(props), func, options); + /// + public async Task ModifyAsync(Action func, TState state, RequestOptions options = null) { - var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); + var model = await ChannelHelper.ModifyAsync(this, Discord, func, state, options).ConfigureAwait(false); Update(model); } diff --git a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs index 3f3aa96c6c..a9dd232b72 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs @@ -41,9 +41,12 @@ internal override void Update(Model model) } /// - public async Task ModifyAsync(Action func, RequestOptions options = null) + public Task ModifyAsync(Action func, RequestOptions options = null) + => ModifyAsync((props, f) => f(props), func, options); + /// + public async Task ModifyAsync(Action func, TState state, RequestOptions options = null) { - var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); + var model = await ChannelHelper.ModifyAsync(this, Discord, func, state, options).ConfigureAwait(false); Update(model); } diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 3f5565ccf6..3c535ce5dd 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -15,13 +15,13 @@ internal static class GuildHelper { //General /// is null. - public static async Task ModifyAsync(IGuild guild, BaseDiscordClient client, - Action func, RequestOptions options) + public static async Task ModifyAsync(IGuild guild, BaseDiscordClient client, + Action func, TState state, RequestOptions options) { if (func == null) throw new ArgumentNullException(nameof(func)); var args = new GuildProperties(); - func(args); + func(args, state); var apiArgs = new API.Rest.ModifyGuildParams { @@ -71,13 +71,13 @@ internal static class GuildHelper return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false); } /// is null. - public static async Task ModifyEmbedAsync(IGuild guild, BaseDiscordClient client, - Action func, RequestOptions options) + public static async Task ModifyEmbedAsync(IGuild guild, BaseDiscordClient client, + Action func, TState state, RequestOptions options) { if (func == null) throw new ArgumentNullException(nameof(func)); var args = new GuildEmbedProperties(); - func(args); + func(args, state); var apiArgs = new API.Rest.ModifyGuildEmbedParams { Enabled = args.Enabled diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index cd142b1844..e2cafa8399 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -166,17 +166,25 @@ public Task DeleteAsync(RequestOptions options = null) /// /// is null. - public async Task ModifyAsync(Action func, RequestOptions options = null) + public Task ModifyAsync(Action func, RequestOptions options = null) + => ModifyAsync((props, f) => f(props), func, options); + /// + /// is null. + public async Task ModifyAsync(Action func, TState state, RequestOptions options = null) { - var model = await GuildHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); + var model = await GuildHelper.ModifyAsync(this, Discord, func, state, options).ConfigureAwait(false); Update(model); } /// /// is null. - public async Task ModifyEmbedAsync(Action func, RequestOptions options = null) + public Task ModifyEmbedAsync(Action func, RequestOptions options = null) + => ModifyEmbedAsync((props, f) => f(props), func, options); + /// + /// is null. + public async Task ModifyEmbedAsync(Action func, TState state, RequestOptions options = null) { - var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false); + var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, state, options).ConfigureAwait(false); Update(model); } diff --git a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs index ef6d9a14cb..f2632980f2 100644 --- a/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs +++ b/src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs @@ -13,14 +13,16 @@ internal static class MessageHelper { /// Only the author of a message may modify the message. /// Message content is too long, length must be less or equal to . - public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action func, + public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, + Action func, + TState state, RequestOptions options) { if (msg.Author.Id != client.CurrentUser.Id) throw new InvalidOperationException("Only the author of a message may modify the message."); var args = new MessageProperties(); - func(args); + func(args, state); var apiArgs = new API.Rest.ModifyMessageParams { diff --git a/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs b/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs index 7d652687ae..0b5290a35a 100644 --- a/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs +++ b/src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs @@ -124,9 +124,12 @@ internal override void Update(Model model) } /// - public async Task ModifyAsync(Action func, RequestOptions options = null) + public Task ModifyAsync(Action func, RequestOptions options = null) + => ModifyAsync((props, f) => f(props), func, options); + /// + public async Task ModifyAsync(Action func, TState state, RequestOptions options = null) { - var model = await MessageHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); + var model = await MessageHelper.ModifyAsync(this, Discord, func, state, options).ConfigureAwait(false); Update(model); } diff --git a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs index 7c1a3aaa2d..8d78d14d32 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RestRole.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RestRole.cs @@ -57,11 +57,13 @@ internal void Update(Model model) Color = new Color(model.Color); Permissions = new GuildPermissions(model.Permissions); } - /// - public async Task ModifyAsync(Action func, RequestOptions options = null) + public Task ModifyAsync(Action func, RequestOptions options = null) + => ModifyAsync((props, f) => f(props), func, options); + /// + public async Task ModifyAsync(Action func, TState state, RequestOptions options = null) { - var model = await RoleHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); + var model = await RoleHelper.ModifyAsync(this, Discord, func, state, options).ConfigureAwait(false); Update(model); } /// diff --git a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs index d570f078b1..0306ffa50b 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using Model = Discord.API.Role; using BulkParams = Discord.API.Rest.ModifyGuildRolesParams; @@ -13,11 +13,11 @@ internal static class RoleHelper { await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false); } - public static async Task ModifyAsync(IRole role, BaseDiscordClient client, - Action func, RequestOptions options) + public static async Task ModifyAsync(IRole role, BaseDiscordClient client, + Action func, TState state, RequestOptions options) { var args = new RoleProperties(); - func(args); + func(args, state); var apiArgs = new API.Rest.ModifyGuildRoleParams { Color = args.Color.IsSpecified ? args.Color.Value.RawValue : Optional.Create(), diff --git a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs index d6a8c2edab..19a5863942 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs @@ -90,9 +90,12 @@ public override async Task UpdateAsync(RequestOptions options = null) Update(model); } /// - public async Task ModifyAsync(Action func, RequestOptions options = null) + public Task ModifyAsync(Action func, RequestOptions options = null) + => ModifyAsync((props, f) => f(props), func, options); + /// + public async Task ModifyAsync(Action func, TState state, RequestOptions options = null) { - var args = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); + var args = await UserHelper.ModifyAsync(this, Discord, func, state, options).ConfigureAwait(false); if (args.Deaf.IsSpecified) IsDeafened = args.Deaf.Value; if (args.Mute.IsSpecified) diff --git a/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs b/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs index b5ef01c53d..d1675de9f5 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs @@ -65,11 +65,15 @@ public override async Task UpdateAsync(RequestOptions options = null) /// /// Unable to modify this object using a different token. - public async Task ModifyAsync(Action func, RequestOptions options = null) + public Task ModifyAsync(Action func, RequestOptions options = null) + => ModifyAsync((props, f) => f(props), func, options); + /// + /// Unable to modify this object using a different token. + public async Task ModifyAsync(Action func, TState state, RequestOptions options = null) { if (Id != Discord.CurrentUser.Id) throw new InvalidOperationException("Unable to modify this object using a different token."); - var model = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); + var model = await UserHelper.ModifyAsync(this, Discord, func, state, options).ConfigureAwait(false); Update(model); } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs b/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs index 8462cb8d45..4a5bcad0ad 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs @@ -63,6 +63,9 @@ IGuild IGuildUser.Guild /// Task IGuildUser.ModifyAsync(Action func, RequestOptions options) => throw new NotSupportedException("Webhook users cannot be modified."); + /// + Task IGuildUser.ModifyAsync(Action func, TState state, RequestOptions options) => + throw new NotSupportedException("Webhook users cannot be modified."); /// Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) => diff --git a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs index 58e8cd4179..56a6551e81 100644 --- a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs +++ b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs @@ -10,11 +10,13 @@ namespace Discord.Rest { internal static class UserHelper { - public static async Task ModifyAsync(ISelfUser user, BaseDiscordClient client, Action func, + public static async Task ModifyAsync(ISelfUser user, BaseDiscordClient client, + Action func, + TState state, RequestOptions options) { var args = new SelfUserProperties(); - func(args); + func(args, state); var apiArgs = new API.Rest.ModifyCurrentUserParams { Avatar = args.Avatar.IsSpecified ? args.Avatar.Value?.ToModel() : Optional.Create(), @@ -26,11 +28,13 @@ internal static class UserHelper return await client.ApiClient.ModifySelfAsync(apiArgs, options).ConfigureAwait(false); } - public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, Action func, + public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, + Action func, + TState state, RequestOptions options) { var args = new GuildUserProperties(); - func(args); + func(args, state); var apiArgs = new API.Rest.ModifyGuildMemberParams { Deaf = args.Deaf, diff --git a/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs b/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs index 1fdc95a63d..5c1fe4beb7 100644 --- a/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs +++ b/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs @@ -77,9 +77,11 @@ public async Task UpdateAsync(RequestOptions options = null) public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format); - public async Task ModifyAsync(Action func, RequestOptions options = null) + public Task ModifyAsync(Action func, RequestOptions options = null) + => ModifyAsync((props, f) => f(props), func, options); + public async Task ModifyAsync(Action func, TState state, RequestOptions options = null) { - var model = await WebhookHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); + var model = await WebhookHelper.ModifyAsync(this, Discord, func, state, options).ConfigureAwait(false); Update(model); } diff --git a/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs b/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs index 50e9cab78a..ba3054a8d9 100644 --- a/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs +++ b/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading.Tasks; using Discord.API.Rest; using ImageModel = Discord.API.Image; @@ -8,11 +8,11 @@ namespace Discord.Rest { internal static class WebhookHelper { - public static async Task ModifyAsync(IWebhook webhook, BaseDiscordClient client, - Action func, RequestOptions options) + public static async Task ModifyAsync(IWebhook webhook, BaseDiscordClient client, + Action func, TState state, RequestOptions options) { var args = new WebhookProperties(); - func(args); + func(args, state); var apiArgs = new ModifyWebhookParams { Avatar = args.Image.IsSpecified ? args.Image.Value?.ToModel() : Optional.Create(), diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index c65f3be059..614db906a3 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -75,7 +75,10 @@ internal override void Update(ClientState state, Model model) /// public Task ModifyAsync(Action func, RequestOptions options = null) - => ChannelHelper.ModifyAsync(this, Discord, func, options); + => ModifyAsync((props, f) => f(props), func, options); + /// + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + => ChannelHelper.ModifyAsync(this, Discord, func, state, options); /// public Task DeleteAsync(RequestOptions options = null) => ChannelHelper.DeleteAsync(this, Discord, options); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs index ca7ca11dc2..8e7fb691c1 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -73,7 +73,10 @@ internal override void Update(ClientState state, Model model) /// public Task ModifyAsync(Action func, RequestOptions options = null) - => ChannelHelper.ModifyAsync(this, Discord, func, options); + => ModifyAsync((props, f) => f(props), func, options); + /// + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + => ChannelHelper.ModifyAsync(this, Discord, func, state, options); //Messages /// diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs index 9fff6c2079..3af2383389 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs @@ -59,7 +59,10 @@ internal override void Update(ClientState state, Model model) /// public Task ModifyAsync(Action func, RequestOptions options = null) - => ChannelHelper.ModifyAsync(this, Discord, func, options); + => ModifyAsync((props, f) => f(props), func, options); + /// + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + => ChannelHelper.ModifyAsync(this, Discord, func, state, options); /// public async Task ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false) diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index cd0ab3db21..cf41ff1573 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -441,12 +441,20 @@ public Task DeleteAsync(RequestOptions options = null) /// /// is null. public Task ModifyAsync(Action func, RequestOptions options = null) - => GuildHelper.ModifyAsync(this, Discord, func, options); + => ModifyAsync((props, f) => f(props), func, options); + /// + /// is null. + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + => GuildHelper.ModifyAsync(this, Discord, func, state, options); /// /// is null. public Task ModifyEmbedAsync(Action func, RequestOptions options = null) - => GuildHelper.ModifyEmbedAsync(this, Discord, func, options); + => ModifyEmbedAsync((props, f) => f(props), func, options); + /// + /// is null. + public Task ModifyEmbedAsync(Action func, TState state, RequestOptions options = null) + => GuildHelper.ModifyEmbedAsync(this, Discord, func, state, options); /// public Task ReorderChannelsAsync(IEnumerable args, RequestOptions options = null) => GuildHelper.ReorderChannelsAsync(this, Discord, args, options); diff --git a/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs b/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs index b26dfe5fb6..355097ffd6 100644 --- a/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs +++ b/src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs @@ -123,12 +123,17 @@ internal override void Update(ClientState state, Model model) model.Content = text; } } - + /// /// Only the author of a message may modify the message. /// Message content is too long, length must be less or equal to . public Task ModifyAsync(Action func, RequestOptions options = null) - => MessageHelper.ModifyAsync(this, Discord, func, options); + => ModifyAsync((props, f) => f(props), func, options); + /// + /// Only the author of a message may modify the message. + /// Message content is too long, length must be less or equal to . + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + => MessageHelper.ModifyAsync(this, Discord, func, state, options); /// public Task PinAsync(RequestOptions options = null) diff --git a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs index b5e26ad782..1277021779 100644 --- a/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs +++ b/src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs @@ -75,7 +75,10 @@ internal void Update(ClientState state, Model model) /// public Task ModifyAsync(Action func, RequestOptions options = null) - => RoleHelper.ModifyAsync(this, Discord, func, options); + => ModifyAsync((props, f) => f(props), func, options); + /// + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + => RoleHelper.ModifyAsync(this, Discord, func, state, options); /// public Task DeleteAsync(RequestOptions options = null) => RoleHelper.DeleteAsync(this, Discord, options); diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs index e5dbfa01dd..7548b002e4 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs @@ -166,7 +166,10 @@ private void UpdateRoles(ulong[] roleIds) /// public Task ModifyAsync(Action func, RequestOptions options = null) - => UserHelper.ModifyAsync(this, Discord, func, options); + => ModifyAsync((props, f) => f(props), func, options); + /// + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + => UserHelper.ModifyAsync(this, Discord, func, state, options); /// public Task KickAsync(string reason = null, RequestOptions options = null) => UserHelper.KickAsync(this, Discord, reason, options); diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs index 7b11257a3b..5861953f29 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs @@ -88,8 +88,12 @@ internal override bool Update(ClientState state, Model model) } /// + /// Unable to modify this object using a different token. public Task ModifyAsync(Action func, RequestOptions options = null) - => UserHelper.ModifyAsync(this, Discord, func, options); + => ModifyAsync((props, f) => f(props), func, options); + /// + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + => UserHelper.ModifyAsync(this, Discord, func, state, options); private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Self)"; internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser; diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs index 8819fe1b43..1e56537a1b 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs @@ -78,6 +78,10 @@ internal static SocketWebhookUser Create(SocketGuild guild, ClientState state, M /// Webhook users cannot be modified. Task IGuildUser.ModifyAsync(Action func, RequestOptions options) => throw new NotSupportedException("Webhook users cannot be modified."); + /// + /// Webhook users cannot be modified. + Task IGuildUser.ModifyAsync(Action func, TState state, RequestOptions options) => + throw new NotSupportedException("Webhook users cannot be modified."); /// /// Roles are not supported on webhook users. diff --git a/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs b/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs index 60cb89ee26..993749900a 100644 --- a/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs +++ b/src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using System.Threading.Tasks; using Model = Discord.API.Webhook; @@ -47,9 +47,11 @@ internal void Update(Model model) public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) => CDN.GetUserAvatarUrl(Id, AvatarId, size, format); - public async Task ModifyAsync(Action func, RequestOptions options = null) + public Task ModifyAsync(Action func, RequestOptions options = null) + => ModifyAsync((props, f) => f(props), func, options); + public async Task ModifyAsync(Action func, TState state, RequestOptions options = null) { - var model = await WebhookClientHelper.ModifyAsync(_client, func, options).ConfigureAwait(false); + var model = await WebhookClientHelper.ModifyAsync(_client, func, state, options).ConfigureAwait(false); Update(model); } diff --git a/src/Discord.Net.Webhook/WebhookClientHelper.cs b/src/Discord.Net.Webhook/WebhookClientHelper.cs index 311d58bdae..7bb3a87b4d 100644 --- a/src/Discord.Net.Webhook/WebhookClientHelper.cs +++ b/src/Discord.Net.Webhook/WebhookClientHelper.cs @@ -55,11 +55,11 @@ public static async Task GetWebhookAsync(DiscordWebhookClie return msg.Id; } - public static async Task ModifyAsync(DiscordWebhookClient client, - Action func, RequestOptions options) + public static async Task ModifyAsync(DiscordWebhookClient client, + Action func, TState state, RequestOptions options) { var args = new WebhookProperties(); - func(args); + func(args, state); var apiArgs = new ModifyWebhookParams { Avatar = args.Image.IsSpecified ? args.Image.Value?.ToModel() : Optional.Create(), diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedCategoryChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedCategoryChannel.cs index 7125704676..bb1f7725fb 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedCategoryChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedCategoryChannel.cs @@ -61,6 +61,11 @@ public Task ModifyAsync(Action func, RequestOptions opti throw new NotImplementedException(); } + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + { + throw new NotImplementedException(); + } + public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) { throw new NotImplementedException(); diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs index ca84219fd3..fb6c0cf60d 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs @@ -152,11 +152,21 @@ public Task ModifyAsync(Action func, RequestOptions optio throw new NotImplementedException(); } + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + { + throw new NotImplementedException(); + } + public Task ModifyAsync(Action func, RequestOptions options = null) { throw new NotImplementedException(); } + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + { + throw new NotImplementedException(); + } + public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) { throw new NotImplementedException(); diff --git a/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs b/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs index eb617125df..142954add8 100644 --- a/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs +++ b/test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs @@ -93,11 +93,21 @@ public Task ModifyAsync(Action func, RequestOptions opti throw new NotImplementedException(); } + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + { + throw new NotImplementedException(); + } + public Task ModifyAsync(Action func, RequestOptions options = null) { throw new NotImplementedException(); } + public Task ModifyAsync(Action func, TState state, RequestOptions options = null) + { + throw new NotImplementedException(); + } + public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) { throw new NotImplementedException();