Skip to content

Commit 301efd7

Browse files
committed
Add non-capturing overloads of Modify methods
1 parent 0bda8a4 commit 301efd7

39 files changed

+286
-68
lines changed

src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ public interface IGuildChannel : IChannel, IDeletable
5757
/// A task that represents the asynchronous modification operation.
5858
/// </returns>
5959
Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null);
60+
/// <summary>
61+
/// Modifies this guild channel.
62+
/// </summary>
63+
/// <remarks>
64+
/// This method modifies the current guild channel with the specified properties. To see an example of this
65+
/// method and what properties are available, please refer to <see cref="GuildChannelProperties"/>.
66+
/// </remarks>
67+
/// <param name="func">The delegate containing the properties to modify the channel with.</param>
68+
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
69+
/// <param name="options">The options to be used when sending the request.</param>
70+
/// <returns>
71+
/// A task that represents the asynchronous modification operation.
72+
/// </returns>
73+
Task ModifyAsync<TState>(Action<GuildChannelProperties, TState> func, TState state, RequestOptions options = null);
6074

6175
/// <summary>
6276
/// Gets the permission overwrite for a specific role.

src/Discord.Net.Core/Entities/Channels/ITextChannel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,18 @@ public interface ITextChannel : IMessageChannel, IMentionable, INestedChannel
8383
/// </returns>
8484
/// <seealso cref="TextChannelProperties"/>
8585
Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null);
86-
86+
/// <summary>
87+
/// Modifies this text channel.
88+
/// </summary>
89+
/// <param name="func">The delegate containing the properties to modify the channel with.</param>
90+
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
91+
/// <param name="options">The options to be used when sending the request.</param>
92+
/// <returns>
93+
/// A task that represents the asynchronous modification operation.
94+
/// </returns>
95+
/// <seealso cref="TextChannelProperties"/>
96+
Task ModifyAsync<TState>(Action<TextChannelProperties, TState> func, TState state, RequestOptions options = null);
97+
8798
/// <summary>
8899
/// Creates a webhook in this text channel.
89100
/// </summary>

src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,16 @@ public interface IVoiceChannel : INestedChannel, IAudioChannel
3535
/// </returns>
3636
/// <seealso cref="VoiceChannelProperties"/>
3737
Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null);
38+
/// <summary>
39+
/// Modifies this voice channel.
40+
/// </summary>
41+
/// <param name="func">The properties to modify the channel with.</param>
42+
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
43+
/// <param name="options">The options to be used when sending the request.</param>
44+
/// <returns>
45+
/// A task that represents the asynchronous modification operation.
46+
/// </returns>
47+
/// <seealso cref="VoiceChannelProperties"/>
48+
Task ModifyAsync<TState>(Action<VoiceChannelProperties, TState> func, TState state, RequestOptions options = null);
3849
}
3950
}

src/Discord.Net.Core/Entities/Guilds/IGuild.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ public interface IGuild : IDeletable, ISnowflakeEntity
259259
/// </returns>
260260
Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null);
261261
/// <summary>
262+
/// Modifies this guild.
263+
/// </summary>
264+
/// <param name="func">The delegate containing the properties to modify the guild with.</param>
265+
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
266+
/// <param name="options">The options to be used when sending the request.</param>
267+
/// <returns>
268+
/// A task that represents the asynchronous modification operation.
269+
/// </returns>
270+
Task ModifyAsync<TState>(Action<GuildProperties, TState> func, TState state, RequestOptions options = null);
271+
/// <summary>
262272
/// Modifies this guild's embed channel.
263273
/// </summary>
264274
/// <param name="func">The delegate containing the properties to modify the guild widget with.</param>
@@ -268,6 +278,16 @@ public interface IGuild : IDeletable, ISnowflakeEntity
268278
/// </returns>
269279
Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null);
270280
/// <summary>
281+
/// Modifies this guild's embed channel.
282+
/// </summary>
283+
/// <param name="func">The delegate containing the properties to modify the guild widget with.</param>
284+
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
285+
/// <param name="options">The options to be used when sending the request.</param>
286+
/// <returns>
287+
/// A task that represents the asynchronous modification operation.
288+
/// </returns>
289+
Task ModifyEmbedAsync<TState>(Action<GuildEmbedProperties, TState> func, TState state, RequestOptions options = null);
290+
/// <summary>
271291
/// Bulk-modifies the order of channels in this guild.
272292
/// </summary>
273293
/// <param name="args">The properties used to modify the channel positions with.</param>

src/Discord.Net.Core/Entities/Messages/IUserMessage.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ public interface IUserMessage : IMessage
2929
/// </returns>
3030
Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null);
3131
/// <summary>
32+
/// Modifies this message.
33+
/// </summary>
34+
/// <remarks>
35+
/// This method modifies this message with the specified properties. To see an example of this
36+
/// method and what properties are available, please refer to <see cref="MessageProperties"/>.
37+
/// </remarks>
38+
/// <example>
39+
/// The following example replaces the content of the message with <c>Hello World!</c>.
40+
/// <code language="cs">
41+
/// await msg.ModifyAsync((x, s) =&gt; x.Content = s, "Hello World!");
42+
/// </code>
43+
/// </example>
44+
/// <param name="func">A delegate containing the properties to modify the message with.</param>
45+
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
46+
/// <param name="options">The options to be used when sending the request.</param>
47+
/// <returns>
48+
/// A task that represents the asynchronous modification operation.
49+
/// </returns>
50+
Task ModifyAsync<TState>(Action<MessageProperties, TState> func, TState state, RequestOptions options = null);
51+
/// <summary>
3252
/// Modifies the suppression of this message.
3353
/// </summary>
3454
/// <remarks>

src/Discord.Net.Core/Entities/Roles/IRole.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,19 @@ public interface IRole : ISnowflakeEntity, IDeletable, IMentionable, IComparable
7979
/// A task that represents the asynchronous modification operation.
8080
/// </returns>
8181
Task ModifyAsync(Action<RoleProperties> func, RequestOptions options = null);
82+
/// <summary>
83+
/// Modifies this role.
84+
/// </summary>
85+
/// <remarks>
86+
/// This method modifies this role with the specified properties. To see an example of this
87+
/// method and what properties are available, please refer to <see cref="RoleProperties"/>.
88+
/// </remarks>
89+
/// <param name="func">A delegate containing the properties to modify the role with.</param>
90+
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
91+
/// <param name="options">The options to be used when sending the request.</param>
92+
/// <returns>
93+
/// A task that represents the asynchronous modification operation.
94+
/// </returns>
95+
Task ModifyAsync<TState>(Action<RoleProperties, TState> func, TState state, RequestOptions options = null);
8296
}
8397
}

src/Discord.Net.Core/Entities/Users/IGuildUser.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ public interface IGuildUser : IUser, IVoiceState
108108
/// A task that represents the asynchronous modification operation.
109109
/// </returns>
110110
Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null);
111+
/// <summary>
112+
/// Modifies this user's properties in this guild.
113+
/// </summary>
114+
/// <remarks>
115+
/// This method modifies the current guild user with the specified properties. To see an example of this
116+
/// method and what properties are available, please refer to <see cref="GuildUserProperties"/>.
117+
/// </remarks>
118+
/// <param name="func">The delegate containing the properties to modify the user with.</param>
119+
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
120+
/// <param name="options">The options to be used when sending the request.</param>
121+
/// <returns>
122+
/// A task that represents the asynchronous modification operation.
123+
/// </returns>
124+
Task ModifyAsync<TState>(Action<GuildUserProperties, TState> func, TState state, RequestOptions options = null);
111125

112126
/// <summary>
113127
/// Adds the specified role to this user in the guild.

src/Discord.Net.Core/Entities/Users/ISelfUser.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@ public interface ISelfUser : IUser
5959
/// Modifies the user's properties.
6060
/// </summary>
6161
Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null);
62+
/// <summary>
63+
/// Modifies the user's properties.
64+
/// </summary>
65+
Task ModifyAsync<TState>(Action<SelfUserProperties, TState> func, TState state, RequestOptions options = null);
6266
}
6367
}

src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Threading.Tasks;
33

44
namespace Discord
@@ -53,5 +53,9 @@ public interface IWebhook : IDeletable, ISnowflakeEntity
5353
/// Modifies this webhook.
5454
/// </summary>
5555
Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null);
56+
/// <summary>
57+
/// Modifies this webhook.
58+
/// </summary>
59+
Task ModifyAsync<TState>(Action<WebhookProperties, TState> func, TState state, RequestOptions options = null);
5660
}
5761
}

src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client,
1818
{
1919
await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false);
2020
}
21-
public static async Task<Model> ModifyAsync(IGuildChannel channel, BaseDiscordClient client,
22-
Action<GuildChannelProperties> func,
21+
public static async Task<Model> ModifyAsync<TState>(IGuildChannel channel, BaseDiscordClient client,
22+
Action<GuildChannelProperties, TState> func,
23+
TState state,
2324
RequestOptions options)
2425
{
2526
var args = new GuildChannelProperties();
26-
func(args);
27+
func(args, state);
2728
var apiArgs = new API.Rest.ModifyGuildChannelParams
2829
{
2930
Name = args.Name,
@@ -32,12 +33,13 @@ public static async Task<Model> ModifyAsync(IGuildChannel channel, BaseDiscordCl
3233
};
3334
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
3435
}
35-
public static async Task<Model> ModifyAsync(ITextChannel channel, BaseDiscordClient client,
36-
Action<TextChannelProperties> func,
36+
public static async Task<Model> ModifyAsync<TState>(ITextChannel channel, BaseDiscordClient client,
37+
Action<TextChannelProperties, TState> func,
38+
TState state,
3739
RequestOptions options)
3840
{
3941
var args = new TextChannelProperties();
40-
func(args);
42+
func(args, state);
4143
var apiArgs = new API.Rest.ModifyTextChannelParams
4244
{
4345
Name = args.Name,
@@ -49,12 +51,13 @@ public static async Task<Model> ModifyAsync(ITextChannel channel, BaseDiscordCli
4951
};
5052
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
5153
}
52-
public static async Task<Model> ModifyAsync(IVoiceChannel channel, BaseDiscordClient client,
53-
Action<VoiceChannelProperties> func,
54+
public static async Task<Model> ModifyAsync<TState>(IVoiceChannel channel, BaseDiscordClient client,
55+
Action<VoiceChannelProperties, TState> func,
56+
TState state,
5457
RequestOptions options)
5558
{
5659
var args = new VoiceChannelProperties();
57-
func(args);
60+
func(args, state);
5861
var apiArgs = new API.Rest.ModifyVoiceChannelParams
5962
{
6063
Bitrate = args.Bitrate,

0 commit comments

Comments
 (0)