cordo 2.6.2 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordo",
3
- "version": "2.6.2",
3
+ "version": "2.7.0",
4
4
  "description": "A framework for handling complex discord api interactions",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
@@ -1,4 +1,4 @@
1
- import { ApplicationCommandType, InteractionContextType, InteractionResponseType, InteractionType, MessageFlags, type APIUser } from "discord-api-types/v10"
1
+ import { ApplicationCommandOptionType, ApplicationCommandType, InteractionContextType, InteractionResponseType, InteractionType, MessageFlags, type APIUser } from "discord-api-types/v10"
2
2
  import { disableAllComponents } from "../../components"
3
3
  import { ComponentType, renderComponent, renderComponentList, type CordoComponent } from "../../components/component"
4
4
  import type { RouteInternals, RouteRequest, RouteResponse } from "../files/route"
@@ -86,6 +86,16 @@ export namespace RoutingRespond {
86
86
  return out
87
87
  }
88
88
 
89
+ function parseCommandOptions(options: any) {
90
+ if (!options)
91
+ return {}
92
+
93
+ if (options.length === 1 && options[0].type === ApplicationCommandOptionType.SubcommandGroup)
94
+ return parseCommandOptions(options[0].options)
95
+
96
+ return (options as Record<string, any>[]).reduce((out, opt) => ({ [opt.name]: opt.value, ...out }), {})
97
+ }
98
+
89
99
  export function buildRouteRequest(
90
100
  route: RouteInternals.ParsedRoute,
91
101
  args: string[],
@@ -194,7 +204,7 @@ export namespace RoutingRespond {
194
204
  // @ts-ignore
195
205
  id: interaction.data.id,
196
206
  // @ts-ignore
197
- options: interaction.data.options?.reduce((out, opt) => ({ [opt.name]: opt.value, ...out }), {}) ?? {},
207
+ options: parseCommandOptions(interaction.data.options),
198
208
  // @ts-ignore
199
209
  type: (interaction.data.type === ApplicationCommandType.ChatInput)
200
210
  ? 'chat'