/// <summary> /// Unpacks an interaction into a command name string and a set of parameters. /// </summary> /// <param name="commandData">The interaction to unpack.</param> /// <param name="commandName">The command name.</param> /// <param name="parameters">The parameters supplied to the command.</param> public static void UnpackInteraction ( this IApplicationCommandInteractionData commandData, out string commandName, out IReadOnlyDictionary <string, IReadOnlyList <string> > parameters ) { if (!commandData.Name.HasValue) { throw new InvalidOperationException(); } if (!commandData.Options.HasValue) { commandName = commandData.Name.Value; parameters = new Dictionary <string, IReadOnlyList <string> >(); return; } UnpackInteractionOptions(commandData.Options.Value !, out var nestedCommandName, out var nestedParameters); commandName = nestedCommandName is not null ? $"{commandData.Name.Value} {nestedCommandName}" : commandData.Name.Value; parameters = nestedParameters ?? new Dictionary <string, IReadOnlyList <string> >(); }
/// <summary> /// Get the name of the executed command and its parents in hierarchical order. /// </summary> /// <param name="data"></param> /// <returns> /// The name of the executed command and its parents in hierarchical order. /// </returns> public static IList <string> GetCommandKeywords(this IApplicationCommandInteractionData data) { var keywords = new List <string> { data.Name }; var child = data.Options?.ElementAtOrDefault(0); while (child?.Type == ApplicationCommandOptionType.SubCommandGroup || child?.Type == ApplicationCommandOptionType.SubCommand) { keywords.Add(child.Name); child = child.Options?.ElementAtOrDefault(0); } return(keywords); }