From 8515eec9122a3b2ec427569c8e5a28f54309e027 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:07:22 +0200 Subject: [PATCH 1/9] Implement IMessageProperties --- .../Rest/ForumGuildThreadMessageProperties.cs | 2 +- NetCord/Rest/IMessageProperties.cs | 23 +++++++++++++++++++ NetCord/Rest/InteractionMessageProperties.cs | 2 +- NetCord/Rest/MessageProperties.cs | 2 +- NetCord/Rest/ReplyMessageProperties.cs | 2 +- NetCord/Rest/WebhookMessageProperties.cs | 2 +- 6 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 NetCord/Rest/IMessageProperties.cs diff --git a/NetCord/Rest/ForumGuildThreadMessageProperties.cs b/NetCord/Rest/ForumGuildThreadMessageProperties.cs index b863b6da2..f5451880f 100644 --- a/NetCord/Rest/ForumGuildThreadMessageProperties.cs +++ b/NetCord/Rest/ForumGuildThreadMessageProperties.cs @@ -2,7 +2,7 @@ namespace NetCord.Rest; -public partial class ForumGuildThreadMessageProperties +public partial class ForumGuildThreadMessageProperties : IMessageProperties { [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] [JsonPropertyName("content")] diff --git a/NetCord/Rest/IMessageProperties.cs b/NetCord/Rest/IMessageProperties.cs new file mode 100644 index 000000000..bf97bd1c8 --- /dev/null +++ b/NetCord/Rest/IMessageProperties.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace NetCord.Rest; + +public interface IMessageProperties +{ + public bool Tts { get; set; } + + public string? Content { get; set; } + + public IEnumerable? Embeds { get; set; } + + public AllowedMentionsProperties? AllowedMentions { get; set; } + + public IEnumerable? Attachments { get; set; } + + public MessageFlags? Flags { get; set; } +} diff --git a/NetCord/Rest/InteractionMessageProperties.cs b/NetCord/Rest/InteractionMessageProperties.cs index 515c97536..6fa8bb554 100644 --- a/NetCord/Rest/InteractionMessageProperties.cs +++ b/NetCord/Rest/InteractionMessageProperties.cs @@ -2,7 +2,7 @@ namespace NetCord.Rest; -public partial class InteractionMessageProperties : IHttpSerializable +public partial class InteractionMessageProperties : IHttpSerializable, IMessageProperties { [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] [JsonPropertyName("tts")] diff --git a/NetCord/Rest/MessageProperties.cs b/NetCord/Rest/MessageProperties.cs index 15d32a354..b7773825a 100644 --- a/NetCord/Rest/MessageProperties.cs +++ b/NetCord/Rest/MessageProperties.cs @@ -2,7 +2,7 @@ namespace NetCord.Rest; -public partial class MessageProperties : IHttpSerializable +public partial class MessageProperties : IHttpSerializable, IMessageProperties { [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] [JsonPropertyName("content")] diff --git a/NetCord/Rest/ReplyMessageProperties.cs b/NetCord/Rest/ReplyMessageProperties.cs index 1ea406228..80a6fb8f0 100644 --- a/NetCord/Rest/ReplyMessageProperties.cs +++ b/NetCord/Rest/ReplyMessageProperties.cs @@ -1,6 +1,6 @@ namespace NetCord.Rest; -public partial class ReplyMessageProperties +public partial class ReplyMessageProperties : IMessageProperties { public string? Content { get; set; } public NonceProperties? Nonce { get; set; } diff --git a/NetCord/Rest/WebhookMessageProperties.cs b/NetCord/Rest/WebhookMessageProperties.cs index 9550eeef9..38cc920c1 100644 --- a/NetCord/Rest/WebhookMessageProperties.cs +++ b/NetCord/Rest/WebhookMessageProperties.cs @@ -2,7 +2,7 @@ namespace NetCord.Rest; -public partial class WebhookMessageProperties : IHttpSerializable +public partial class WebhookMessageProperties : IHttpSerializable, IMessageProperties { [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] [JsonPropertyName("content")] From 801ac08aa5ac8b501af734bc20da745447a3b551 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:08:28 +0200 Subject: [PATCH 2/9] Remove unnecessary usings --- NetCord/Rest/IMessageProperties.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/NetCord/Rest/IMessageProperties.cs b/NetCord/Rest/IMessageProperties.cs index bf97bd1c8..9ef4a4755 100644 --- a/NetCord/Rest/IMessageProperties.cs +++ b/NetCord/Rest/IMessageProperties.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json.Serialization; -using System.Threading.Tasks; - -namespace NetCord.Rest; +namespace NetCord.Rest; public interface IMessageProperties { From c0584b38c51e24a9c7b9a02c5aadefd51957b820 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:10:26 +0200 Subject: [PATCH 3/9] Swap TTS with components, oopsie --- NetCord/Rest/IMessageProperties.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NetCord/Rest/IMessageProperties.cs b/NetCord/Rest/IMessageProperties.cs index 9ef4a4755..c44632d7e 100644 --- a/NetCord/Rest/IMessageProperties.cs +++ b/NetCord/Rest/IMessageProperties.cs @@ -2,8 +2,6 @@ public interface IMessageProperties { - public bool Tts { get; set; } - public string? Content { get; set; } public IEnumerable? Embeds { get; set; } @@ -12,5 +10,7 @@ public interface IMessageProperties public IEnumerable? Attachments { get; set; } + public IEnumerable? Components { get; set; } + public MessageFlags? Flags { get; set; } } From 660df951de3066e5708c2554c28feedaf98399e4 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:12:20 +0200 Subject: [PATCH 4/9] Mark IMessageProperties as partial (for SG?) --- NetCord/Rest/IMessageProperties.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NetCord/Rest/IMessageProperties.cs b/NetCord/Rest/IMessageProperties.cs index c44632d7e..c4d3947bd 100644 --- a/NetCord/Rest/IMessageProperties.cs +++ b/NetCord/Rest/IMessageProperties.cs @@ -1,6 +1,6 @@ namespace NetCord.Rest; -public interface IMessageProperties +public partial interface IMessageProperties { public string? Content { get; set; } From 7a31fcc1de87877101bccdca3b1bc1cc854348e4 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:50:29 +0200 Subject: [PATCH 5/9] Init --- .../ApplicationCommandInteractionHandler.cs | 2 +- .../ApplicationCommandResultHandler.cs | 32 +++++++++++++++++++ .../ApplicationCommandServiceOptions.cs | 18 ++--------- .../IApplicationCommandResultHandler.cs | 12 +++++++ .../Commands/CommandHandler.cs | 2 +- .../Commands/CommandResultHandler.cs | 29 +++++++++++++++++ .../Commands/CommandServiceOptions.cs | 22 ++----------- .../Commands/ICommandResultHandler.cs | 12 +++++++ .../ComponentInteractionHandler.cs | 2 +- .../ComponentInteractionResultHandler.cs | 32 +++++++++++++++++++ .../ComponentInteractionServiceOptions.cs | 21 ++---------- .../IComponentInteractionResultHandler.cs | 12 +++++++ .../CustomSlashCommandResultHandler.cs | 24 ++++++++++++++ Tests/NetCord.Test.Hosting/Program.cs | 5 ++- 14 files changed, 168 insertions(+), 57 deletions(-) create mode 100644 Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs create mode 100644 Hosting/NetCord.Hosting.Services/ApplicationCommands/IApplicationCommandResultHandler.cs create mode 100644 Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs create mode 100644 Hosting/NetCord.Hosting.Services/Commands/ICommandResultHandler.cs create mode 100644 Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs create mode 100644 Hosting/NetCord.Hosting.Services/ComponentInteractions/IComponentInteractionResultHandler.cs create mode 100644 Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs index 8548c8606..96bb48d8e 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs @@ -44,7 +44,7 @@ public ApplicationCommandInteractionHandler(IServiceProvider services, _handleAsync = &HandleInteractionAsync; _createContext = optionsValue.CreateContext ?? ContextHelper.CreateContextDelegate(); - _handleResultAsync = optionsValue.HandleResultAsync; + _handleResultAsync = optionsValue.ResultHandler.HandleResultAsync; _client = client; } diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs new file mode 100644 index 000000000..25078accb --- /dev/null +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Microsoft.Extensions.Logging; + +using NetCord.Gateway; +using NetCord.Rest; +using NetCord.Services; +using NetCord.Services.ApplicationCommands; + +namespace NetCord.Hosting.Services.ApplicationCommands; + +public class ApplicationCommandResultHandler : IApplicationCommandResultHandler where TInteraction : ApplicationCommandInteraction where TContext : IApplicationCommandContext +{ + public virtual ValueTask HandleResultAsync(IExecutionResult result, TInteraction interaction, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) + { + if (result is not IFailResult failResult) + return default; + + var message = failResult.Message; + + if (failResult is IExceptionResult exceptionResult) + logger.LogError(exceptionResult.Exception, "Execution of an application command of name '{Name}' failed with an exception", interaction.Data.Name); + else + logger.LogDebug("Execution of an application command of name '{Name}' failed with '{Message}'", interaction.Data.Name, message); + + return new(interaction.SendResponseAsync(InteractionCallback.Message(message))); + } +} diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs index 74ce6cc20..dab13180f 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using NetCord.Gateway; using NetCord.Rest; @@ -15,20 +16,7 @@ public class ApplicationCommandServiceOptions where TInt public Func? CreateContext { get; set; } - public Func HandleResultAsync { get; set; } = (result, interaction, context, client, logger, services) => - { - if (result is not IFailResult failResult) - return default; - - var message = failResult.Message; - - if (failResult is IExceptionResult exceptionResult) - logger.LogError(exceptionResult.Exception, "Execution of an application command of name '{Name}' failed with an exception", interaction.Data.Name); - else - logger.LogDebug("Execution of an application command of name '{Name}' failed with '{Message}'", interaction.Data.Name, message); - - return new(interaction.SendResponseAsync(InteractionCallback.Message(message))); - }; + public IApplicationCommandResultHandler ResultHandler { get; set; } = new ApplicationCommandResultHandler(); } public class ApplicationCommandServiceOptions : ApplicationCommandServiceOptions where TInteraction : ApplicationCommandInteraction where TContext : IApplicationCommandContext where TAutocompleteContext : IAutocompleteInteractionContext diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/IApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/IApplicationCommandResultHandler.cs new file mode 100644 index 000000000..7fefef553 --- /dev/null +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/IApplicationCommandResultHandler.cs @@ -0,0 +1,12 @@ +using Microsoft.Extensions.Logging; + +using NetCord.Gateway; +using NetCord.Services; +using NetCord.Services.ApplicationCommands; + +namespace NetCord.Hosting.Services.ApplicationCommands; + +public interface IApplicationCommandResultHandler where TInteraction : ApplicationCommandInteraction where TContext : IApplicationCommandContext +{ + public ValueTask HandleResultAsync(IExecutionResult result, TInteraction interaction, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services); +} diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs index 5ef026c5d..63808de96 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs @@ -46,7 +46,7 @@ public CommandHandler(IServiceProvider services, _getPrefixLengthAsync = GetGetPrefixLengthAsyncDelegate(optionsValue); _createContext = optionsValue.CreateContext ?? ContextHelper.CreateContextDelegate(); - _handleResultAsync = optionsValue.HandleResultAsync; + _handleResultAsync = optionsValue.ResultHandler.HandleResultAsync; _client = client; } diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs new file mode 100644 index 000000000..f7d5b2242 --- /dev/null +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs @@ -0,0 +1,29 @@ +using Microsoft.Extensions.Logging; + +using NetCord.Gateway; +using NetCord.Services; +using NetCord.Services.Commands; + +namespace NetCord.Hosting.Services.Commands; + +public class CommandResultHandler : ICommandResultHandler where TContext : ICommandContext +{ + public virtual ValueTask HandleResultAsync(IExecutionResult result, Message message, TContext context, GatewayClient client, ILogger logger, IServiceProvider services) + { + if (result is not IFailResult failResult) + return default; + + string resultMessage = failResult.Message; + + if (failResult is IExceptionResult exceptionResult) + logger.LogError(exceptionResult.Exception, "Execution of a command with content '{Content}' failed with an exception", message.Content); + else + logger.LogDebug("Execution of a command with content '{Content}' failed with '{Message}'", message.Content, resultMessage); + + return new(message.ReplyAsync(new() + { + Content = resultMessage, + FailIfNotExists = false, + })); + } +} diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandServiceOptions.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandServiceOptions.cs index 32bcdc839..2acf6b799 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandServiceOptions.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandServiceOptions.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using NetCord.Gateway; using NetCord.Services; @@ -20,22 +21,5 @@ public class CommandServiceOptions where TContext : ICommandContext public Func? CreateContext { get; set; } - public Func HandleResultAsync { get; set; } = (result, message, context, client, logger, services) => - { - if (result is not IFailResult failResult) - return default; - - string resultMessage = failResult.Message; - - if (failResult is IExceptionResult exceptionResult) - logger.LogError(exceptionResult.Exception, "Execution of a command with content '{Content}' failed with an exception", message.Content); - else - logger.LogDebug("Execution of a command with content '{Content}' failed with '{Message}'", message.Content, resultMessage); - - return new(message.ReplyAsync(new() - { - Content = resultMessage, - FailIfNotExists = false, - })); - }; + public ICommandResultHandler ResultHandler { get; set; } = new CommandResultHandler(); } diff --git a/Hosting/NetCord.Hosting.Services/Commands/ICommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/ICommandResultHandler.cs new file mode 100644 index 000000000..d4151fe33 --- /dev/null +++ b/Hosting/NetCord.Hosting.Services/Commands/ICommandResultHandler.cs @@ -0,0 +1,12 @@ +using Microsoft.Extensions.Logging; + +using NetCord.Gateway; +using NetCord.Services; +using NetCord.Services.Commands; + +namespace NetCord.Hosting.Services.Commands; + +public interface ICommandResultHandler where TContext : ICommandContext +{ + public ValueTask HandleResultAsync(IExecutionResult result, Message message, TContext context, GatewayClient client, ILogger logger, IServiceProvider services); +} diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs index 04b5e37ea..c54d2a159 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs @@ -44,7 +44,7 @@ public ComponentInteractionHandler(IServiceProvider services, _handleAsync = &HandleInteractionAsync; _createContext = optionsValue.CreateContext ?? ContextHelper.CreateContextDelegate(); - _handleResultAsync = optionsValue.HandleResultAsync; + _handleResultAsync = optionsValue.ResultHandler.HandleResultAsync; _client = client; } diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs new file mode 100644 index 000000000..0f2564254 --- /dev/null +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Microsoft.Extensions.Logging; + +using NetCord.Gateway; +using NetCord.Rest; +using NetCord.Services; +using NetCord.Services.ComponentInteractions; + +namespace NetCord.Hosting.Services.ComponentInteractions; + +public class ComponentInteractionResultHandler : IComponentInteractionResultHandler where TInteraction : Interaction where TContext : IComponentInteractionContext +{ + public virtual ValueTask HandleResultAsync(IExecutionResult result, TInteraction interaction, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) + { + if (result is not IFailResult failResult) + return default; + + var message = failResult.Message; + + if (failResult is IExceptionResult exceptionResult) + logger.LogError(exceptionResult.Exception, "Execution of an interaction of custom ID '{Id}' failed with an exception", interaction.Id); + else + logger.LogDebug("Execution of an interaction of custom ID '{Id}' failed with '{Message}'", interaction.Id, message); + + return new(interaction.SendResponseAsync(InteractionCallback.Message(message))); + } +} diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionServiceOptions.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionServiceOptions.cs index 84798d62b..5660cab8e 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionServiceOptions.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionServiceOptions.cs @@ -1,8 +1,4 @@ -using Microsoft.Extensions.Logging; - -using NetCord.Gateway; -using NetCord.Rest; -using NetCord.Services; +using NetCord.Gateway; using NetCord.Services.ComponentInteractions; namespace NetCord.Hosting.Services.ComponentInteractions; @@ -15,18 +11,5 @@ public class ComponentInteractionServiceOptions where TI public Func? CreateContext { get; set; } - public Func HandleResultAsync { get; set; } = (result, interaction, context, client, logger, services) => - { - if (result is not IFailResult failResult) - return default; - - var message = failResult.Message; - - if (failResult is IExceptionResult exceptionResult) - logger.LogError(exceptionResult.Exception, "Execution of an interaction of custom ID '{Id}' failed with an exception", interaction.Id); - else - logger.LogDebug("Execution of an interaction of custom ID '{Id}' failed with '{Message}'", interaction.Id, message); - - return new(interaction.SendResponseAsync(InteractionCallback.Message(message))); - }; + public IComponentInteractionResultHandler ResultHandler { get; set; } = new ComponentInteractionResultHandler(); } diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/IComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/IComponentInteractionResultHandler.cs new file mode 100644 index 000000000..35bb1873b --- /dev/null +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/IComponentInteractionResultHandler.cs @@ -0,0 +1,12 @@ +using Microsoft.Extensions.Logging; + +using NetCord.Gateway; +using NetCord.Services; +using NetCord.Services.ComponentInteractions; + +namespace NetCord.Hosting.Services.ComponentInteractions; + +public interface IComponentInteractionResultHandler where TInteraction : Interaction where TContext : IComponentInteractionContext +{ + public ValueTask HandleResultAsync(IExecutionResult result, TInteraction interaction, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services); +} diff --git a/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs b/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs new file mode 100644 index 000000000..ea369fd6f --- /dev/null +++ b/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Microsoft.Extensions.Logging; + +using NetCord.Gateway; +using NetCord.Hosting.Services.ApplicationCommands; +using NetCord.Services; +using NetCord.Services.ApplicationCommands; + +namespace NetCord.Test.Hosting; + +internal class CustomSlashCommandResultHandler : ApplicationCommandResultHandler +{ + public override ValueTask HandleResultAsync(IExecutionResult result, SlashCommandInteraction interaction, SlashCommandContext context, GatewayClient? client, ILogger logger, IServiceProvider services) + { + logger.LogInformation("Handling result of slash command"); + + return base.HandleResultAsync(result, interaction, context, client, logger, services); + } +} diff --git a/Tests/NetCord.Test.Hosting/Program.cs b/Tests/NetCord.Test.Hosting/Program.cs index 1536c37b1..f5e546def 100644 --- a/Tests/NetCord.Test.Hosting/Program.cs +++ b/Tests/NetCord.Test.Hosting/Program.cs @@ -39,7 +39,10 @@ { Intents = GatewayIntents.All, }) - .AddApplicationCommands() + .AddApplicationCommands(options => + { + options.ResultHandler = new CustomSlashCommandResultHandler(); + }) .AddApplicationCommands() .AddApplicationCommands() .AddComponentInteractions() From df133d5fa33b4862ace2810d72d660c903c295fc Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:53:40 +0200 Subject: [PATCH 6/9] Clean usings --- .../ApplicationCommandResultHandler.cs | 8 +------- .../ApplicationCommandServiceOptions.cs | 4 +--- .../Commands/CommandServiceOptions.cs | 6 +----- .../ComponentInteractionResultHandler.cs | 8 +------- 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index 25078accb..36bdd45f1 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using NetCord.Gateway; using NetCord.Rest; diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs index dab13180f..56c94de0d 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs @@ -1,8 +1,6 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using NetCord.Gateway; -using NetCord.Rest; using NetCord.Services; using NetCord.Services.ApplicationCommands; diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandServiceOptions.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandServiceOptions.cs index 2acf6b799..de132b816 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandServiceOptions.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandServiceOptions.cs @@ -1,8 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -using NetCord.Gateway; -using NetCord.Services; +using NetCord.Gateway; using NetCord.Services.Commands; namespace NetCord.Hosting.Services.Commands; diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index 0f2564254..d9caaffae 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using NetCord.Gateway; using NetCord.Rest; From 2c7206db74e283ec176a720ef8bbbe6f7f1feb2b Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:55:06 +0200 Subject: [PATCH 7/9] ^ (again) --- .../CustomSlashCommandResultHandler.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs b/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs index ea369fd6f..a74251702 100644 --- a/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs +++ b/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using NetCord.Gateway; using NetCord.Hosting.Services.ApplicationCommands; From abc1a543548de227e25fac78559e2d9dc77ab516 Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:56:16 +0200 Subject: [PATCH 8/9] Take suggestions --- .../ApplicationCommandInteractionHandler.cs | 6 +++--- .../ApplicationCommandResultHandler.cs | 20 +++++++++++++------ .../ApplicationCommandServiceOptions.cs | 2 +- .../IApplicationCommandResultHandler.cs | 4 ++-- .../Commands/CommandHandler.cs | 6 +++--- .../Commands/CommandResultHandler.cs | 7 +++++-- .../ComponentInteractionHandler.cs | 6 +++--- .../ComponentInteractionResultHandler.cs | 20 +++++++++++++------ .../ComponentInteractionServiceOptions.cs | 2 +- .../IComponentInteractionResultHandler.cs | 4 ++-- .../CustomSlashCommandResultHandler.cs | 8 +++++--- 11 files changed, 53 insertions(+), 32 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs index 96bb48d8e..2edd0d5b2 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandInteractionHandler.cs @@ -19,7 +19,7 @@ internal unsafe partial class ApplicationCommandInteractionHandler, Interaction, GatewayClient?, ValueTask> _handleAsync; private readonly Func _createContext; - private readonly Func _handleResultAsync; + private readonly IApplicationCommandResultHandler _resultHandler; private readonly GatewayClient? _client; public ApplicationCommandInteractionHandler(IServiceProvider services, @@ -44,7 +44,7 @@ public ApplicationCommandInteractionHandler(IServiceProvider services, _handleAsync = &HandleInteractionAsync; _createContext = optionsValue.CreateContext ?? ContextHelper.CreateContextDelegate(); - _handleResultAsync = optionsValue.ResultHandler.HandleResultAsync; + _resultHandler = optionsValue.ResultHandler; _client = client; } @@ -89,7 +89,7 @@ private async ValueTask HandleInteractionAsyncCore(TInteraction interaction, Gat try { - await _handleResultAsync(result, interaction, context, client, _logger, services).ConfigureAwait(false); + await _resultHandler.HandleResultAsync(result, context, client, _logger, services).ConfigureAwait(false); } catch (Exception exceptionHandlerException) { diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index 36bdd45f1..8edb89822 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -7,20 +7,28 @@ namespace NetCord.Hosting.Services.ApplicationCommands; -public class ApplicationCommandResultHandler : IApplicationCommandResultHandler where TInteraction : ApplicationCommandInteraction where TContext : IApplicationCommandContext +public class ApplicationCommandResultHandler(MessageFlags? onFailResultResponseFlags = null) : IApplicationCommandResultHandler where TContext : IApplicationCommandContext { - public virtual ValueTask HandleResultAsync(IExecutionResult result, TInteraction interaction, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) + public MessageFlags? OnFailResultResponseFlags { get; set; } = onFailResultResponseFlags; + + public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) return default; - var message = failResult.Message; + var resultMessage = failResult.Message; if (failResult is IExceptionResult exceptionResult) - logger.LogError(exceptionResult.Exception, "Execution of an application command of name '{Name}' failed with an exception", interaction.Data.Name); + logger.LogError(exceptionResult.Exception, "Execution of an application command of name '{Name}' failed with an exception", context.Interaction.Data.Name); else - logger.LogDebug("Execution of an application command of name '{Name}' failed with '{Message}'", interaction.Data.Name, message); + logger.LogDebug("Execution of an application command of name '{Name}' failed with '{Message}'", context.Interaction.Data.Name, resultMessage); + + var message = new InteractionMessageProperties() + { + Content = resultMessage, + Flags = OnFailResultResponseFlags + }; - return new(interaction.SendResponseAsync(InteractionCallback.Message(message))); + return new(context.Interaction.SendResponseAsync(InteractionCallback.Message(message))); } } diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs index 56c94de0d..50307155b 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandServiceOptions.cs @@ -14,7 +14,7 @@ public class ApplicationCommandServiceOptions where TInt public Func? CreateContext { get; set; } - public IApplicationCommandResultHandler ResultHandler { get; set; } = new ApplicationCommandResultHandler(); + public IApplicationCommandResultHandler ResultHandler { get; set; } = new ApplicationCommandResultHandler(); } public class ApplicationCommandServiceOptions : ApplicationCommandServiceOptions where TInteraction : ApplicationCommandInteraction where TContext : IApplicationCommandContext where TAutocompleteContext : IAutocompleteInteractionContext diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/IApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/IApplicationCommandResultHandler.cs index 7fefef553..61eaf5761 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/IApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/IApplicationCommandResultHandler.cs @@ -6,7 +6,7 @@ namespace NetCord.Hosting.Services.ApplicationCommands; -public interface IApplicationCommandResultHandler where TInteraction : ApplicationCommandInteraction where TContext : IApplicationCommandContext +public interface IApplicationCommandResultHandler where TContext : IApplicationCommandContext { - public ValueTask HandleResultAsync(IExecutionResult result, TInteraction interaction, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services); + public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services); } diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs index 63808de96..7481aba22 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandHandler.cs @@ -20,7 +20,7 @@ internal unsafe partial class CommandHandler : IGatewayEventHandler, Message, GatewayClient, ValueTask> _handleAsync; private readonly Func> _getPrefixLengthAsync; private readonly Func _createContext; - private readonly Func _handleResultAsync; + private readonly ICommandResultHandler _resultHandler; private readonly GatewayClient? _client; public CommandHandler(IServiceProvider services, @@ -46,7 +46,7 @@ public CommandHandler(IServiceProvider services, _getPrefixLengthAsync = GetGetPrefixLengthAsyncDelegate(optionsValue); _createContext = optionsValue.CreateContext ?? ContextHelper.CreateContextDelegate(); - _handleResultAsync = optionsValue.ResultHandler.HandleResultAsync; + _resultHandler = optionsValue.ResultHandler; _client = client; } @@ -134,7 +134,7 @@ private async ValueTask HandleMessageAsyncCore(Message message, GatewayClient cl try { - await _handleResultAsync(result, message, context, client, _logger, services).ConfigureAwait(false); + await _resultHandler.HandleResultAsync(result, message, context, client, _logger, services).ConfigureAwait(false); } catch (Exception exceptionHandlerException) { diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs index f7d5b2242..45b588f1b 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs @@ -6,9 +6,11 @@ namespace NetCord.Hosting.Services.Commands; -public class CommandResultHandler : ICommandResultHandler where TContext : ICommandContext +public class CommandResultHandler(MessageFlags? onFailResultResponseFlags = null) : ICommandResultHandler where TContext : ICommandContext { - public virtual ValueTask HandleResultAsync(IExecutionResult result, Message message, TContext context, GatewayClient client, ILogger logger, IServiceProvider services) + public MessageFlags? OnFailResultResponseFlags { get; set; } = onFailResultResponseFlags; + + public ValueTask HandleResultAsync(IExecutionResult result, Message message, TContext context, GatewayClient client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) return default; @@ -24,6 +26,7 @@ public virtual ValueTask HandleResultAsync(IExecutionResult result, Message mess { Content = resultMessage, FailIfNotExists = false, + Flags = OnFailResultResponseFlags, })); } } diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs index c54d2a159..e5387f1e5 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionHandler.cs @@ -19,7 +19,7 @@ internal unsafe partial class ComponentInteractionHandler, Interaction, GatewayClient?, ValueTask> _handleAsync; private readonly Func _createContext; - private readonly Func _handleResultAsync; + private readonly IComponentInteractionResultHandler _resultHandler; private readonly GatewayClient? _client; public ComponentInteractionHandler(IServiceProvider services, @@ -44,7 +44,7 @@ public ComponentInteractionHandler(IServiceProvider services, _handleAsync = &HandleInteractionAsync; _createContext = optionsValue.CreateContext ?? ContextHelper.CreateContextDelegate(); - _handleResultAsync = optionsValue.ResultHandler.HandleResultAsync; + _resultHandler = optionsValue.ResultHandler; _client = client; } @@ -89,7 +89,7 @@ private async ValueTask HandleInteractionAsyncCore(TInteraction interaction, Gat try { - await _handleResultAsync(result, interaction, context, client, _logger, services).ConfigureAwait(false); + await _resultHandler.HandleResultAsync(result, context, client, _logger, services).ConfigureAwait(false); } catch (Exception exceptionHandlerException) { diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index d9caaffae..71a1ee3be 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -7,20 +7,28 @@ namespace NetCord.Hosting.Services.ComponentInteractions; -public class ComponentInteractionResultHandler : IComponentInteractionResultHandler where TInteraction : Interaction where TContext : IComponentInteractionContext +public class ComponentInteractionResultHandler(MessageFlags? onFailResultResponseFlags = null) : IComponentInteractionResultHandler where TContext : IComponentInteractionContext { - public virtual ValueTask HandleResultAsync(IExecutionResult result, TInteraction interaction, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) + public MessageFlags? OnFailResultResponseFlags { get; set; } = onFailResultResponseFlags; + + public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) return default; - var message = failResult.Message; + var resultMessage = failResult.Message; if (failResult is IExceptionResult exceptionResult) - logger.LogError(exceptionResult.Exception, "Execution of an interaction of custom ID '{Id}' failed with an exception", interaction.Id); + logger.LogError(exceptionResult.Exception, "Execution of an interaction of custom ID '{Id}' failed with an exception", context.Interaction.Id); else - logger.LogDebug("Execution of an interaction of custom ID '{Id}' failed with '{Message}'", interaction.Id, message); + logger.LogDebug("Execution of an interaction of custom ID '{Id}' failed with '{Message}'", context.Interaction.Id, resultMessage); + + var message = new InteractionMessageProperties() + { + Content = resultMessage, + Flags = OnFailResultResponseFlags, + }; - return new(interaction.SendResponseAsync(InteractionCallback.Message(message))); + return new(context.Interaction.SendResponseAsync(InteractionCallback.Message(message))); } } diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionServiceOptions.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionServiceOptions.cs index 5660cab8e..21d5d51fb 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionServiceOptions.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionServiceOptions.cs @@ -11,5 +11,5 @@ public class ComponentInteractionServiceOptions where TI public Func? CreateContext { get; set; } - public IComponentInteractionResultHandler ResultHandler { get; set; } = new ComponentInteractionResultHandler(); + public IComponentInteractionResultHandler ResultHandler { get; set; } = new ComponentInteractionResultHandler(); } diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/IComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/IComponentInteractionResultHandler.cs index 35bb1873b..ea5b6a073 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/IComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/IComponentInteractionResultHandler.cs @@ -6,7 +6,7 @@ namespace NetCord.Hosting.Services.ComponentInteractions; -public interface IComponentInteractionResultHandler where TInteraction : Interaction where TContext : IComponentInteractionContext +public interface IComponentInteractionResultHandler where TContext : IComponentInteractionContext { - public ValueTask HandleResultAsync(IExecutionResult result, TInteraction interaction, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services); + public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services); } diff --git a/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs b/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs index a74251702..51b0dfce8 100644 --- a/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs +++ b/Tests/NetCord.Test.Hosting/CustomSlashCommandResultHandler.cs @@ -7,12 +7,14 @@ namespace NetCord.Test.Hosting; -internal class CustomSlashCommandResultHandler : ApplicationCommandResultHandler +internal class CustomSlashCommandResultHandler : IApplicationCommandResultHandler { - public override ValueTask HandleResultAsync(IExecutionResult result, SlashCommandInteraction interaction, SlashCommandContext context, GatewayClient? client, ILogger logger, IServiceProvider services) + private static readonly ApplicationCommandResultHandler _defaultHandler = new(MessageFlags.Ephemeral); + + public ValueTask HandleResultAsync(IExecutionResult result, SlashCommandContext context, GatewayClient? client, ILogger logger, IServiceProvider services) { logger.LogInformation("Handling result of slash command"); - return base.HandleResultAsync(result, interaction, context, client, logger, services); + return _defaultHandler.HandleResultAsync(result, context, client, logger, services); } } From 0c791f4e63b56fd51b57332cced8fd03888c02ca Mon Sep 17 00:00:00 2001 From: Armano den Boef <68127614+Rozen4334@users.noreply.github.com> Date: Fri, 9 Aug 2024 21:09:27 +0200 Subject: [PATCH 9/9] Clarity & accessibility reduction, take suggestion --- .../ApplicationCommands/ApplicationCommandResultHandler.cs | 6 ++---- .../Commands/CommandResultHandler.cs | 6 ++---- .../ComponentInteractionResultHandler.cs | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs index 8edb89822..32c6cba1b 100644 --- a/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ApplicationCommands/ApplicationCommandResultHandler.cs @@ -7,10 +7,8 @@ namespace NetCord.Hosting.Services.ApplicationCommands; -public class ApplicationCommandResultHandler(MessageFlags? onFailResultResponseFlags = null) : IApplicationCommandResultHandler where TContext : IApplicationCommandContext +public class ApplicationCommandResultHandler(MessageFlags? messageFlags = null) : IApplicationCommandResultHandler where TContext : IApplicationCommandContext { - public MessageFlags? OnFailResultResponseFlags { get; set; } = onFailResultResponseFlags; - public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) @@ -26,7 +24,7 @@ public ValueTask HandleResultAsync(IExecutionResult result, TContext context, Ga var message = new InteractionMessageProperties() { Content = resultMessage, - Flags = OnFailResultResponseFlags + Flags = messageFlags }; return new(context.Interaction.SendResponseAsync(InteractionCallback.Message(message))); diff --git a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs index 45b588f1b..6ddbc9728 100644 --- a/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/Commands/CommandResultHandler.cs @@ -6,10 +6,8 @@ namespace NetCord.Hosting.Services.Commands; -public class CommandResultHandler(MessageFlags? onFailResultResponseFlags = null) : ICommandResultHandler where TContext : ICommandContext +public class CommandResultHandler(MessageFlags? messageFlags = null) : ICommandResultHandler where TContext : ICommandContext { - public MessageFlags? OnFailResultResponseFlags { get; set; } = onFailResultResponseFlags; - public ValueTask HandleResultAsync(IExecutionResult result, Message message, TContext context, GatewayClient client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) @@ -26,7 +24,7 @@ public ValueTask HandleResultAsync(IExecutionResult result, Message message, TCo { Content = resultMessage, FailIfNotExists = false, - Flags = OnFailResultResponseFlags, + Flags = messageFlags, })); } } diff --git a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs index 71a1ee3be..c1d2ad730 100644 --- a/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs +++ b/Hosting/NetCord.Hosting.Services/ComponentInteractions/ComponentInteractionResultHandler.cs @@ -7,10 +7,8 @@ namespace NetCord.Hosting.Services.ComponentInteractions; -public class ComponentInteractionResultHandler(MessageFlags? onFailResultResponseFlags = null) : IComponentInteractionResultHandler where TContext : IComponentInteractionContext +public class ComponentInteractionResultHandler(MessageFlags? messageFlags = null) : IComponentInteractionResultHandler where TContext : IComponentInteractionContext { - public MessageFlags? OnFailResultResponseFlags { get; set; } = onFailResultResponseFlags; - public ValueTask HandleResultAsync(IExecutionResult result, TContext context, GatewayClient? client, ILogger logger, IServiceProvider services) { if (result is not IFailResult failResult) @@ -26,7 +24,7 @@ public ValueTask HandleResultAsync(IExecutionResult result, TContext context, Ga var message = new InteractionMessageProperties() { Content = resultMessage, - Flags = OnFailResultResponseFlags, + Flags = messageFlags, }; return new(context.Interaction.SendResponseAsync(InteractionCallback.Message(message)));