From 9a52d05637e5f68a57f12a14d14172044e78ca8d Mon Sep 17 00:00:00 2001 From: Quin Lynch <49576606+quinchs@users.noreply.github.com> Date: Fri, 14 Jan 2022 07:52:43 -0400 Subject: [PATCH] Add search methods to InteractionService (#2041) --- .../InteractionService.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/Discord.Net.Interactions/InteractionService.cs b/src/Discord.Net.Interactions/InteractionService.cs index ac96f08ec..b394109a5 100644 --- a/src/Discord.Net.Interactions/InteractionService.cs +++ b/src/Discord.Net.Interactions/InteractionService.cs @@ -588,6 +588,60 @@ namespace Discord.Interactions return true; } + /// + /// Search the registered slash commands using a . + /// + /// Interaction entity to perform the search with. + /// + /// The search result. When successful, result contains the found . + /// + public SearchResult SearchSlashCommand(ISlashCommandInteraction slashCommandInteraction) + => _slashCommandMap.GetCommand(slashCommandInteraction.Data.GetCommandKeywords()); + + /// + /// Search the registered slash commands using a . + /// + /// Interaction entity to perform the search with. + /// + /// The search result. When successful, result contains the found . + /// + public SearchResult SearchComponentCommand(IComponentInteraction componentInteraction) + => _componentCommandMap.GetCommand(componentInteraction.Data.CustomId); + + /// + /// Search the registered slash commands using a . + /// + /// Interaction entity to perform the search with. + /// + /// The search result. When successful, result contains the found . + /// + public SearchResult SearchUserCommand(IUserCommandInteraction userCommandInteraction) + => _contextCommandMaps[ApplicationCommandType.User].GetCommand(userCommandInteraction.Data.Name); + + /// + /// Search the registered slash commands using a . + /// + /// Interaction entity to perform the search with. + /// + /// The search result. When successful, result contains the found . + /// + public SearchResult SearchMessageCommand(IMessageCommandInteraction messageCommandInteraction) + => _contextCommandMaps[ApplicationCommandType.Message].GetCommand(messageCommandInteraction.Data.Name); + + /// + /// Search the registered slash commands using a . + /// + /// Interaction entity to perform the search with. + /// + /// The search result. When successful, result contains the found . + /// + public SearchResult SearchAutocompleteCommand(IAutocompleteInteraction autocompleteInteraction) + { + var keywords = autocompleteInteraction.Data.GetCommandKeywords(); + keywords.Add(autocompleteInteraction.Data.Current.Name); + return _autocompleteCommandMap.GetCommand(keywords); + } + /// /// Execute a Command from a given . ///