diff --git a/samples/HelloWorldButton/Commands/HelloWorldButtonCommand.cs b/samples/HelloWorldButton/Commands/HelloWorldButtonCommand.cs index f4e8fd07..8199e679 100644 --- a/samples/HelloWorldButton/Commands/HelloWorldButtonCommand.cs +++ b/samples/HelloWorldButton/Commands/HelloWorldButtonCommand.cs @@ -30,10 +30,10 @@ public async Task> InitButtonAsync() var actionRowBuilder = new ActionRowComponentBuilder() .WithButton("Hello world", DiscordButtonStyle.Primary, HelloWorldComponent.HelloWorldComponentId); - var responseBuilder = new SlashCommandResponseBuilder() + var responseBuilder = new InteractionResponseBuilder() .WithContent("hello world button") .WithComponent(actionRowBuilder.Build()); - + // Return the response to Discord. return FromSuccess(responseBuilder.Build()); } diff --git a/samples/HelloWorldButton/Components/HelloWorldComponent.cs b/samples/HelloWorldButton/Components/HelloWorldComponent.cs index 3da41f27..7c8713d8 100644 --- a/samples/HelloWorldButton/Components/HelloWorldComponent.cs +++ b/samples/HelloWorldButton/Components/HelloWorldComponent.cs @@ -18,12 +18,12 @@ public class HelloWorldComponent : ComponentInteractionModule public const string HelloWorldComponentId = "hello_world"; /// - /// Edits a message with a component with the id of . + /// Edits a message with a component with the id of . /// [Component(HelloWorldComponentId, DiscordComponentType.Button)] public async Task> HelloWorldButtonAsync() { - var response = new SlashCommandResponseBuilder() + var response = new InteractionResponseBuilder() .WithContent("Hello world!") .EmptyComponents() .Build(DiscordInteractionResponseType.UpdateMessage); diff --git a/samples/HelloWorldButton/HelloWorldButton.csproj b/samples/HelloWorldButton/HelloWorldButton.csproj index 6bc08f8f..11976262 100644 --- a/samples/HelloWorldButton/HelloWorldButton.csproj +++ b/samples/HelloWorldButton/HelloWorldButton.csproj @@ -5,7 +5,7 @@ - + diff --git a/samples/HelloWorldButton/Startup.cs b/samples/HelloWorldButton/Startup.cs index fcae17f5..cab52e3f 100644 --- a/samples/HelloWorldButton/Startup.cs +++ b/samples/HelloWorldButton/Startup.cs @@ -27,10 +27,7 @@ public void ConfigureServices(IServiceCollection services) slashOptions.EnableAutoSync = true; slashOptions.SendDefaultErrorMessage = true; }, - ComponentInteractionConfig = componentOptions => - { - componentOptions.SendDefaultErrorMessage = true; - } + ComponentInteractionConfig = componentOptions => { componentOptions.SendDefaultErrorMessage = true; } }; // Replace the arguments with the data of your bot. diff --git a/src/Color-Chan.Discord.Commands/Attributes/ComponentAttribute.cs b/src/Color-Chan.Discord.Commands/Attributes/ComponentAttribute.cs index 7714b325..918c5616 100644 --- a/src/Color-Chan.Discord.Commands/Attributes/ComponentAttribute.cs +++ b/src/Color-Chan.Discord.Commands/Attributes/ComponentAttribute.cs @@ -19,7 +19,8 @@ public class ComponentAttribute : Attribute /// from turning inactive after 3 seconds. /// /// - /// Whether or not the original message of the component should be edited with the returned response. Ignored if is set to false. + /// Whether or not the original message of the component should be edited with the returned response. Ignored if + /// is set to false. /// public ComponentAttribute(string customId, DiscordComponentType type, bool acknowledge = false, bool editOriginalMessage = false) { diff --git a/src/Color-Chan.Discord.Commands/Attributes/ProvidedRequirements/RequireDmAttribute.cs b/src/Color-Chan.Discord.Commands/Attributes/ProvidedRequirements/RequireDmAttribute.cs index c417e73a..292f9af2 100644 --- a/src/Color-Chan.Discord.Commands/Attributes/ProvidedRequirements/RequireDmAttribute.cs +++ b/src/Color-Chan.Discord.Commands/Attributes/ProvidedRequirements/RequireDmAttribute.cs @@ -36,7 +36,7 @@ public override Task CheckRequirementAsync(IInteractionContext context, return Task.FromResult(Result.FromSuccess()); } - return Task.FromResult(Result.FromError(new SlashCommandRequireDmErrorResult("Interaction can not be executed in a guild"))); + return Task.FromResult(Result.FromError(new RequireDmErrorResult("Interaction can not be executed in a guild"))); } } } \ No newline at end of file diff --git a/src/Color-Chan.Discord.Commands/Attributes/ProvidedRequirements/UserRateLimitAttribute.cs b/src/Color-Chan.Discord.Commands/Attributes/ProvidedRequirements/UserRateLimitAttribute.cs index 237eb78c..66b94c12 100644 --- a/src/Color-Chan.Discord.Commands/Attributes/ProvidedRequirements/UserRateLimitAttribute.cs +++ b/src/Color-Chan.Discord.Commands/Attributes/ProvidedRequirements/UserRateLimitAttribute.cs @@ -13,7 +13,8 @@ namespace Color_Chan.Discord.Commands.Attributes.ProvidedRequirements /// This requirement will limit the amount of time a user can request interactions during a time period. /// /// - /// This example limits all the interaction commands in the PongCommands interaction command module to 2 requests every 10 seconds + /// This example limits all the interaction commands in the PongCommands interaction command module to 2 requests every + /// 10 seconds /// and 4 requests every 30 seconds per user. You can also put the on /// a method if /// you only want to rate limit a specific interaction. diff --git a/src/Color-Chan.Discord.Commands/Color-Chan.Discord.Commands.csproj b/src/Color-Chan.Discord.Commands/Color-Chan.Discord.Commands.csproj index 8c978414..b270130a 100644 --- a/src/Color-Chan.Discord.Commands/Color-Chan.Discord.Commands.csproj +++ b/src/Color-Chan.Discord.Commands/Color-Chan.Discord.Commands.csproj @@ -7,14 +7,14 @@ - - - + + + - - + + @@ -53,7 +53,7 @@ - + diff --git a/src/Color-Chan.Discord.Commands/Configurations/ComponentInteractionConfiguration.cs b/src/Color-Chan.Discord.Commands/Configurations/ComponentInteractionConfiguration.cs index bbd88e72..255dfb02 100644 --- a/src/Color-Chan.Discord.Commands/Configurations/ComponentInteractionConfiguration.cs +++ b/src/Color-Chan.Discord.Commands/Configurations/ComponentInteractionConfiguration.cs @@ -12,7 +12,7 @@ public class ComponentInteractionConfiguration /// unsuccessfully. Default: false. /// public bool SendDefaultErrorMessage { get; set; } - + /// /// Whether or not should be auto loaded on command requests. Default: false. /// diff --git a/src/Color-Chan.Discord.Commands/Configurations/SlashCommandConfiguration.cs b/src/Color-Chan.Discord.Commands/Configurations/SlashCommandConfiguration.cs index 21b27d6b..b043d51e 100644 --- a/src/Color-Chan.Discord.Commands/Configurations/SlashCommandConfiguration.cs +++ b/src/Color-Chan.Discord.Commands/Configurations/SlashCommandConfiguration.cs @@ -11,7 +11,6 @@ public class SlashCommandConfiguration /// Whether or not the slash commands auto sync feature is enabled. Default: true. /// public bool EnableAutoSync { get; set; } = true; - /// /// Whether or not should be auto loaded on command requests. Default: false. diff --git a/src/Color-Chan.Discord.Commands/Exceptions/ComponentInteractionResultException.cs b/src/Color-Chan.Discord.Commands/Exceptions/ComponentInteractionResultException.cs index 4969146a..d829ad11 100644 --- a/src/Color-Chan.Discord.Commands/Exceptions/ComponentInteractionResultException.cs +++ b/src/Color-Chan.Discord.Commands/Exceptions/ComponentInteractionResultException.cs @@ -3,7 +3,8 @@ namespace Color_Chan.Discord.Commands.Exceptions { /// - /// An exception that should be thrown when a component interaction failed to execute and has not properly been handled. + /// An exception that should be thrown when a component interaction failed to execute and has not properly been + /// handled. /// public class ComponentInteractionResultException : Exception { diff --git a/src/Color-Chan.Discord.Commands/Extensions/ServiceCollectionExtensions.cs b/src/Color-Chan.Discord.Commands/Extensions/ServiceCollectionExtensions.cs index 2bb29fcf..41a6d643 100644 --- a/src/Color-Chan.Discord.Commands/Extensions/ServiceCollectionExtensions.cs +++ b/src/Color-Chan.Discord.Commands/Extensions/ServiceCollectionExtensions.cs @@ -47,7 +47,7 @@ public static IServiceCollection AddColorChanDiscordCommand(this IServiceCollect services.TryAddTransient(); services.TryAddTransient(); services.TryAddTransient(); - + services.TryAddTransient(); services.TryAddTransient(); diff --git a/src/Color-Chan.Discord.Commands/MessageBuilders/SlashCommandResponseBuilder.cs b/src/Color-Chan.Discord.Commands/MessageBuilders/InteractionResponseBuilder.cs similarity index 80% rename from src/Color-Chan.Discord.Commands/MessageBuilders/SlashCommandResponseBuilder.cs rename to src/Color-Chan.Discord.Commands/MessageBuilders/InteractionResponseBuilder.cs index 1172bf19..c5079fea 100644 --- a/src/Color-Chan.Discord.Commands/MessageBuilders/SlashCommandResponseBuilder.cs +++ b/src/Color-Chan.Discord.Commands/MessageBuilders/InteractionResponseBuilder.cs @@ -12,7 +12,7 @@ namespace Color_Chan.Discord.Commands.MessageBuilders /// /// Represents a builder class for creating s. /// - public class SlashCommandResponseBuilder + public class InteractionResponseBuilder { private const int MaxEmbeds = 10; @@ -50,9 +50,9 @@ public class SlashCommandResponseBuilder /// Enables Text To Speech for the response. /// /// - /// The updated . + /// The updated . /// - public SlashCommandResponseBuilder EnableTts() + public InteractionResponseBuilder EnableTts() { _isTts = true; return this; @@ -62,7 +62,7 @@ public SlashCommandResponseBuilder EnableTts() /// Makes the response only visible to the person that has used the slash command. /// /// - public SlashCommandResponseBuilder MakePrivate() + public InteractionResponseBuilder MakePrivate() { _flags = DiscordInteractionCallbackFlags.Ephemeral; return this; @@ -73,9 +73,9 @@ public SlashCommandResponseBuilder MakePrivate() /// /// The content. /// - /// The updated . + /// The updated . /// - public SlashCommandResponseBuilder WithContent(string content) + public InteractionResponseBuilder WithContent(string content) { _content = content; return this; @@ -86,10 +86,10 @@ public SlashCommandResponseBuilder WithContent(string content) /// /// The embed that will be added. /// - /// The updated . + /// The updated . /// /// Thrown when the max embed limit of 10 has been reached. - public SlashCommandResponseBuilder WithEmbed(IDiscordEmbed embed) + public InteractionResponseBuilder WithEmbed(IDiscordEmbed embed) { _embeds ??= new List(); @@ -104,9 +104,9 @@ public SlashCommandResponseBuilder WithEmbed(IDiscordEmbed embed) /// /// The allowed mentions. /// - /// The updated . + /// The updated . /// - public SlashCommandResponseBuilder WithAllowedMentions(IDiscordAllowedMentions allowedMentions) + public InteractionResponseBuilder WithAllowedMentions(IDiscordAllowedMentions allowedMentions) { _allowedMentions = allowedMentions; return this; @@ -117,10 +117,10 @@ public SlashCommandResponseBuilder WithAllowedMentions(IDiscordAllowedMentions a /// /// The new component. /// - /// The updated . + /// The updated . /// /// Thrown when the max component limit of 5 has been reached. - public SlashCommandResponseBuilder WithComponent(IDiscordComponent component) + public InteractionResponseBuilder WithComponent(IDiscordComponent component) { _components ??= new List(); @@ -129,26 +129,26 @@ public SlashCommandResponseBuilder WithComponent(IDiscordComponent component) _components.Add(component); return this; } - + /// - /// Sets the to an empty list of s. + /// Sets the to an empty list of s. /// /// - /// The updated . + /// The updated . /// - public SlashCommandResponseBuilder EmptyComponents() + public InteractionResponseBuilder EmptyComponents() { _components = new List(); return this; } - + /// - /// Sets the to an empty list of s. + /// Sets the to an empty list of s. /// /// - /// The updated . + /// The updated . /// - public SlashCommandResponseBuilder EmptyEmbeds() + public InteractionResponseBuilder EmptyEmbeds() { _embeds = new List(); return this; @@ -191,7 +191,7 @@ internal IDiscordInteractionResponse DefaultErrorMessage() .WithTimeStamp(); // Build the response with the embed. - var errorResponse = new SlashCommandResponseBuilder() + var errorResponse = new InteractionResponseBuilder() .WithEmbed(errorEmbedBuilder.Build()) .MakePrivate() .Build(); diff --git a/src/Color-Chan.Discord.Commands/Models/Contexts/IInteractionContext.cs b/src/Color-Chan.Discord.Commands/Models/Contexts/IInteractionContext.cs index 763c7efc..580b897c 100644 --- a/src/Color-Chan.Discord.Commands/Models/Contexts/IInteractionContext.cs +++ b/src/Color-Chan.Discord.Commands/Models/Contexts/IInteractionContext.cs @@ -64,7 +64,7 @@ public interface IInteractionContext /// The interaction id. /// ulong InteractionId { get; init; } - + /// /// The method name of the method that will handle the interaction request. /// @@ -72,7 +72,7 @@ public interface IInteractionContext /// Used to create a unique string for rate limiting. /// string? MethodName { get; set; } - + /// /// The guild the interaction was used in. /// diff --git a/src/Color-Chan.Discord.Commands/Models/Contexts/InteractionContext.cs b/src/Color-Chan.Discord.Commands/Models/Contexts/InteractionContext.cs index e07dc31c..9d12ae72 100644 --- a/src/Color-Chan.Discord.Commands/Models/Contexts/InteractionContext.cs +++ b/src/Color-Chan.Discord.Commands/Models/Contexts/InteractionContext.cs @@ -37,7 +37,7 @@ public class InteractionContext : IInteractionContext /// public string? MethodName { get; set; } - + /// public IDiscordGuild? Guild { get; init; } diff --git a/src/Color-Chan.Discord.Commands/Models/Info/ComponentInfo.cs b/src/Color-Chan.Discord.Commands/Models/Info/ComponentInfo.cs index 7c752f60..09bb11a0 100644 --- a/src/Color-Chan.Discord.Commands/Models/Info/ComponentInfo.cs +++ b/src/Color-Chan.Discord.Commands/Models/Info/ComponentInfo.cs @@ -19,7 +19,10 @@ public class ComponentInfo : IComponentInfo /// Whether or not the component interaction should be automatically acknowledge to prevent the token /// from turning inactive after 3 seconds. /// - /// Whether or not the original message of the component should be edited with the returned response. + /// + /// Whether or not the original message of the component should be edited with the + /// returned response. + /// public ComponentInfo(string customId, DiscordComponentType type, MethodInfo componentMethod, TypeInfo parentModule, bool acknowledge, bool editOriginalMessage) { CustomId = customId; @@ -41,13 +44,13 @@ public ComponentInfo(string customId, DiscordComponentType type, MethodInfo comp /// public TypeInfo ParentModule { get; set; } - + /// public IEnumerable? Requirements { get; set; } - + /// public bool Acknowledge { get; } - + /// public bool EditOriginalMessage { get; } } diff --git a/src/Color-Chan.Discord.Commands/Models/Info/IComponentInfo.cs b/src/Color-Chan.Discord.Commands/Models/Info/IComponentInfo.cs index 24fee866..9eb4d0cc 100644 --- a/src/Color-Chan.Discord.Commands/Models/Info/IComponentInfo.cs +++ b/src/Color-Chan.Discord.Commands/Models/Info/IComponentInfo.cs @@ -29,19 +29,19 @@ public interface IComponentInfo /// The component module containing the . /// public TypeInfo ParentModule { get; set; } - + /// /// A of s containing all the requirements /// to execute the component. /// public IEnumerable? Requirements { get; set; } - + /// /// Whether or not the component interaction should be automatically acknowledge to prevent the token /// from turning inactive after 3 seconds. /// public bool Acknowledge { get; } - + /// /// Whether or not the original message of the component should be edited with the returned response. /// diff --git a/src/Color-Chan.Discord.Commands/Models/Info/ISlashCommandInfo.cs b/src/Color-Chan.Discord.Commands/Models/Info/ISlashCommandInfo.cs index ad0ee993..ac96b8ff 100644 --- a/src/Color-Chan.Discord.Commands/Models/Info/ISlashCommandInfo.cs +++ b/src/Color-Chan.Discord.Commands/Models/Info/ISlashCommandInfo.cs @@ -42,7 +42,7 @@ public interface ISlashCommandInfo /// from turning inactive after 3 seconds. /// public bool Acknowledge { get; } - + /// /// A of containing the IDs of the guilds that /// will get access to this slash command. diff --git a/src/Color-Chan.Discord.Commands/Models/Info/ISlashCommandOptionInfo.cs b/src/Color-Chan.Discord.Commands/Models/Info/ISlashCommandOptionInfo.cs index 2ab21605..33a7d90c 100644 --- a/src/Color-Chan.Discord.Commands/Models/Info/ISlashCommandOptionInfo.cs +++ b/src/Color-Chan.Discord.Commands/Models/Info/ISlashCommandOptionInfo.cs @@ -57,7 +57,7 @@ public interface ISlashCommandOptionInfo /// from turning inactive after 3 seconds. /// public bool Acknowledge { get; } - + /// /// A of containing the IDs of the guilds that /// will get access to this slash command. diff --git a/src/Color-Chan.Discord.Commands/Models/Info/SlashCommandOptionInfo.cs b/src/Color-Chan.Discord.Commands/Models/Info/SlashCommandOptionInfo.cs index c3c83c92..23176440 100644 --- a/src/Color-Chan.Discord.Commands/Models/Info/SlashCommandOptionInfo.cs +++ b/src/Color-Chan.Discord.Commands/Models/Info/SlashCommandOptionInfo.cs @@ -129,7 +129,7 @@ public SlashCommandOptionInfo(string name, string description, bool acknowledge, /// public bool Acknowledge { get; } - + /// public IEnumerable? Guilds { get; set; } diff --git a/src/Color-Chan.Discord.Commands/Models/Results/BaseRateLimitErrorResult.cs b/src/Color-Chan.Discord.Commands/Models/Results/BaseRateLimitErrorResult.cs index 0fe99071..30565d7c 100644 --- a/src/Color-Chan.Discord.Commands/Models/Results/BaseRateLimitErrorResult.cs +++ b/src/Color-Chan.Discord.Commands/Models/Results/BaseRateLimitErrorResult.cs @@ -5,7 +5,7 @@ namespace Color_Chan.Discord.Commands.Models.Results /// /// An error result describing a slash command rate limit. /// - public record BaseRateLimitErrorResult : SlashCommandRequirementErrorResult + public record BaseRateLimitErrorResult : InteractionRequirementErrorResult { /// /// Initializes a new instance of . diff --git a/src/Color-Chan.Discord.Commands/Models/Results/SlashCommandRequirementErrorResult.cs b/src/Color-Chan.Discord.Commands/Models/Results/InteractionRequirementErrorResult.cs similarity index 63% rename from src/Color-Chan.Discord.Commands/Models/Results/SlashCommandRequirementErrorResult.cs rename to src/Color-Chan.Discord.Commands/Models/Results/InteractionRequirementErrorResult.cs index d5d4697b..b7c17458 100644 --- a/src/Color-Chan.Discord.Commands/Models/Results/SlashCommandRequirementErrorResult.cs +++ b/src/Color-Chan.Discord.Commands/Models/Results/InteractionRequirementErrorResult.cs @@ -6,13 +6,13 @@ namespace Color_Chan.Discord.Commands.Models.Results /// /// An error result describing an error thrown by a . /// - public record SlashCommandRequirementErrorResult : ErrorResult + public record InteractionRequirementErrorResult : ErrorResult { /// - /// Initializes a new instance of . + /// Initializes a new instance of . /// /// The message of the error. - public SlashCommandRequirementErrorResult(string errorMessage) : base(errorMessage) + public InteractionRequirementErrorResult(string errorMessage) : base(errorMessage) { } } diff --git a/src/Color-Chan.Discord.Commands/Models/Results/RequireBotPermissionErrorResult.cs b/src/Color-Chan.Discord.Commands/Models/Results/RequireBotPermissionErrorResult.cs index 4bfa2f35..12b6d6e6 100644 --- a/src/Color-Chan.Discord.Commands/Models/Results/RequireBotPermissionErrorResult.cs +++ b/src/Color-Chan.Discord.Commands/Models/Results/RequireBotPermissionErrorResult.cs @@ -8,7 +8,7 @@ namespace Color_Chan.Discord.Commands.Models.Results /// An error result describing an error for when the bot did /// not meet the permission requirements. /// - public record RequireBotPermissionErrorResult : SlashCommandRequirementErrorResult + public record RequireBotPermissionErrorResult : InteractionRequirementErrorResult { /// /// Initializes a new instance of . diff --git a/src/Color-Chan.Discord.Commands/Models/Results/RequireChannelErrorResult.cs b/src/Color-Chan.Discord.Commands/Models/Results/RequireChannelErrorResult.cs index 856462b6..34cd76b7 100644 --- a/src/Color-Chan.Discord.Commands/Models/Results/RequireChannelErrorResult.cs +++ b/src/Color-Chan.Discord.Commands/Models/Results/RequireChannelErrorResult.cs @@ -5,7 +5,7 @@ namespace Color_Chan.Discord.Commands.Models.Results /// /// An error describing when a requirement failed for the . /// - public record RequireChannelErrorResult : SlashCommandRequirementErrorResult + public record RequireChannelErrorResult : InteractionRequirementErrorResult { /// /// Initializes a new instance of . diff --git a/src/Color-Chan.Discord.Commands/Models/Results/SlashCommandRequireDmErrorResult.cs b/src/Color-Chan.Discord.Commands/Models/Results/RequireDmErrorResult.cs similarity index 60% rename from src/Color-Chan.Discord.Commands/Models/Results/SlashCommandRequireDmErrorResult.cs rename to src/Color-Chan.Discord.Commands/Models/Results/RequireDmErrorResult.cs index 2dca75a2..8309852a 100644 --- a/src/Color-Chan.Discord.Commands/Models/Results/SlashCommandRequireDmErrorResult.cs +++ b/src/Color-Chan.Discord.Commands/Models/Results/RequireDmErrorResult.cs @@ -5,13 +5,13 @@ namespace Color_Chan.Discord.Commands.Models.Results /// /// An error describing when a requirement failed for the . /// - public record SlashCommandRequireDmErrorResult : SlashCommandRequirementErrorResult + public record RequireDmErrorResult : InteractionRequirementErrorResult { /// - /// Initializes a new instance of . + /// Initializes a new instance of . /// /// The message of the error. - public SlashCommandRequireDmErrorResult(string errorMessage) : base(errorMessage) + public RequireDmErrorResult(string errorMessage) : base(errorMessage) { } } diff --git a/src/Color-Chan.Discord.Commands/Models/Results/RequireGuildErrorResult.cs b/src/Color-Chan.Discord.Commands/Models/Results/RequireGuildErrorResult.cs index 8420d0f6..aee1c383 100644 --- a/src/Color-Chan.Discord.Commands/Models/Results/RequireGuildErrorResult.cs +++ b/src/Color-Chan.Discord.Commands/Models/Results/RequireGuildErrorResult.cs @@ -5,7 +5,7 @@ namespace Color_Chan.Discord.Commands.Models.Results /// /// An error describing when a requirement failed for the . /// - public record RequireGuildErrorResult : SlashCommandRequirementErrorResult + public record RequireGuildErrorResult : InteractionRequirementErrorResult { /// /// Initializes a new instance of . diff --git a/src/Color-Chan.Discord.Commands/Models/Results/RequireGuildOwnerErrorResult.cs b/src/Color-Chan.Discord.Commands/Models/Results/RequireGuildOwnerErrorResult.cs index 65892a86..1558ae76 100644 --- a/src/Color-Chan.Discord.Commands/Models/Results/RequireGuildOwnerErrorResult.cs +++ b/src/Color-Chan.Discord.Commands/Models/Results/RequireGuildOwnerErrorResult.cs @@ -5,7 +5,7 @@ namespace Color_Chan.Discord.Commands.Models.Results /// /// An error describing when a requirement failed for the . /// - public record RequireGuildOwnerErrorResult : SlashCommandRequirementErrorResult + public record RequireGuildOwnerErrorResult : InteractionRequirementErrorResult { /// /// Initializes a new instance of . diff --git a/src/Color-Chan.Discord.Commands/Models/Results/RequireUserPermissionErrorResult.cs b/src/Color-Chan.Discord.Commands/Models/Results/RequireUserPermissionErrorResult.cs index 83b482ac..6643d851 100644 --- a/src/Color-Chan.Discord.Commands/Models/Results/RequireUserPermissionErrorResult.cs +++ b/src/Color-Chan.Discord.Commands/Models/Results/RequireUserPermissionErrorResult.cs @@ -8,7 +8,7 @@ namespace Color_Chan.Discord.Commands.Models.Results /// An error result describing an error for when the user did /// not meet the permission requirements. /// - public record RequireUserPermissionErrorResult : SlashCommandRequirementErrorResult + public record RequireUserPermissionErrorResult : InteractionRequirementErrorResult { /// /// Initializes a new instance of . diff --git a/src/Color-Chan.Discord.Commands/Modules/ComponentInteractionModule.cs b/src/Color-Chan.Discord.Commands/Modules/ComponentInteractionModule.cs index 2a6c5422..9397e374 100644 --- a/src/Color-Chan.Discord.Commands/Modules/ComponentInteractionModule.cs +++ b/src/Color-Chan.Discord.Commands/Modules/ComponentInteractionModule.cs @@ -3,7 +3,7 @@ namespace Color_Chan.Discord.Commands.Modules { - /// + /// public class ComponentInteractionModule : InteractionModuleBase, IComponentInteractionModule { /// diff --git a/src/Color-Chan.Discord.Commands/Modules/InteractionModuleBase.cs b/src/Color-Chan.Discord.Commands/Modules/InteractionModuleBase.cs index 18b0bcb0..91f0fa76 100644 --- a/src/Color-Chan.Discord.Commands/Modules/InteractionModuleBase.cs +++ b/src/Color-Chan.Discord.Commands/Modules/InteractionModuleBase.cs @@ -33,7 +33,7 @@ protected static Result FromSuccess(IDiscordInterac protected static Result FromSuccess(string content, bool isPrivate = false) { // Build the response with the content. - var responseBuilder = new SlashCommandResponseBuilder().WithContent(content); + var responseBuilder = new InteractionResponseBuilder().WithContent(content); if (isPrivate) responseBuilder.MakePrivate(); @@ -52,7 +52,7 @@ protected static Result FromSuccess(string content, protected static Result FromSuccess(IDiscordEmbed embed, bool isPrivate = false) { // Build the response with the embed. - var responseBuilder = new SlashCommandResponseBuilder().WithEmbed(embed); + var responseBuilder = new InteractionResponseBuilder().WithEmbed(embed); if (isPrivate) responseBuilder.MakePrivate(); diff --git a/src/Color-Chan.Discord.Commands/Modules/SlashCommandModule.cs b/src/Color-Chan.Discord.Commands/Modules/SlashCommandModule.cs index e5ea7132..4daede6c 100644 --- a/src/Color-Chan.Discord.Commands/Modules/SlashCommandModule.cs +++ b/src/Color-Chan.Discord.Commands/Modules/SlashCommandModule.cs @@ -3,7 +3,7 @@ namespace Color_Chan.Discord.Commands.Modules { - /// + /// public class SlashCommandModule : InteractionModuleBase, ISlashCommandModule { /// diff --git a/src/Color-Chan.Discord.Commands/Services/IComponentInteractionHandler.cs b/src/Color-Chan.Discord.Commands/Services/IComponentInteractionHandler.cs index e0350573..88cc6fc4 100644 --- a/src/Color-Chan.Discord.Commands/Services/IComponentInteractionHandler.cs +++ b/src/Color-Chan.Discord.Commands/Services/IComponentInteractionHandler.cs @@ -14,11 +14,11 @@ public interface IComponentInteractionHandler /// /// Handles a component interaction request. /// - /// The that was requested. + /// The that was requested. /// /// A containing the result of the component interaction. /// - /// Thrown when the is null. + /// Thrown when the is null. /// Thrown when no user or member was found. /// Thrown when no channel id was found. Task HandleComponentInteractionAsync(IDiscordInteraction interaction); diff --git a/src/Color-Chan.Discord.Commands/Services/IComponentService.cs b/src/Color-Chan.Discord.Commands/Services/IComponentService.cs index 074fcb43..7a05793d 100644 --- a/src/Color-Chan.Discord.Commands/Services/IComponentService.cs +++ b/src/Color-Chan.Discord.Commands/Services/IComponentService.cs @@ -34,21 +34,21 @@ public interface IComponentService /// /// Executes a component interaction. /// - /// The that will be executed. + /// The that will be executed. /// The context of the interaction. /// The services needed for the interaction. /// /// The containing the result of the component interaction execution. /// Task> ExecuteComponentInteractionAsync(IComponentInfo componentInfo, InteractionContext context, IServiceProvider serviceProvider); - + /// /// Search for a registered component. /// - /// The of the component. + /// The of the component. /// - /// A if one was found. - /// Null if no was found. + /// A if one was found. + /// Null if no was found. /// IComponentInfo? SearchComponent(string customId); } diff --git a/src/Color-Chan.Discord.Commands/Services/Implementations/Builders/ComponentBuildService.cs b/src/Color-Chan.Discord.Commands/Services/Implementations/Builders/ComponentBuildService.cs index d34d24e5..f059b6a0 100644 --- a/src/Color-Chan.Discord.Commands/Services/Implementations/Builders/ComponentBuildService.cs +++ b/src/Color-Chan.Discord.Commands/Services/Implementations/Builders/ComponentBuildService.cs @@ -46,7 +46,8 @@ public IEnumerable BuildComponentInfos(Assembly assembly) var componentAttribute = validMethod.GetCustomAttribute(); if (componentAttribute is null) throw new NullReferenceException(nameof(componentAttribute)); - var componentInfo = new ComponentInfo(componentAttribute.CustomId, componentAttribute.Type, validMethod, parentModule, componentAttribute.Acknowledge, componentAttribute.EditOriginalMessage) + var componentInfo = new ComponentInfo(componentAttribute.CustomId, componentAttribute.Type, validMethod, parentModule, componentAttribute.Acknowledge, + componentAttribute.EditOriginalMessage) { Requirements = _requirementBuildService.GetCommandRequirements(validMethod) }; diff --git a/src/Color-Chan.Discord.Commands/Services/Implementations/ComponentInteractionHandler.cs b/src/Color-Chan.Discord.Commands/Services/Implementations/ComponentInteractionHandler.cs index f83d78ea..d57e40d2 100644 --- a/src/Color-Chan.Discord.Commands/Services/Implementations/ComponentInteractionHandler.cs +++ b/src/Color-Chan.Discord.Commands/Services/Implementations/ComponentInteractionHandler.cs @@ -21,25 +21,28 @@ namespace Color_Chan.Discord.Commands.Services.Implementations /// public class ComponentInteractionHandler : IComponentInteractionHandler { - private readonly ILogger _logger; - private readonly IServiceProvider _serviceProvider; private readonly IComponentService _componentService; - private readonly IDiscordRestGuild _restGuild; - private readonly IDiscordRestChannel _restChannel; - private readonly IDiscordRestApplication _restApplication; + private readonly ILogger _logger; private readonly ComponentInteractionConfiguration _options; + private readonly IDiscordRestApplication _restApplication; + private readonly IDiscordRestChannel _restChannel; + private readonly IDiscordRestGuild _restGuild; + private readonly IServiceProvider _serviceProvider; /// /// Initializes a new instance of . /// /// The for . /// The services needed to execute the component interactions. - /// The used to search and execute the correct components. - /// The containing the configuration data for component interactions. + /// The used to search and execute the correct components. + /// + /// The containing the configuration data for + /// component interactions. + /// /// The rest class for Guilds. /// The rest class for Channels. /// The rest class the Application calls. - public ComponentInteractionHandler(ILogger logger, IServiceProvider serviceProvider, IComponentService componentService, + public ComponentInteractionHandler(ILogger logger, IServiceProvider serviceProvider, IComponentService componentService, IOptions options, IDiscordRestGuild restGuild, IDiscordRestChannel restChannel, IDiscordRestApplication application) { _logger = logger; @@ -58,12 +61,12 @@ public async Task HandleComponentInteractionAsync(I { throw new ArgumentNullException(nameof(interaction.Data), $"{nameof(interaction.Data)} can not be null for a component interaction!"); } - + if (interaction.Data.CustomId is null) { throw new ArgumentNullException(nameof(interaction.Data), $"{nameof(interaction.Data.CustomId)} can not be null for a component interaction!"); } - + IDiscordGuild? guild = null; if (_options.EnableAutoGetGuild && interaction.GuildId is not null) { @@ -77,8 +80,8 @@ public async Task HandleComponentInteractionAsync(I var channelResult = await _restChannel.GetChannelAsync(interaction.ChannelId.Value).ConfigureAwait(false); channel = channelResult.Entity; } - - InteractionContext context = new () + + InteractionContext context = new() { User = interaction.User ?? interaction.GuildMember?.User ?? throw new NullReferenceException(nameof(context.User)), Message = interaction.Message, @@ -98,7 +101,7 @@ public async Task HandleComponentInteractionAsync(I { throw new NullReferenceException($"Failed to find the requested interaction component {interaction.Data.CustomId}"); } - + // Acknowledge the component interaction request if needed. var acknowledged = false; if (componentInfo.Acknowledge) @@ -119,7 +122,7 @@ public async Task HandleComponentInteractionAsync(I acknowledged = true; } } - + // Local method to execute the command. async Task> Handler() { @@ -136,7 +139,7 @@ async Task> Handler() if (_options.SendDefaultErrorMessage) { _logger.LogWarning("Sending default error message"); - return new InternalInteractionResponse(acknowledged, new SlashCommandResponseBuilder().DefaultErrorMessage()); + return new InternalInteractionResponse(acknowledged, new InteractionResponseBuilder().DefaultErrorMessage()); } throw new ComponentInteractionResultException($"Component interaction request {interaction.Id} returned unsuccessfully, {result.ErrorResult?.ErrorMessage}"); diff --git a/src/Color-Chan.Discord.Commands/Services/Implementations/ComponentService.cs b/src/Color-Chan.Discord.Commands/Services/Implementations/ComponentService.cs index 10a1c544..47a36f55 100644 --- a/src/Color-Chan.Discord.Commands/Services/Implementations/ComponentService.cs +++ b/src/Color-Chan.Discord.Commands/Services/Implementations/ComponentService.cs @@ -18,9 +18,9 @@ namespace Color_Chan.Discord.Commands.Services.Implementations public class ComponentService : IComponentService { private readonly IComponentBuildService _componentBuildService; - private readonly ISlashCommandRequirementService _requirementService; private readonly ConcurrentDictionary _components = new(); private readonly ILogger _logger; + private readonly ISlashCommandRequirementService _requirementService; /// /// Initializes a new instance of . @@ -63,10 +63,10 @@ public Task AddComponentsAsync(Assembly assembly) public async Task> ExecuteComponentInteractionAsync(InteractionContext context, IServiceProvider serviceProvider) { if (context.Data.CustomId is null) throw new NullReferenceException(nameof(context.Data.CustomId)); - + // Get the component. var searchResult = SearchComponent(context.Data.CustomId); - if (searchResult is null) + if (searchResult is null) return Result.FromError(default, new ErrorResult($"Failed to find component with id {context.Data.CustomId}")); return await ExecuteComponentInteractionAsync(searchResult, context, serviceProvider).ConfigureAwait(false); @@ -87,7 +87,7 @@ public async Task> ExecuteComponentInteracti var instance = GetComponentInteractionModuleInstance(serviceProvider, componentInfo.ComponentMethod); context.MethodName = componentInfo.ComponentMethod.Name; instance.SetContext(context); - + // Try to run the requirements for the slash command. try { @@ -102,7 +102,7 @@ public async Task> ExecuteComponentInteracti _logger.LogError(e, "Exception thrown while running component interaction `{Name}` requirements", componentInfo.CustomId); return Result.FromError(default, new ExceptionResult(e.InnerException!)); } - + // Try to execute the component interaction. try { @@ -121,13 +121,13 @@ public async Task> ExecuteComponentInteracti return Result.FromError(default, new ExceptionResult(e.InnerException ?? e)); } } - + /// public IComponentInfo? SearchComponent(string customId) { return _components.TryGetValue(customId, out var componentInfo) ? componentInfo : null; } - + /// /// Get a new instance of a with its required dependencies. /// diff --git a/src/Color-Chan.Discord.Commands/Services/Implementations/DiscordSlashCommandHandler.cs b/src/Color-Chan.Discord.Commands/Services/Implementations/DiscordSlashCommandHandler.cs index 91763d0f..cae76a89 100644 --- a/src/Color-Chan.Discord.Commands/Services/Implementations/DiscordSlashCommandHandler.cs +++ b/src/Color-Chan.Discord.Commands/Services/Implementations/DiscordSlashCommandHandler.cs @@ -42,8 +42,8 @@ public class DiscordSlashCommandHandler : IDiscordSlashCommandHandler /// The rest class for Channels. /// The configuration class for slash commands. /// The rest class for application calls. - public DiscordSlashCommandHandler(ISlashCommandService slashCommandService, IServiceProvider serviceProvider, ILogger logger, - IDiscordRestApplication restApplication, IDiscordRestGuild restGuild, IDiscordRestChannel restChannel, + public DiscordSlashCommandHandler(ISlashCommandService slashCommandService, IServiceProvider serviceProvider, ILogger logger, + IDiscordRestApplication restApplication, IDiscordRestGuild restGuild, IDiscordRestChannel restChannel, IOptions slashCommandConfiguration) { _slashCommandService = slashCommandService; @@ -60,7 +60,7 @@ public async Task HandleSlashCommandAsync(IDiscordI { if (interaction.Data is null) { - throw new ArgumentNullException(nameof(interaction.Data), $"{nameof(interaction.Data)} can not be null for a slash command!"); + throw new ArgumentNullException(nameof(interaction.Data), $"{nameof(interaction.Data)} can not be null for a slash command!"); } IDiscordGuild? guild = null; @@ -156,7 +156,7 @@ public async Task HandleSlashCommandAsync(IDiscordI { throw new NullReferenceException($"Failed to find the requested interaction command {interaction.Data.Name}"); } - + // Acknowledge the slash command request if needed. var acknowledged = false; if (commandInfo is not null && commandInfo.Acknowledge || optionInfo is not null && optionInfo.Acknowledge) @@ -177,7 +177,7 @@ public async Task HandleSlashCommandAsync(IDiscordI acknowledged = true; } } - + // Local method to execute the command. async Task> Handler() { @@ -185,7 +185,7 @@ async Task> Handler() { return await _slashCommandService.ExecuteSlashCommandAsync(commandInfo, context, options?.ToList(), _serviceProvider).ConfigureAwait(false); } - + return await _slashCommandService.ExecuteSlashCommandAsync(optionInfo!, context, options?.ToList(), _serviceProvider).ConfigureAwait(false); } @@ -199,7 +199,7 @@ async Task> Handler() if (_slashCommandConfiguration.SendDefaultErrorMessage) { _logger.LogWarning("Sending default error message"); - return new InternalInteractionResponse(acknowledged, new SlashCommandResponseBuilder().DefaultErrorMessage()); + return new InternalInteractionResponse(acknowledged, new InteractionResponseBuilder().DefaultErrorMessage()); } throw new SlashCommandResultException($"Command request {interaction.Id} returned unsuccessfully, {result.ErrorResult?.ErrorMessage}"); diff --git a/src/Color-Chan.Discord.Core/Color-Chan.Discord.Core.csproj b/src/Color-Chan.Discord.Core/Color-Chan.Discord.Core.csproj index 70537e35..8783bbbd 100644 --- a/src/Color-Chan.Discord.Core/Color-Chan.Discord.Core.csproj +++ b/src/Color-Chan.Discord.Core/Color-Chan.Discord.Core.csproj @@ -7,15 +7,15 @@ - + - + - + @@ -54,7 +54,7 @@ - + diff --git a/src/Color-Chan.Discord.Core/Common/API/DataModels/DiscordComponentData.cs b/src/Color-Chan.Discord.Core/Common/API/DataModels/DiscordComponentData.cs index 792bc04c..e8293209 100644 --- a/src/Color-Chan.Discord.Core/Common/API/DataModels/DiscordComponentData.cs +++ b/src/Color-Chan.Discord.Core/Common/API/DataModels/DiscordComponentData.cs @@ -17,13 +17,13 @@ public record DiscordComponentData /// [JsonPropertyName("custom_id")] public string? CustomId { get; init; } - + /// /// Whether the button is disabled, default false /// [JsonPropertyName("disabled")] public bool? Disabled { get; init; } - + /// /// The style the button. /// @@ -53,25 +53,25 @@ public record DiscordComponentData /// [JsonPropertyName("options")] public IEnumerable? SelectOptions { get; init; } - + /// /// Custom placeholder text if nothing is selected, max 100 characters. /// [JsonPropertyName("placeholder")] public string? Placeholder { get; init; } - + /// /// The minimum number of items that must be chosen; default 1, min 0, max 25. /// [JsonPropertyName("min_values")] public int? MinValues { get; init; } - + /// /// The maximum number of items that can be chosen; default 1, max 25. /// [JsonPropertyName("max_values")] public int? MaxValues { get; init; } - + /// /// A list of child components. /// diff --git a/src/Color-Chan.Discord.Core/Common/API/Params/Webhook/DiscordExecuteWebhook.cs b/src/Color-Chan.Discord.Core/Common/API/Params/Webhook/DiscordExecuteWebhook.cs index 0e29f54c..840bda31 100644 --- a/src/Color-Chan.Discord.Core/Common/API/Params/Webhook/DiscordExecuteWebhook.cs +++ b/src/Color-Chan.Discord.Core/Common/API/Params/Webhook/DiscordExecuteWebhook.cs @@ -11,7 +11,7 @@ public record DiscordExecuteWebhook /// The message contents (up to 2000 characters). /// /// - /// Required when is not provided. + /// Required when is not provided. /// [JsonPropertyName("content")] public string? Content { get; set; } @@ -21,24 +21,24 @@ public record DiscordExecuteWebhook /// [JsonPropertyName("username")] public string? Username { get; set; } - + /// /// Override the default avatar of the webhook. /// [JsonPropertyName("avatar_url")] public string? AvatarUrl { get; set; } - + /// /// True if this is a TTS message. /// [JsonPropertyName("tts")] public bool? UseTts { get; set; } - + /// /// Embedded rich content. /// /// - /// Required when is not provided. + /// Required when is not provided. /// [JsonPropertyName("embeds")] public IEnumerable? Embeds { get; set; } diff --git a/src/Color-Chan.Discord.Core/Common/Models/IDiscordComponent.cs b/src/Color-Chan.Discord.Core/Common/Models/IDiscordComponent.cs index 9e418000..add82bcd 100644 --- a/src/Color-Chan.Discord.Core/Common/Models/IDiscordComponent.cs +++ b/src/Color-Chan.Discord.Core/Common/Models/IDiscordComponent.cs @@ -45,22 +45,22 @@ public interface IDiscordComponent /// The choices in the select, max 25. /// public List? SelectOptions { get; init; } - + /// /// Custom placeholder text if nothing is selected, max 100 characters. /// public string? Placeholder { get; init; } - + /// /// The minimum number of items that must be chosen; default 1, min 0, max 25. /// public int? MinValues { get; init; } - + /// /// The maximum number of items that can be chosen; default 1, max 25. /// public int? MaxValues { get; init; } - + /// /// A list of child components. /// diff --git a/src/Color-Chan.Discord.Rest/API/Rest/DiscordRestApplication.cs b/src/Color-Chan.Discord.Rest/API/Rest/DiscordRestApplication.cs index d54467f9..c68dd3dd 100644 --- a/src/Color-Chan.Discord.Rest/API/Rest/DiscordRestApplication.cs +++ b/src/Color-Chan.Discord.Rest/API/Rest/DiscordRestApplication.cs @@ -217,9 +217,9 @@ public virtual async Task> GetFollowupMessageAsync(ulong var result = await HttpClient.GetAsync(endpoint, ct: ct).ConfigureAwait(false); return ApiResultConverters.ConvertResult(result); } - + /// - public virtual async Task> EditFollowupMessageAsync(ulong applicationId, string token, ulong messageId, DiscordEditWebhookMessage webhookMessage, + public virtual async Task> EditFollowupMessageAsync(ulong applicationId, string token, ulong messageId, DiscordEditWebhookMessage webhookMessage, CancellationToken ct = default) { string endpoint = $"webhooks/{applicationId.ToString()}/{token}/messages/{messageId.ToString()}"; @@ -233,7 +233,7 @@ public virtual async Task DeleteFollowupMessageAsync(ulong applicationId string endpoint = $"webhooks/{applicationId.ToString()}/{token}/messages/{messageId.ToString()}"; return await HttpClient.DeleteAsync(endpoint, ct: ct).ConfigureAwait(false); } - + #endregion } } \ No newline at end of file diff --git a/src/Color-Chan.Discord.Rest/Color-Chan.Discord.Rest.csproj b/src/Color-Chan.Discord.Rest/Color-Chan.Discord.Rest.csproj index b1906d2f..9fb3325c 100644 --- a/src/Color-Chan.Discord.Rest/Color-Chan.Discord.Rest.csproj +++ b/src/Color-Chan.Discord.Rest/Color-Chan.Discord.Rest.csproj @@ -7,16 +7,16 @@ - + - - + + - + @@ -46,7 +46,7 @@ - + diff --git a/src/Color-Chan.Discord.Rest/Extensions/ServiceCollectionExtensions.cs b/src/Color-Chan.Discord.Rest/Extensions/ServiceCollectionExtensions.cs index 51611baf..cb16a8db 100644 --- a/src/Color-Chan.Discord.Rest/Extensions/ServiceCollectionExtensions.cs +++ b/src/Color-Chan.Discord.Rest/Extensions/ServiceCollectionExtensions.cs @@ -46,7 +46,7 @@ public static IServiceCollection AddColorChanDiscordRest(this IServiceCollection .WaitAndRetryAsync(retryDelay) .WrapAsync(customPolicy) ).AddPolicyHandler(Policy.HandleResult(response => response.StatusCode == HttpStatusCode.TooManyRequests) - .WaitAndRetryAsync(1, (_, response, _) => response.Result?.Headers.RetryAfter?.Delta ?? TimeSpan.FromMilliseconds(2500), + .WaitAndRetryAsync(1, (_, response, _) => response.Result?.Headers.RetryAfter?.Delta ?? TimeSpan.FromMilliseconds(2500), (_, _, _, _) => Task.CompletedTask)); // Add all rest classes with Transient live cycle that inherit DiscordRestBase. diff --git a/src/Color-Chan.Discord.Rest/Models/DiscordComponent.cs b/src/Color-Chan.Discord.Rest/Models/DiscordComponent.cs index 52c886af..86df4156 100644 --- a/src/Color-Chan.Discord.Rest/Models/DiscordComponent.cs +++ b/src/Color-Chan.Discord.Rest/Models/DiscordComponent.cs @@ -12,7 +12,7 @@ public record DiscordComponent : IDiscordComponent public DiscordComponent() { } - + public DiscordComponent(DiscordComponentData data) { Type = data.Type; @@ -28,40 +28,40 @@ public DiscordComponent(DiscordComponentData data) Placeholder = data.Placeholder; SelectOptions = data.SelectOptions?.Select(selectData => new DiscordSelectOption(selectData)).Cast().ToList(); } - + /// public DiscordComponentType Type { get; init; } - + /// public string? CustomId { get; init; } - + /// public bool? Disabled { get; init; } - + /// public DiscordButtonStyle? ButtonStyle { get; init; } - + /// public string? Label { get; init; } /// public IDiscordEmoji? Emoji { get; init; } - + /// public string? Url { get; init; } /// public List? SelectOptions { get; init; } - + /// public string? Placeholder { get; init; } - + /// public int? MinValues { get; init; } - + /// public int? MaxValues { get; init; } - + /// public IEnumerable? ChildComponents { get; init; } diff --git a/src/Color-Chan.Discord.Rest/Results/DiscordHttpErrorResult.cs b/src/Color-Chan.Discord.Rest/Results/DiscordHttpErrorResult.cs index 4bbf63c2..84cf8932 100644 --- a/src/Color-Chan.Discord.Rest/Results/DiscordHttpErrorResult.cs +++ b/src/Color-Chan.Discord.Rest/Results/DiscordHttpErrorResult.cs @@ -8,11 +8,6 @@ namespace Color_Chan.Discord.Rest.Results /// public record DiscordHttpErrorResult : HttpErrorResult { - /// - /// The error data of the HTTP request. - /// - public DiscordJsonErrorData ErrorData { get; } - /// /// Initializes a new instance of . /// @@ -22,5 +17,10 @@ public DiscordHttpErrorResult(DiscordJsonErrorData errorData, HttpStatusCode sta { ErrorData = errorData; } + + /// + /// The error data of the HTTP request. + /// + public DiscordJsonErrorData ErrorData { get; } } } \ No newline at end of file diff --git a/src/Color-Chan.Discord/Controllers/DiscordInteractionController.cs b/src/Color-Chan.Discord/Controllers/DiscordInteractionController.cs index 28633141..bbc476c7 100644 --- a/src/Color-Chan.Discord/Controllers/DiscordInteractionController.cs +++ b/src/Color-Chan.Discord/Controllers/DiscordInteractionController.cs @@ -33,9 +33,9 @@ public class DiscordInteractionController : ControllerBase private const string ReturnContentType = "application/json"; private readonly IDiscordInteractionAuthService _authService; private readonly IDiscordSlashCommandHandler _commandHandler; + private readonly IComponentInteractionHandler _componentInteractionHandler; private readonly InteractionsConfiguration _configuration; private readonly DiscordTokens _discordTokens; - private readonly IComponentInteractionHandler _componentInteractionHandler; private readonly ILogger _logger; private readonly IDiscordRestApplication _restApplication; private readonly JsonSerializerOptions _serializerOptions; @@ -97,7 +97,7 @@ public async Task HandleInteractionRequestAsync() if (interactionData is null) throw new JsonException("Failed to deserialize JSON body to DiscordInteractionData"); _logger.LogDebug("Verified Interaction {Id}", interactionData.Id.ToString()); - + // Execute the correct interaction type. var interactionResponse = interactionData.RequestType switch { @@ -113,7 +113,7 @@ public async Task HandleInteractionRequestAsync() _logger.LogDebug("Returning interaction response {Id} to discord", interactionData.Id.ToString()); return SerializeResult(interactionResponse.Response); } - + // Send an edit request. var responseData = interactionResponse.Response.Data?.ToDataModel(); var editResponse = new DiscordEditWebhookMessage @@ -123,21 +123,21 @@ public async Task HandleInteractionRequestAsync() Components = responseData?.Components, AllowedMentions = responseData?.AllowedMentions }; - + _logger.LogDebug("Editing original interaction response {Id}", interactionData.Id.ToString()); var responseResult = await _restApplication.EditOriginalInteractionResponseAsync(_discordTokens.ApplicationId, interactionData.Token, editResponse).ConfigureAwait(false); if (responseResult.IsSuccessful) return Ok(); - + if (responseResult.ErrorResult is DiscordHttpErrorResult httpErrorResult) { // Send an error response. - _logger.LogWarning("Failed to edit interaction response {Id}, reason: {Message}, details: {Details}", - interactionData.Id.ToString(), + _logger.LogWarning("Failed to edit interaction response {Id}, reason: {Message}, details: {Details}", + interactionData.Id.ToString(), responseResult.ErrorResult?.ErrorMessage, JsonSerializer.Serialize(httpErrorResult.ErrorData)); return StatusCode(StatusCodes.Status500InternalServerError, responseResult.ErrorResult); } - + // Send an error response. _logger.LogWarning("Failed to edit interaction response {Id}, reason: {Message}", interactionData.Id.ToString(), responseResult.ErrorResult?.ErrorMessage); return StatusCode(StatusCodes.Status500InternalServerError, responseResult.ErrorResult); diff --git a/src/Color-Chan.Discord/Extensions/HostExtensions.cs b/src/Color-Chan.Discord/Extensions/HostExtensions.cs index 9cf5528b..b945a978 100644 --- a/src/Color-Chan.Discord/Extensions/HostExtensions.cs +++ b/src/Color-Chan.Discord/Extensions/HostExtensions.cs @@ -35,10 +35,10 @@ public static async Task RegisterSlashCommandsAsync(this IHost host, Asse // Get the slash command service. var componentService = scope.ServiceProvider.GetRequiredService(); - + // Add all components in an assembly to the component service. await componentService.AddComponentsAsync(assembly).ConfigureAwait(false); - + return host; } } diff --git a/src/Color-Chan.Discord/Extensions/ServiceCollectionExtensions.cs b/src/Color-Chan.Discord/Extensions/ServiceCollectionExtensions.cs index 42e7c2a5..96b354c6 100644 --- a/src/Color-Chan.Discord/Extensions/ServiceCollectionExtensions.cs +++ b/src/Color-Chan.Discord/Extensions/ServiceCollectionExtensions.cs @@ -67,10 +67,7 @@ public static IServiceCollection AddColorChanDiscord(this IServiceCollection ser services.AddSingleton(); services.TryAddTransient(); - interactionConfigs ??= configuration => - { - configuration.VerifyInteractions = true; - }; + interactionConfigs ??= configuration => { configuration.VerifyInteractions = true; }; services.Configure(interactionConfigs); diff --git a/tests/Color-Chan.Discord.Commands.Tests/Attributes/RequireUserPermissionAttributeTests.cs b/tests/Color-Chan.Discord.Commands.Tests/Attributes/RequireUserPermissionAttributeTests.cs index 396058cf..074b3e15 100644 --- a/tests/Color-Chan.Discord.Commands.Tests/Attributes/RequireUserPermissionAttributeTests.cs +++ b/tests/Color-Chan.Discord.Commands.Tests/Attributes/RequireUserPermissionAttributeTests.cs @@ -63,8 +63,8 @@ public async Task Should_not_pass_user_permission_requirement() }) }; var attribute = new RequireUserPermissionAttribute(DiscordPermission.Administrator - | DiscordPermission.Speak - | DiscordPermission.AddReactions); + | DiscordPermission.Speak + | DiscordPermission.AddReactions); // Act var result = await attribute.CheckRequirementAsync(context, collectionProvider); diff --git a/tests/Color-Chan.Discord.Commands.Tests/Color-Chan.Discord.Commands.Tests.csproj b/tests/Color-Chan.Discord.Commands.Tests/Color-Chan.Discord.Commands.Tests.csproj index 8ef5b3af..063407cb 100644 --- a/tests/Color-Chan.Discord.Commands.Tests/Color-Chan.Discord.Commands.Tests.csproj +++ b/tests/Color-Chan.Discord.Commands.Tests/Color-Chan.Discord.Commands.Tests.csproj @@ -8,18 +8,18 @@ - - - - - - + + + + + + - - - + + + diff --git a/tests/Color-Chan.Discord.Commands.Tests/Services/Implementations/DiscordSlashCommandHandlerTests.cs b/tests/Color-Chan.Discord.Commands.Tests/Services/Implementations/DiscordSlashCommandHandlerTests.cs index 9e84a1bc..ba0305c3 100644 --- a/tests/Color-Chan.Discord.Commands.Tests/Services/Implementations/DiscordSlashCommandHandlerTests.cs +++ b/tests/Color-Chan.Discord.Commands.Tests/Services/Implementations/DiscordSlashCommandHandlerTests.cs @@ -48,8 +48,8 @@ public void SetUp() It.IsAny>(), It.IsAny())) .ReturnsAsync(Result.FromSuccess(new DiscordInteractionResponse())) .Callback(FakeSlashCommandCall); - - _commandServiceMock.Setup(x => x.ExecuteSlashCommandAsync(It.IsAny(), It.IsAny(), + + _commandServiceMock.Setup(x => x.ExecuteSlashCommandAsync(It.IsAny(), It.IsAny(), It.IsAny>(), It.IsAny())) .ReturnsAsync(Result.FromSuccess(new DiscordInteractionResponse())) .Callback(FakeSlashCommandCall); @@ -73,7 +73,8 @@ public void Should_throw_when_no_data() { // Arrange var serviceProviderMock = new Mock(); - var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProviderMock.Object, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, _restChannelMock.Object, _options); + var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProviderMock.Object, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, + _restChannelMock.Object, _options); var interaction = new DiscordInteraction(new DiscordInteractionData()); // Act & Assert @@ -86,7 +87,8 @@ public async Task Should_execute_top_level_command_with_no_pipelines() // Arrange var serviceProvider = new ServiceCollection() .BuildServiceProvider(); - var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProvider, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, _restChannelMock.Object, _options); + var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProvider, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, + _restChannelMock.Object, _options); var interaction = new DiscordInteraction(new DiscordInteractionData { Data = new DiscordInteractionRequestData @@ -118,7 +120,8 @@ public async Task Should_execute_top_level_command_with_resolved_and_pipelines() var serviceProvider = new ServiceCollection() .AddSlashCommandPipeline() .BuildServiceProvider(); - var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProvider, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, _restChannelMock.Object, _options); + var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProvider, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, + _restChannelMock.Object, _options); var interaction = new DiscordInteraction(new DiscordInteractionData { Data = new DiscordInteractionRequestData @@ -170,7 +173,8 @@ public async Task Should_execute_top_level_command_with_pipelines() .AddSlashCommandPipeline() .AddSlashCommandPipeline() .BuildServiceProvider(); - var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProvider, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, _restChannelMock.Object, _options); + var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProvider, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, + _restChannelMock.Object, _options); var interaction = new DiscordInteraction(new DiscordInteractionData { Data = new DiscordInteractionRequestData @@ -203,7 +207,8 @@ public async Task Should_execute_sub_command_with_pipelines() .AddSlashCommandPipeline() .AddSlashCommandPipeline() .BuildServiceProvider(); - var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProvider, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, _restChannelMock.Object, _options); + var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProvider, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, + _restChannelMock.Object, _options); var interaction = new DiscordInteraction(new DiscordInteractionData { Data = new DiscordInteractionRequestData @@ -244,7 +249,8 @@ public async Task Should_execute_sub_sub_command_with_pipelines() .AddSlashCommandPipeline() .AddSlashCommandPipeline() .BuildServiceProvider(); - var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProvider, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, _restChannelMock.Object, _options); + var handler = new DiscordSlashCommandHandler(_commandServiceMock.Object, serviceProvider, _handlerLoggerMock.Object, _restApplicationMock.Object, _restGuildMock.Object, + _restChannelMock.Object, _options); var interaction = new DiscordInteraction(new DiscordInteractionData { Data = new DiscordInteractionRequestData