Browse Source

Add search methods to InteractionService (#2041)

tags/3.2.0
Quin Lynch GitHub 3 years ago
parent
commit
9a52d05637
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 0 deletions
  1. +54
    -0
      src/Discord.Net.Interactions/InteractionService.cs

+ 54
- 0
src/Discord.Net.Interactions/InteractionService.cs View File

@@ -588,6 +588,60 @@ namespace Discord.Interactions
return true;
}

/// <summary>
/// Search the registered slash commands using a <see cref="ISlashCommandInteraction"/>.
/// </summary>
/// <param name="slashCommandInteraction">Interaction entity to perform the search with.</param>
/// <returns>
/// The search result. When successful, result contains the found <see cref="SlashCommandInfo"/>.
/// </returns>
public SearchResult<SlashCommandInfo> SearchSlashCommand(ISlashCommandInteraction slashCommandInteraction)
=> _slashCommandMap.GetCommand(slashCommandInteraction.Data.GetCommandKeywords());

/// <summary>
/// Search the registered slash commands using a <see cref="IComponentInteraction"/>.
/// </summary>
/// <param name="componentInteraction">Interaction entity to perform the search with.</param>
/// <returns>
/// The search result. When successful, result contains the found <see cref="ComponentCommandInfo"/>.
/// </returns>
public SearchResult<ComponentCommandInfo> SearchComponentCommand(IComponentInteraction componentInteraction)
=> _componentCommandMap.GetCommand(componentInteraction.Data.CustomId);

/// <summary>
/// Search the registered slash commands using a <see cref="IUserCommandInteraction"/>.
/// </summary>
/// <param name="userCommandInteraction">Interaction entity to perform the search with.</param>
/// <returns>
/// The search result. When successful, result contains the found <see cref="ContextCommandInfo"/>.
/// </returns>
public SearchResult<ContextCommandInfo> SearchUserCommand(IUserCommandInteraction userCommandInteraction)
=> _contextCommandMaps[ApplicationCommandType.User].GetCommand(userCommandInteraction.Data.Name);

/// <summary>
/// Search the registered slash commands using a <see cref="IMessageCommandInteraction"/>.
/// </summary>
/// <param name="messageCommandInteraction">Interaction entity to perform the search with.</param>
/// <returns>
/// The search result. When successful, result contains the found <see cref="ContextCommandInfo"/>.
/// </returns>
public SearchResult<ContextCommandInfo> SearchMessageCommand(IMessageCommandInteraction messageCommandInteraction)
=> _contextCommandMaps[ApplicationCommandType.Message].GetCommand(messageCommandInteraction.Data.Name);

/// <summary>
/// Search the registered slash commands using a <see cref="IAutocompleteInteraction"/>.
/// </summary>
/// <param name="autocompleteInteraction">Interaction entity to perform the search with.</param>
/// <returns>
/// The search result. When successful, result contains the found <see cref="AutocompleteCommandInfo"/>.
/// </returns>
public SearchResult<AutocompleteCommandInfo> SearchAutocompleteCommand(IAutocompleteInteraction autocompleteInteraction)
{
var keywords = autocompleteInteraction.Data.GetCommandKeywords();
keywords.Add(autocompleteInteraction.Data.Current.Name);
return _autocompleteCommandMap.GetCommand(keywords);
}

/// <summary>
/// Execute a Command from a given <see cref="IInteractionContext"/>.
/// </summary>


Loading…
Cancel
Save