Browse Source

Merge 391823ba44 into e40ca4a422

pull/1396/merge
Joe4evr GitHub 4 years ago
parent
commit
ccbbe41406
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 285 additions and 67 deletions
  1. +14
    -0
      src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs
  2. +12
    -1
      src/Discord.Net.Core/Entities/Channels/ITextChannel.cs
  3. +11
    -0
      src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs
  4. +20
    -0
      src/Discord.Net.Core/Entities/Guilds/IGuild.cs
  5. +20
    -0
      src/Discord.Net.Core/Entities/Messages/IUserMessage.cs
  6. +14
    -0
      src/Discord.Net.Core/Entities/Roles/IRole.cs
  7. +14
    -0
      src/Discord.Net.Core/Entities/Users/IGuildUser.cs
  8. +4
    -0
      src/Discord.Net.Core/Entities/Users/ISelfUser.cs
  9. +5
    -1
      src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs
  10. +12
    -9
      src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
  11. +5
    -2
      src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
  12. +5
    -2
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  13. +5
    -2
      src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
  14. +6
    -6
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
  15. +12
    -4
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  16. +4
    -2
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  17. +5
    -2
      src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs
  18. +5
    -3
      src/Discord.Net.Rest/Entities/Roles/RestRole.cs
  19. +4
    -4
      src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs
  20. +5
    -2
      src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs
  21. +6
    -2
      src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs
  22. +3
    -0
      src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs
  23. +8
    -4
      src/Discord.Net.Rest/Entities/Users/UserHelper.cs
  24. +4
    -2
      src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs
  25. +4
    -4
      src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs
  26. +4
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs
  27. +4
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
  28. +4
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs
  29. +10
    -2
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
  30. +6
    -1
      src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs
  31. +4
    -1
      src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs
  32. +4
    -1
      src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
  33. +5
    -1
      src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs
  34. +4
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs
  35. +5
    -3
      src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs
  36. +3
    -3
      src/Discord.Net.Webhook/WebhookClientHelper.cs
  37. +5
    -0
      test/Discord.Net.Tests.Unit/MockedEntities/MockedCategoryChannel.cs
  38. +10
    -0
      test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs
  39. +10
    -0
      test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs

+ 14
- 0
src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs View File

@@ -57,6 +57,20 @@ namespace Discord
/// A task that represents the asynchronous modification operation. /// A task that represents the asynchronous modification operation.
/// </returns> /// </returns>
Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null); Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null);
/// <summary>
/// Modifies this guild channel.
/// </summary>
/// <remarks>
/// 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 <see cref="GuildChannelProperties"/>.
/// </remarks>
/// <param name="func">The delegate containing the properties to modify the channel with.</param>
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous modification operation.
/// </returns>
Task ModifyAsync<TState>(Action<GuildChannelProperties, TState> func, TState state, RequestOptions options = null);


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


+ 12
- 1
src/Discord.Net.Core/Entities/Channels/ITextChannel.cs View File

@@ -83,7 +83,18 @@ namespace Discord
/// </returns> /// </returns>
/// <seealso cref="TextChannelProperties"/> /// <seealso cref="TextChannelProperties"/>
Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null); Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null);
/// <summary>
/// Modifies this text channel.
/// </summary>
/// <param name="func">The delegate containing the properties to modify the channel with.</param>
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous modification operation.
/// </returns>
/// <seealso cref="TextChannelProperties"/>
Task ModifyAsync<TState>(Action<TextChannelProperties, TState> func, TState state, RequestOptions options = null);

/// <summary> /// <summary>
/// Creates a webhook in this text channel. /// Creates a webhook in this text channel.
/// </summary> /// </summary>


+ 11
- 0
src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs View File

@@ -35,5 +35,16 @@ namespace Discord
/// </returns> /// </returns>
/// <seealso cref="VoiceChannelProperties"/> /// <seealso cref="VoiceChannelProperties"/>
Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null); Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null);
/// <summary>
/// Modifies this voice channel.
/// </summary>
/// <param name="func">The properties to modify the channel with.</param>
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous modification operation.
/// </returns>
/// <seealso cref="VoiceChannelProperties"/>
Task ModifyAsync<TState>(Action<VoiceChannelProperties, TState> func, TState state, RequestOptions options = null);
} }
} }

+ 20
- 0
src/Discord.Net.Core/Entities/Guilds/IGuild.cs View File

@@ -278,6 +278,16 @@ namespace Discord
/// </returns> /// </returns>
Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null); Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null);
/// <summary> /// <summary>
/// Modifies this guild.
/// </summary>
/// <param name="func">The delegate containing the properties to modify the guild with.</param>
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous modification operation.
/// </returns>
Task ModifyAsync<TState>(Action<GuildProperties, TState> func, TState state, RequestOptions options = null);
/// <summary>
/// Modifies this guild's embed channel. /// Modifies this guild's embed channel.
/// </summary> /// </summary>
/// <param name="func">The delegate containing the properties to modify the guild widget with.</param> /// <param name="func">The delegate containing the properties to modify the guild widget with.</param>
@@ -287,6 +297,16 @@ namespace Discord
/// </returns> /// </returns>
Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null); Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null);
/// <summary> /// <summary>
/// Modifies this guild's embed channel.
/// </summary>
/// <param name="func">The delegate containing the properties to modify the guild widget with.</param>
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous modification operation.
/// </returns>
Task ModifyEmbedAsync<TState>(Action<GuildEmbedProperties, TState> func, TState state, RequestOptions options = null);
/// <summary>
/// Bulk-modifies the order of channels in this guild. /// Bulk-modifies the order of channels in this guild.
/// </summary> /// </summary>
/// <param name="args">The properties used to modify the channel positions with.</param> /// <param name="args">The properties used to modify the channel positions with.</param>


+ 20
- 0
src/Discord.Net.Core/Entities/Messages/IUserMessage.cs View File

@@ -29,6 +29,26 @@ namespace Discord
/// </returns> /// </returns>
Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null); Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null);
/// <summary> /// <summary>
/// Modifies this message.
/// </summary>
/// <remarks>
/// This method modifies this message with the specified properties. To see an example of this
/// method and what properties are available, please refer to <see cref="MessageProperties"/>.
/// </remarks>
/// <example>
/// The following example replaces the content of the message with <c>Hello World!</c>.
/// <code language="cs">
/// await msg.ModifyAsync((x, s) =&gt; x.Content = s, "Hello World!");
/// </code>
/// </example>
/// <param name="func">A delegate containing the properties to modify the message with.</param>
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous modification operation.
/// </returns>
Task ModifyAsync<TState>(Action<MessageProperties, TState> func, TState state, RequestOptions options = null);
/// <summary>
/// Modifies the suppression of this message. /// Modifies the suppression of this message.
/// </summary> /// </summary>
/// <remarks> /// <remarks>


+ 14
- 0
src/Discord.Net.Core/Entities/Roles/IRole.cs View File

@@ -79,5 +79,19 @@ namespace Discord
/// A task that represents the asynchronous modification operation. /// A task that represents the asynchronous modification operation.
/// </returns> /// </returns>
Task ModifyAsync(Action<RoleProperties> func, RequestOptions options = null); Task ModifyAsync(Action<RoleProperties> func, RequestOptions options = null);
/// <summary>
/// Modifies this role.
/// </summary>
/// <remarks>
/// This method modifies this role with the specified properties. To see an example of this
/// method and what properties are available, please refer to <see cref="RoleProperties"/>.
/// </remarks>
/// <param name="func">A delegate containing the properties to modify the role with.</param>
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous modification operation.
/// </returns>
Task ModifyAsync<TState>(Action<RoleProperties, TState> func, TState state, RequestOptions options = null);
} }
} }

+ 14
- 0
src/Discord.Net.Core/Entities/Users/IGuildUser.cs View File

@@ -108,6 +108,20 @@ namespace Discord
/// A task that represents the asynchronous modification operation. /// A task that represents the asynchronous modification operation.
/// </returns> /// </returns>
Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null); Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null);
/// <summary>
/// Modifies this user's properties in this guild.
/// </summary>
/// <remarks>
/// 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 <see cref="GuildUserProperties"/>.
/// </remarks>
/// <param name="func">The delegate containing the properties to modify the user with.</param>
/// <param name="state">An object to carry state into the delegate to prevent closures.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous modification operation.
/// </returns>
Task ModifyAsync<TState>(Action<GuildUserProperties, TState> func, TState state, RequestOptions options = null);


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


+ 4
- 0
src/Discord.Net.Core/Entities/Users/ISelfUser.cs View File

@@ -59,5 +59,9 @@ namespace Discord
/// Modifies the user's properties. /// Modifies the user's properties.
/// </summary> /// </summary>
Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null); Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null);
/// <summary>
/// Modifies the user's properties.
/// </summary>
Task ModifyAsync<TState>(Action<SelfUserProperties, TState> func, TState state, RequestOptions options = null);
} }
} }

+ 5
- 1
src/Discord.Net.Core/Entities/Webhooks/IWebhook.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;


namespace Discord namespace Discord
@@ -53,5 +53,9 @@ namespace Discord
/// Modifies this webhook. /// Modifies this webhook.
/// </summary> /// </summary>
Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null); Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null);
/// <summary>
/// Modifies this webhook.
/// </summary>
Task ModifyAsync<TState>(Action<WebhookProperties, TState> func, TState state, RequestOptions options = null);
} }
} }

+ 12
- 9
src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs View File

@@ -18,12 +18,13 @@ namespace Discord.Rest
{ {
await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false); await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false);
} }
public static async Task<Model> ModifyAsync(IGuildChannel channel, BaseDiscordClient client,
Action<GuildChannelProperties> func,
public static async Task<Model> ModifyAsync<TState>(IGuildChannel channel, BaseDiscordClient client,
Action<GuildChannelProperties, TState> func,
TState state,
RequestOptions options) RequestOptions options)
{ {
var args = new GuildChannelProperties(); var args = new GuildChannelProperties();
func(args);
func(args, state);
var apiArgs = new API.Rest.ModifyGuildChannelParams var apiArgs = new API.Rest.ModifyGuildChannelParams
{ {
Name = args.Name, Name = args.Name,
@@ -41,12 +42,13 @@ namespace Discord.Rest
}; };
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
} }
public static async Task<Model> ModifyAsync(ITextChannel channel, BaseDiscordClient client,
Action<TextChannelProperties> func,
public static async Task<Model> ModifyAsync<TState>(ITextChannel channel, BaseDiscordClient client,
Action<TextChannelProperties, TState> func,
TState state,
RequestOptions options) RequestOptions options)
{ {
var args = new TextChannelProperties(); var args = new TextChannelProperties();
func(args);
func(args, state);
var apiArgs = new API.Rest.ModifyTextChannelParams var apiArgs = new API.Rest.ModifyTextChannelParams
{ {
Name = args.Name, Name = args.Name,
@@ -67,12 +69,13 @@ namespace Discord.Rest
}; };
return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); return await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
} }
public static async Task<Model> ModifyAsync(IVoiceChannel channel, BaseDiscordClient client,
Action<VoiceChannelProperties> func,
public static async Task<Model> ModifyAsync<TState>(IVoiceChannel channel, BaseDiscordClient client,
Action<VoiceChannelProperties, TState> func,
TState state,
RequestOptions options) RequestOptions options)
{ {
var args = new VoiceChannelProperties(); var args = new VoiceChannelProperties();
func(args);
func(args, state);
var apiArgs = new API.Rest.ModifyVoiceChannelParams var apiArgs = new API.Rest.ModifyVoiceChannelParams
{ {
Bitrate = args.Bitrate, Bitrate = args.Bitrate,


+ 5
- 2
src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs View File

@@ -65,9 +65,12 @@ namespace Discord.Rest
Update(model); Update(model);
} }
/// <inheritdoc /> /// <inheritdoc />
public async Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null)
public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null)
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public async Task ModifyAsync<TState>(Action<GuildChannelProperties, TState> 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); Update(model);
} }
/// <inheritdoc /> /// <inheritdoc />


+ 5
- 2
src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs View File

@@ -48,9 +48,12 @@ namespace Discord.Rest
} }


/// <inheritdoc /> /// <inheritdoc />
public async Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null)
public Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null)
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public async Task ModifyAsync<TState>(Action<TextChannelProperties, TState> 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); Update(model);
} }




+ 5
- 2
src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs View File

@@ -41,9 +41,12 @@ namespace Discord.Rest
} }


/// <inheritdoc /> /// <inheritdoc />
public async Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null)
public Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null)
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public async Task ModifyAsync<TState>(Action<VoiceChannelProperties, TState> 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); Update(model);
} }




+ 6
- 6
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -15,13 +15,13 @@ namespace Discord.Rest
{ {
//General //General
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
public static async Task<Model> ModifyAsync(IGuild guild, BaseDiscordClient client,
Action<GuildProperties> func, RequestOptions options)
public static async Task<Model> ModifyAsync<TState>(IGuild guild, BaseDiscordClient client,
Action<GuildProperties, TState> func, TState state, RequestOptions options)
{ {
if (func == null) throw new ArgumentNullException(nameof(func)); if (func == null) throw new ArgumentNullException(nameof(func));


var args = new GuildProperties(); var args = new GuildProperties();
func(args);
func(args, state);


var apiArgs = new API.Rest.ModifyGuildParams var apiArgs = new API.Rest.ModifyGuildParams
{ {
@@ -80,13 +80,13 @@ namespace Discord.Rest
return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false); return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
} }
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
public static async Task<EmbedModel> ModifyEmbedAsync(IGuild guild, BaseDiscordClient client,
Action<GuildEmbedProperties> func, RequestOptions options)
public static async Task<EmbedModel> ModifyEmbedAsync<TState>(IGuild guild, BaseDiscordClient client,
Action<GuildEmbedProperties, TState> func, TState state, RequestOptions options)
{ {
if (func == null) throw new ArgumentNullException(nameof(func)); if (func == null) throw new ArgumentNullException(nameof(func));


var args = new GuildEmbedProperties(); var args = new GuildEmbedProperties();
func(args);
func(args, state);
var apiArgs = new API.Rest.ModifyGuildEmbedParams var apiArgs = new API.Rest.ModifyGuildEmbedParams
{ {
Enabled = args.Enabled Enabled = args.Enabled


+ 12
- 4
src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs View File

@@ -174,17 +174,25 @@ namespace Discord.Rest


/// <inheritdoc /> /// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
public async Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null)
public Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null)
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
public async Task ModifyAsync<TState>(Action<GuildProperties, TState> 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); Update(model);
} }


/// <inheritdoc /> /// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
public async Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null)
public Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null)
=> ModifyEmbedAsync((props, f) => f(props), func, options);
/// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
public async Task ModifyEmbedAsync<TState>(Action<GuildEmbedProperties, TState> 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); Update(model);
} }




+ 4
- 2
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -23,14 +23,16 @@ namespace Discord.Rest


/// <exception cref="InvalidOperationException">Only the author of a message may modify the message.</exception> /// <exception cref="InvalidOperationException">Only the author of a message may modify the message.</exception>
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
public static async Task<Model> ModifyAsync(IMessage msg, BaseDiscordClient client, Action<MessageProperties> func,
public static async Task<Model> ModifyAsync<TState>(IMessage msg, BaseDiscordClient client,
Action<MessageProperties, TState> func,
TState state,
RequestOptions options) RequestOptions options)
{ {
if (msg.Author.Id != client.CurrentUser.Id) if (msg.Author.Id != client.CurrentUser.Id)
throw new InvalidOperationException("Only the author of a message may modify the message."); throw new InvalidOperationException("Only the author of a message may modify the message.");


var args = new MessageProperties(); var args = new MessageProperties();
func(args);
func(args, state);


bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(msg.Content); bool hasText = args.Content.IsSpecified ? !string.IsNullOrEmpty(args.Content.Value) : !string.IsNullOrEmpty(msg.Content);
bool hasEmbed = args.Embed.IsSpecified ? args.Embed.Value != null : msg.Embeds.Any(); bool hasEmbed = args.Embed.IsSpecified ? args.Embed.Value != null : msg.Embeds.Any();


+ 5
- 2
src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs View File

@@ -129,9 +129,12 @@ namespace Discord.Rest
} }


/// <inheritdoc /> /// <inheritdoc />
public async Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null)
public Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null)
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public async Task ModifyAsync<TState>(Action<MessageProperties, TState> 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); Update(model);
} }




+ 5
- 3
src/Discord.Net.Rest/Entities/Roles/RestRole.cs View File

@@ -57,11 +57,13 @@ namespace Discord.Rest
Color = new Color(model.Color); Color = new Color(model.Color);
Permissions = new GuildPermissions(model.Permissions); Permissions = new GuildPermissions(model.Permissions);
} }

/// <inheritdoc /> /// <inheritdoc />
public async Task ModifyAsync(Action<RoleProperties> func, RequestOptions options = null)
public Task ModifyAsync(Action<RoleProperties> func, RequestOptions options = null)
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public async Task ModifyAsync<TState>(Action<RoleProperties, TState> 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); Update(model);
} }
/// <inheritdoc /> /// <inheritdoc />


+ 4
- 4
src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Model = Discord.API.Role; using Model = Discord.API.Role;
using BulkParams = Discord.API.Rest.ModifyGuildRolesParams; using BulkParams = Discord.API.Rest.ModifyGuildRolesParams;
@@ -13,11 +13,11 @@ namespace Discord.Rest
{ {
await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false); await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false);
} }
public static async Task<Model> ModifyAsync(IRole role, BaseDiscordClient client,
Action<RoleProperties> func, RequestOptions options)
public static async Task<Model> ModifyAsync<TState>(IRole role, BaseDiscordClient client,
Action<RoleProperties, TState> func, TState state, RequestOptions options)
{ {
var args = new RoleProperties(); var args = new RoleProperties();
func(args);
func(args, state);
var apiArgs = new API.Rest.ModifyGuildRoleParams var apiArgs = new API.Rest.ModifyGuildRoleParams
{ {
Color = args.Color.IsSpecified ? args.Color.Value.RawValue : Optional.Create<uint>(), Color = args.Color.IsSpecified ? args.Color.Value.RawValue : Optional.Create<uint>(),


+ 5
- 2
src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs View File

@@ -90,9 +90,12 @@ namespace Discord.Rest
Update(model); Update(model);
} }
/// <inheritdoc /> /// <inheritdoc />
public async Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null)
public Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null)
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public async Task ModifyAsync<TState>(Action<GuildUserProperties, TState> 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) if (args.Deaf.IsSpecified)
IsDeafened = args.Deaf.Value; IsDeafened = args.Deaf.Value;
if (args.Mute.IsSpecified) if (args.Mute.IsSpecified)


+ 6
- 2
src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs View File

@@ -65,11 +65,15 @@ namespace Discord.Rest


/// <inheritdoc /> /// <inheritdoc />
/// <exception cref="InvalidOperationException">Unable to modify this object using a different token.</exception> /// <exception cref="InvalidOperationException">Unable to modify this object using a different token.</exception>
public async Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null)
public Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null)
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
/// <exception cref="InvalidOperationException">Unable to modify this object using a different token.</exception>
public async Task ModifyAsync<TState>(Action<SelfUserProperties, TState> func, TState state, RequestOptions options = null)
{ {
if (Id != Discord.CurrentUser.Id) if (Id != Discord.CurrentUser.Id)
throw new InvalidOperationException("Unable to modify this object using a different token."); 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); Update(model);
} }
} }


+ 3
- 0
src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs View File

@@ -63,6 +63,9 @@ namespace Discord.Rest
/// <inheritdoc /> /// <inheritdoc />
Task IGuildUser.ModifyAsync(Action<GuildUserProperties> func, RequestOptions options) => Task IGuildUser.ModifyAsync(Action<GuildUserProperties> func, RequestOptions options) =>
throw new NotSupportedException("Webhook users cannot be modified."); throw new NotSupportedException("Webhook users cannot be modified.");
/// <inheritdoc />
Task IGuildUser.ModifyAsync<TState>(Action<GuildUserProperties, TState> func, TState state, RequestOptions options) =>
throw new NotSupportedException("Webhook users cannot be modified.");


/// <inheritdoc /> /// <inheritdoc />
Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) => Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options) =>


+ 8
- 4
src/Discord.Net.Rest/Entities/Users/UserHelper.cs View File

@@ -10,11 +10,13 @@ namespace Discord.Rest
{ {
internal static class UserHelper internal static class UserHelper
{ {
public static async Task<Model> ModifyAsync(ISelfUser user, BaseDiscordClient client, Action<SelfUserProperties> func,
public static async Task<Model> ModifyAsync<TState>(ISelfUser user, BaseDiscordClient client,
Action<SelfUserProperties, TState> func,
TState state,
RequestOptions options) RequestOptions options)
{ {
var args = new SelfUserProperties(); var args = new SelfUserProperties();
func(args);
func(args, state);
var apiArgs = new API.Rest.ModifyCurrentUserParams var apiArgs = new API.Rest.ModifyCurrentUserParams
{ {
Avatar = args.Avatar.IsSpecified ? args.Avatar.Value?.ToModel() : Optional.Create<ImageModel?>(), Avatar = args.Avatar.IsSpecified ? args.Avatar.Value?.ToModel() : Optional.Create<ImageModel?>(),
@@ -26,11 +28,13 @@ namespace Discord.Rest


return await client.ApiClient.ModifySelfAsync(apiArgs, options).ConfigureAwait(false); return await client.ApiClient.ModifySelfAsync(apiArgs, options).ConfigureAwait(false);
} }
public static async Task<GuildUserProperties> ModifyAsync(IGuildUser user, BaseDiscordClient client, Action<GuildUserProperties> func,
public static async Task<GuildUserProperties> ModifyAsync<TState>(IGuildUser user, BaseDiscordClient client,
Action<GuildUserProperties, TState> func,
TState state,
RequestOptions options) RequestOptions options)
{ {
var args = new GuildUserProperties(); var args = new GuildUserProperties();
func(args);
func(args, state);
var apiArgs = new API.Rest.ModifyGuildMemberParams var apiArgs = new API.Rest.ModifyGuildMemberParams
{ {
Deaf = args.Deaf, Deaf = args.Deaf,


+ 4
- 2
src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs View File

@@ -77,9 +77,11 @@ namespace Discord.Rest
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format); => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);


public async Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null)
public Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null)
=> ModifyAsync((props, f) => f(props), func, options);
public async Task ModifyAsync<TState>(Action<WebhookProperties, TState> 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); Update(model);
} }




+ 4
- 4
src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.API.Rest; using Discord.API.Rest;
using ImageModel = Discord.API.Image; using ImageModel = Discord.API.Image;
@@ -8,11 +8,11 @@ namespace Discord.Rest
{ {
internal static class WebhookHelper internal static class WebhookHelper
{ {
public static async Task<Model> ModifyAsync(IWebhook webhook, BaseDiscordClient client,
Action<WebhookProperties> func, RequestOptions options)
public static async Task<Model> ModifyAsync<TState>(IWebhook webhook, BaseDiscordClient client,
Action<WebhookProperties, TState> func, TState state, RequestOptions options)
{ {
var args = new WebhookProperties(); var args = new WebhookProperties();
func(args);
func(args, state);
var apiArgs = new ModifyWebhookParams var apiArgs = new ModifyWebhookParams
{ {
Avatar = args.Image.IsSpecified ? args.Image.Value?.ToModel() : Optional.Create<ImageModel?>(), Avatar = args.Image.IsSpecified ? args.Image.Value?.ToModel() : Optional.Create<ImageModel?>(),


+ 4
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs View File

@@ -75,7 +75,10 @@ namespace Discord.WebSocket


/// <inheritdoc /> /// <inheritdoc />
public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public Task ModifyAsync<TState>(Action<GuildChannelProperties, TState> func, TState state, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, state, options);
/// <inheritdoc /> /// <inheritdoc />
public Task DeleteAsync(RequestOptions options = null) public Task DeleteAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options); => ChannelHelper.DeleteAsync(this, Discord, options);


+ 4
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs View File

@@ -73,7 +73,10 @@ namespace Discord.WebSocket


/// <inheritdoc /> /// <inheritdoc />
public Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<TextChannelProperties> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public Task ModifyAsync<TState>(Action<TextChannelProperties, TState> func, TState state, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, state, options);


//Messages //Messages
/// <inheritdoc /> /// <inheritdoc />


+ 4
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs View File

@@ -59,7 +59,10 @@ namespace Discord.WebSocket


/// <inheritdoc /> /// <inheritdoc />
public Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public Task ModifyAsync<TState>(Action<VoiceChannelProperties, TState> func, TState state, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, state, options);


/// <inheritdoc /> /// <inheritdoc />
public async Task<IAudioClient> ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false) public async Task<IAudioClient> ConnectAsync(bool selfDeaf = false, bool selfMute = false, bool external = false)


+ 10
- 2
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -449,12 +449,20 @@ namespace Discord.WebSocket
/// <inheritdoc /> /// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
public Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null)
=> GuildHelper.ModifyAsync(this, Discord, func, options);
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
public Task ModifyAsync<TState>(Action<GuildProperties, TState> func, TState state, RequestOptions options = null)
=> GuildHelper.ModifyAsync(this, Discord, func, state, options);


/// <inheritdoc /> /// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
public Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null) public Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null)
=> GuildHelper.ModifyEmbedAsync(this, Discord, func, options);
=> ModifyEmbedAsync((props, f) => f(props), func, options);
/// <inheritdoc />
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
public Task ModifyEmbedAsync<TState>(Action<GuildEmbedProperties, TState> func, TState state, RequestOptions options = null)
=> GuildHelper.ModifyEmbedAsync(this, Discord, func, state, options);
/// <inheritdoc /> /// <inheritdoc />
public Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null) public Task ReorderChannelsAsync(IEnumerable<ReorderChannelProperties> args, RequestOptions options = null)
=> GuildHelper.ReorderChannelsAsync(this, Discord, args, options); => GuildHelper.ReorderChannelsAsync(this, Discord, args, options);


+ 6
- 1
src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs View File

@@ -137,7 +137,12 @@ namespace Discord.WebSocket
/// <exception cref="InvalidOperationException">Only the author of a message may modify the message.</exception> /// <exception cref="InvalidOperationException">Only the author of a message may modify the message.</exception>
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
public Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null)
=> MessageHelper.ModifyAsync(this, Discord, func, options);
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
/// <exception cref="InvalidOperationException">Only the author of a message may modify the message.</exception>
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
public Task ModifyAsync<TState>(Action<MessageProperties, TState> func, TState state, RequestOptions options = null)
=> MessageHelper.ModifyAsync(this, Discord, func, state, options);


/// <inheritdoc /> /// <inheritdoc />
public Task PinAsync(RequestOptions options = null) public Task PinAsync(RequestOptions options = null)


+ 4
- 1
src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs View File

@@ -75,7 +75,10 @@ namespace Discord.WebSocket


/// <inheritdoc /> /// <inheritdoc />
public Task ModifyAsync(Action<RoleProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<RoleProperties> func, RequestOptions options = null)
=> RoleHelper.ModifyAsync(this, Discord, func, options);
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public Task ModifyAsync<TState>(Action<RoleProperties, TState> func, TState state, RequestOptions options = null)
=> RoleHelper.ModifyAsync(this, Discord, func, state, options);
/// <inheritdoc /> /// <inheritdoc />
public Task DeleteAsync(RequestOptions options = null) public Task DeleteAsync(RequestOptions options = null)
=> RoleHelper.DeleteAsync(this, Discord, options); => RoleHelper.DeleteAsync(this, Discord, options);


+ 4
- 1
src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs View File

@@ -168,7 +168,10 @@ namespace Discord.WebSocket


/// <inheritdoc /> /// <inheritdoc />
public Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null)
=> UserHelper.ModifyAsync(this, Discord, func, options);
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public Task ModifyAsync<TState>(Action<GuildUserProperties, TState> func, TState state, RequestOptions options = null)
=> UserHelper.ModifyAsync(this, Discord, func, state, options);
/// <inheritdoc /> /// <inheritdoc />
public Task KickAsync(string reason = null, RequestOptions options = null) public Task KickAsync(string reason = null, RequestOptions options = null)
=> UserHelper.KickAsync(this, Discord, reason, options); => UserHelper.KickAsync(this, Discord, reason, options);


+ 5
- 1
src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs View File

@@ -88,8 +88,12 @@ namespace Discord.WebSocket
} }


/// <inheritdoc /> /// <inheritdoc />
/// <exception cref="InvalidOperationException">Unable to modify this object using a different token.</exception>
public Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null)
=> UserHelper.ModifyAsync(this, Discord, func, options);
=> ModifyAsync((props, f) => f(props), func, options);
/// <inheritdoc />
public Task ModifyAsync<TState>(Action<SelfUserProperties, TState> func, TState state, RequestOptions options = null)
=> UserHelper.ModifyAsync(this, Discord, func, state, options);


private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Self)"; private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Self)";
internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser; internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser;


+ 4
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs View File

@@ -78,6 +78,10 @@ namespace Discord.WebSocket
/// <exception cref="NotSupportedException">Webhook users cannot be modified.</exception> /// <exception cref="NotSupportedException">Webhook users cannot be modified.</exception>
Task IGuildUser.ModifyAsync(Action<GuildUserProperties> func, RequestOptions options) => Task IGuildUser.ModifyAsync(Action<GuildUserProperties> func, RequestOptions options) =>
throw new NotSupportedException("Webhook users cannot be modified."); throw new NotSupportedException("Webhook users cannot be modified.");
/// <inheritdoc />
/// <exception cref="NotSupportedException">Webhook users cannot be modified.</exception>
Task IGuildUser.ModifyAsync<TState>(Action<GuildUserProperties, TState> func, TState state, RequestOptions options) =>
throw new NotSupportedException("Webhook users cannot be modified.");


/// <inheritdoc /> /// <inheritdoc />
/// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception> /// <exception cref="NotSupportedException">Roles are not supported on webhook users.</exception>


+ 5
- 3
src/Discord.Net.Webhook/Entities/Webhooks/RestInternalWebhook.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Model = Discord.API.Webhook; using Model = Discord.API.Webhook;
@@ -47,9 +47,11 @@ namespace Discord.Webhook
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format); => CDN.GetUserAvatarUrl(Id, AvatarId, size, format);


public async Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null)
public Task ModifyAsync(Action<WebhookProperties> func, RequestOptions options = null)
=> ModifyAsync((props, f) => f(props), func, options);
public async Task ModifyAsync<TState>(Action<WebhookProperties, TState> 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); Update(model);
} }




+ 3
- 3
src/Discord.Net.Webhook/WebhookClientHelper.cs View File

@@ -59,11 +59,11 @@ namespace Discord.Webhook
return msg.Id; return msg.Id;
} }


public static async Task<WebhookModel> ModifyAsync(DiscordWebhookClient client,
Action<WebhookProperties> func, RequestOptions options)
public static async Task<WebhookModel> ModifyAsync<TState>(DiscordWebhookClient client,
Action<WebhookProperties, TState> func, TState state, RequestOptions options)
{ {
var args = new WebhookProperties(); var args = new WebhookProperties();
func(args);
func(args, state);
var apiArgs = new ModifyWebhookParams var apiArgs = new ModifyWebhookParams
{ {
Avatar = args.Image.IsSpecified ? args.Image.Value?.ToModel() : Optional.Create<ImageModel?>(), Avatar = args.Image.IsSpecified ? args.Image.Value?.ToModel() : Optional.Create<ImageModel?>(),


+ 5
- 0
test/Discord.Net.Tests.Unit/MockedEntities/MockedCategoryChannel.cs View File

@@ -61,6 +61,11 @@ namespace Discord
throw new NotImplementedException(); throw new NotImplementedException();
} }


public Task ModifyAsync<TState>(Action<GuildChannelProperties, TState> func, TState state, RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
{ {
throw new NotImplementedException(); throw new NotImplementedException();


+ 10
- 0
test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs View File

@@ -152,11 +152,21 @@ namespace Discord
throw new NotImplementedException(); throw new NotImplementedException();
} }


public Task ModifyAsync<TState>(Action<TextChannelProperties, TState> func, TState state, RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }


public Task ModifyAsync<TState>(Action<GuildChannelProperties, TState> func, TState state, RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
{ {
throw new NotImplementedException(); throw new NotImplementedException();


+ 10
- 0
test/Discord.Net.Tests.Unit/MockedEntities/MockedVoiceChannel.cs View File

@@ -93,11 +93,21 @@ namespace Discord
throw new NotImplementedException(); throw new NotImplementedException();
} }


public Task ModifyAsync<TState>(Action<VoiceChannelProperties, TState> func, TState state, RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null) public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }


public Task ModifyAsync<TState>(Action<GuildChannelProperties, TState> func, TState state, RequestOptions options = null)
{
throw new NotImplementedException();
}

public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
{ {
throw new NotImplementedException(); throw new NotImplementedException();


Loading…
Cancel
Save