nuxt-discord 0.0.17 → 0.2.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.
Files changed (132) hide show
  1. package/README.md +249 -171
  2. package/dist/module.d.mts +146 -10
  3. package/dist/module.json +3 -3
  4. package/dist/module.mjs +1077 -348
  5. package/dist/runtime/acknowledgement.d.ts +11 -0
  6. package/dist/runtime/acknowledgement.js +156 -0
  7. package/dist/runtime/client/chat-theme.css +52 -0
  8. package/dist/runtime/client/components/ChatAvatar.d.vue.ts +6 -0
  9. package/dist/runtime/client/components/ChatAvatar.vue +11 -0
  10. package/dist/runtime/client/components/ChatAvatar.vue.d.ts +6 -0
  11. package/dist/runtime/client/components/CommandPicker.d.vue.ts +24 -0
  12. package/dist/runtime/client/components/CommandPicker.vue +67 -0
  13. package/dist/runtime/client/components/CommandPicker.vue.d.ts +24 -0
  14. package/dist/runtime/client/components/CommandReference.d.vue.ts +20 -0
  15. package/dist/runtime/client/components/CommandReference.vue +21 -0
  16. package/dist/runtime/client/components/CommandReference.vue.d.ts +20 -0
  17. package/dist/runtime/client/components/CommandTestBar.d.vue.ts +60 -0
  18. package/dist/runtime/client/components/CommandTestBar.vue +332 -0
  19. package/dist/runtime/client/components/CommandTestBar.vue.d.ts +60 -0
  20. package/dist/runtime/client/components/CommandTranscript.d.vue.ts +39 -0
  21. package/dist/runtime/client/components/CommandTranscript.vue +147 -0
  22. package/dist/runtime/client/components/CommandTranscript.vue.d.ts +39 -0
  23. package/dist/runtime/client/components/ProjectLogo.d.vue.ts +3 -0
  24. package/dist/runtime/client/components/ProjectLogo.vue +31 -0
  25. package/dist/runtime/client/components/ProjectLogo.vue.d.ts +3 -0
  26. package/dist/runtime/client/components/ReferenceContent.d.ts +26 -0
  27. package/dist/runtime/client/components/ReferenceContent.js +73 -0
  28. package/dist/runtime/client/components/TheHeader.d.vue.ts +3 -0
  29. package/dist/runtime/client/components/TheHeader.vue +53 -16
  30. package/dist/runtime/client/components/TheHeader.vue.d.ts +2 -2
  31. package/dist/runtime/client/components/appearance-select.d.ts +17 -0
  32. package/dist/runtime/client/components/appearance-select.js +15 -0
  33. package/dist/runtime/client/pages/activity.d.vue.ts +3 -0
  34. package/dist/runtime/client/pages/activity.vue +202 -0
  35. package/dist/runtime/client/pages/activity.vue.d.ts +3 -0
  36. package/dist/runtime/client/pages/context-menus.d.vue.ts +3 -0
  37. package/dist/runtime/client/pages/context-menus.vue +120 -0
  38. package/dist/runtime/client/pages/context-menus.vue.d.ts +3 -0
  39. package/dist/runtime/client/pages/listeners.d.vue.ts +3 -0
  40. package/dist/runtime/client/pages/listeners.vue +68 -0
  41. package/dist/runtime/client/pages/listeners.vue.d.ts +3 -0
  42. package/dist/runtime/client/pages/overview.d.vue.ts +3 -0
  43. package/dist/runtime/client/pages/overview.vue +280 -0
  44. package/dist/runtime/client/pages/overview.vue.d.ts +3 -0
  45. package/dist/runtime/client/pages/slash-commands.d.vue.ts +3 -0
  46. package/dist/runtime/client/pages/slash-commands.vue +185 -359
  47. package/dist/runtime/client/pages/slash-commands.vue.d.ts +2 -3
  48. package/dist/runtime/client/reference.css +46 -0
  49. package/dist/runtime/client/style.css +4 -1
  50. package/dist/runtime/client/useActivityLog.d.ts +7 -0
  51. package/dist/runtime/client/useActivityLog.js +76 -0
  52. package/dist/runtime/client/useCommandRegistry.d.ts +7 -0
  53. package/dist/runtime/client/useCommandRegistry.js +34 -0
  54. package/dist/runtime/client/useDashboardCatalog.d.ts +5 -0
  55. package/dist/runtime/client/useDashboardCatalog.js +9 -0
  56. package/dist/runtime/client/useDiscordCommandReference.d.ts +2 -0
  57. package/dist/runtime/client/useDiscordCommandReference.js +6 -0
  58. package/dist/runtime/dashboard/auth.d.ts +4 -0
  59. package/dist/runtime/dashboard/auth.js +55 -0
  60. package/dist/runtime/dashboard/oauth.d.ts +17 -0
  61. package/dist/runtime/dashboard/oauth.js +172 -0
  62. package/dist/runtime/dashboard/origin.d.ts +3 -0
  63. package/dist/runtime/dashboard/origin.js +15 -0
  64. package/dist/runtime/dashboard/permissions.d.ts +4 -0
  65. package/dist/runtime/dashboard/permissions.js +84 -0
  66. package/dist/runtime/dashboard/signin.d.ts +3 -0
  67. package/dist/runtime/dashboard/signin.js +42 -0
  68. package/dist/runtime/diagnostics.d.ts +4 -0
  69. package/dist/runtime/diagnostics.js +24 -0
  70. package/dist/runtime/discordInvocation.d.ts +14 -0
  71. package/dist/runtime/discordInvocation.js +28 -0
  72. package/dist/runtime/middleware.d.ts +1 -0
  73. package/dist/runtime/middleware.js +12 -0
  74. package/dist/runtime/reference/access.d.ts +6 -0
  75. package/dist/runtime/reference/access.js +143 -0
  76. package/dist/runtime/reference/catalog.d.ts +2 -0
  77. package/dist/runtime/reference/catalog.js +9 -0
  78. package/dist/runtime/reference/document.d.ts +2 -0
  79. package/dist/runtime/reference/document.js +22 -0
  80. package/dist/runtime/reference/hosted.d.ts +2 -0
  81. package/dist/runtime/reference/hosted.js +16 -0
  82. package/dist/runtime/reference/oauth.d.ts +2 -0
  83. package/dist/runtime/reference/oauth.js +4 -0
  84. package/dist/runtime/registration.d.ts +65 -0
  85. package/dist/runtime/registration.js +354 -0
  86. package/dist/runtime/server/api/discord/activity.get.d.ts +2 -0
  87. package/dist/runtime/server/api/discord/activity.get.js +6 -0
  88. package/dist/runtime/server/api/discord/catalog.get.d.ts +2 -0
  89. package/dist/runtime/server/api/discord/catalog.get.js +3 -0
  90. package/dist/runtime/server/api/discord/slash-command/autocomplete.post.d.ts +2 -0
  91. package/dist/runtime/server/api/discord/slash-command/autocomplete.post.js +14 -0
  92. package/dist/runtime/server/api/discord/slash-command/register.post.d.ts +1 -1
  93. package/dist/runtime/server/api/discord/slash-command/register.post.js +1 -1
  94. package/dist/runtime/server/api/discord/slash-command/remote-all.get.d.ts +1 -1
  95. package/dist/runtime/server/api/discord/slash-command/remote-diff.post.d.ts +1 -238
  96. package/dist/runtime/server/api/discord/slash-command/remote-diff.post.js +3 -1
  97. package/dist/runtime/server/api/discord/slash-command/test.post.d.ts +20 -0
  98. package/dist/runtime/server/api/discord/slash-command/test.post.js +19 -0
  99. package/dist/runtime/server/plugins/discord.js +95 -31
  100. package/dist/runtime/server/utils/client.d.ts +59 -246
  101. package/dist/runtime/server/utils/client.js +413 -451
  102. package/dist/runtime/server/utils/defineContextMenu.d.ts +49 -0
  103. package/dist/runtime/server/utils/defineContextMenu.js +12 -0
  104. package/dist/runtime/server/utils/defineListener.d.ts +24 -0
  105. package/dist/runtime/server/utils/defineListener.js +7 -0
  106. package/dist/runtime/server/utils/defineMiddleware.d.ts +29 -0
  107. package/dist/runtime/server/utils/defineMiddleware.js +24 -0
  108. package/dist/runtime/server/utils/describeCommand.d.ts +2 -0
  109. package/dist/runtime/server/utils/describeOption.d.ts +1 -1
  110. package/dist/runtime/server/utils/messageSender.d.ts +37 -0
  111. package/dist/runtime/server/utils/messageSender.js +149 -0
  112. package/dist/runtime/server/utils/middleware/cooldown.d.ts +1 -0
  113. package/dist/runtime/server/utils/middleware/cooldown.js +39 -0
  114. package/dist/runtime/server/utils/middleware/guildOnly.d.ts +1 -0
  115. package/dist/runtime/server/utils/middleware/guildOnly.js +6 -0
  116. package/dist/runtime/server/utils/middleware/ownerOnly.d.ts +1 -0
  117. package/dist/runtime/server/utils/middleware/ownerOnly.js +10 -0
  118. package/dist/runtime/server/utils/middleware/requireRole.d.ts +1 -0
  119. package/dist/runtime/server/utils/middleware/requireRole.js +15 -0
  120. package/dist/runtime/server/utils/reply.d.ts +13 -3
  121. package/dist/runtime/server/utils/reply.js +111 -162
  122. package/dist/runtime/server/utils/simulateInteraction.d.ts +20 -0
  123. package/dist/runtime/server/utils/simulateInteraction.js +127 -0
  124. package/dist/runtime/server/utils/useTextChannel.d.ts +56 -0
  125. package/dist/runtime/server/utils/useTextChannel.js +105 -0
  126. package/dist/types.d.mts +11 -1
  127. package/dist/types.d.ts +11 -1
  128. package/package.json +62 -44
  129. package/dist/runtime/client/components/TheHeader.css +0 -1
  130. package/dist/runtime/client/pages/slash-commands.css +0 -1
  131. package/dist/runtime/client/uno.config.d.ts +0 -2
  132. package/dist/runtime/client/uno.config.js +0 -10
@@ -0,0 +1,354 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import { ApplicationCommandOptionType, ApplicationCommandType, ContextMenuCommandBuilder, Routes, SlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from "discord.js";
3
+ function getSlashCommandBuilder(command, builder) {
4
+ builder ??= new SlashCommandBuilder();
5
+ builder.setName(command.name).setDescription(command.description);
6
+ if (command.nameLocalizations)
7
+ builder.setNameLocalizations(command.nameLocalizations);
8
+ if (command.descriptionLocalizations)
9
+ builder.setDescriptionLocalizations(command.descriptionLocalizations);
10
+ if (builder instanceof SlashCommandBuilder) {
11
+ if (command.nsfw != null)
12
+ builder.setNSFW(command.nsfw);
13
+ if (!command.guilds && command.contexts != null)
14
+ builder.setContexts(...command.contexts);
15
+ if (command.defaultMemberPermissions !== void 0)
16
+ builder.setDefaultMemberPermissions(command.defaultMemberPermissions);
17
+ }
18
+ const children = command.subcommands?.length ? command.subcommands : command.options;
19
+ if (new Set(children.map((child) => child.name)).size !== children.length)
20
+ throw new Error(`Duplicate option or subcommand name in ${command.path}`);
21
+ if (command.subcommands?.length && command.options.length)
22
+ throw new Error(`Discord commands with subcommands cannot also declare parameters: ${command.path}`);
23
+ if (command.subcommands != null && command.subcommands.length > 0) {
24
+ for (const subcommand of command.subcommands) {
25
+ if (builder instanceof SlashCommandBuilder) {
26
+ if ("subcommands" in subcommand && (subcommand.subcommands?.length ?? 0) > 0) {
27
+ builder.addSubcommandGroup((subcommandGroupBuilder) => getSlashCommandBuilder(subcommand, subcommandGroupBuilder));
28
+ } else {
29
+ builder.addSubcommand((subcommandBuilder) => getSlashCommandBuilder(subcommand, subcommandBuilder));
30
+ }
31
+ } else if (builder instanceof SlashCommandSubcommandGroupBuilder) {
32
+ builder.addSubcommand((subcommandBuilder) => getSlashCommandBuilder(subcommand, subcommandBuilder));
33
+ } else {
34
+ throw new TypeError(`Unexpected builder type: ${builder.constructor.name}`);
35
+ }
36
+ }
37
+ } else if (builder instanceof SlashCommandBuilder || builder instanceof SlashCommandSubcommandBuilder) {
38
+ for (const option of command.options.toSorted((a, b) => Number(b.required) - Number(a.required))) {
39
+ switch (option.type) {
40
+ case ApplicationCommandOptionType.String:
41
+ builder.addStringOption((opt) => {
42
+ setBasicOptionFields(opt, option);
43
+ if (option.minLength !== void 0)
44
+ opt.setMinLength(option.minLength);
45
+ if (option.maxLength !== void 0)
46
+ opt.setMaxLength(option.maxLength);
47
+ if (option.choices)
48
+ opt.addChoices(...option.choices);
49
+ if (option.hasAutocomplete)
50
+ opt.setAutocomplete(true);
51
+ return opt;
52
+ });
53
+ break;
54
+ case ApplicationCommandOptionType.Integer:
55
+ builder.addIntegerOption((opt) => {
56
+ setBasicOptionFields(opt, option);
57
+ if (option.min !== void 0)
58
+ opt.setMinValue(option.min);
59
+ if (option.max !== void 0)
60
+ opt.setMaxValue(option.max);
61
+ if (option.choices)
62
+ opt.addChoices(...option.choices);
63
+ if (option.hasAutocomplete)
64
+ opt.setAutocomplete(true);
65
+ return opt;
66
+ });
67
+ break;
68
+ case ApplicationCommandOptionType.Number:
69
+ builder.addNumberOption((opt) => {
70
+ setBasicOptionFields(opt, option);
71
+ if (option.min !== void 0)
72
+ opt.setMinValue(option.min);
73
+ if (option.max !== void 0)
74
+ opt.setMaxValue(option.max);
75
+ if (option.choices)
76
+ opt.addChoices(...option.choices);
77
+ if (option.hasAutocomplete)
78
+ opt.setAutocomplete(true);
79
+ return opt;
80
+ });
81
+ break;
82
+ case ApplicationCommandOptionType.Boolean:
83
+ builder.addBooleanOption((opt) => setBasicOptionFields(opt, option));
84
+ break;
85
+ case ApplicationCommandOptionType.Channel:
86
+ builder.addChannelOption((opt) => setBasicOptionFields(opt, option));
87
+ break;
88
+ case ApplicationCommandOptionType.User:
89
+ builder.addUserOption((opt) => setBasicOptionFields(opt, option));
90
+ break;
91
+ case ApplicationCommandOptionType.Role:
92
+ builder.addRoleOption((opt) => setBasicOptionFields(opt, option));
93
+ break;
94
+ case ApplicationCommandOptionType.Mentionable:
95
+ builder.addMentionableOption((opt) => setBasicOptionFields(opt, option));
96
+ break;
97
+ case ApplicationCommandOptionType.Attachment:
98
+ builder.addAttachmentOption((opt) => setBasicOptionFields(opt, option));
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ return builder;
104
+ }
105
+ function setBasicOptionFields(opt, option) {
106
+ opt.setName(option.name).setRequired(option.required);
107
+ opt.setDescription(option.description || option.name);
108
+ if (option.nameLocalizations)
109
+ opt.setNameLocalizations(option.nameLocalizations);
110
+ if (option.descriptionLocalizations)
111
+ opt.setDescriptionLocalizations(option.descriptionLocalizations);
112
+ return opt;
113
+ }
114
+ export function commandScopes(targets, guilds) {
115
+ return targets === true ? guilds : targets ?? ["global"];
116
+ }
117
+ export function planRegistrations(commands, menus, guilds) {
118
+ const scopes = /* @__PURE__ */ new Map();
119
+ const unassigned = [];
120
+ const unassignedMenus = [];
121
+ function add(scope, entry) {
122
+ const entries = scopes.get(scope) ?? [];
123
+ entries.push(entry);
124
+ scopes.set(scope, entries);
125
+ }
126
+ for (const command of commands) {
127
+ const targets = commandScopes(command.guilds, guilds);
128
+ if (!targets.length) {
129
+ unassigned.push(command);
130
+ continue;
131
+ }
132
+ const body = getSlashCommandBuilder(command, new SlashCommandBuilder()).toJSON();
133
+ for (const scope of new Set(targets))
134
+ add(scope, { body, local: command });
135
+ }
136
+ for (const menu of menus) {
137
+ const type = menu.type === "user" ? ApplicationCommandType.User : ApplicationCommandType.Message;
138
+ const targets = commandScopes(menu.guilds, guilds);
139
+ if (!targets.length) {
140
+ unassignedMenus.push(menu.name);
141
+ continue;
142
+ }
143
+ const body = new ContextMenuCommandBuilder().setName(menu.name).setType(type).toJSON();
144
+ for (const scope of new Set(targets))
145
+ add(scope, { body });
146
+ }
147
+ return { scopes, unassigned, unassignedMenus };
148
+ }
149
+ function scopesToReconcile(plan, managed) {
150
+ const scopes = /* @__PURE__ */ new Set([...plan.scopes.keys(), ...managed]);
151
+ if (plan.unassigned.length || plan.unassignedMenus.length)
152
+ return [...scopes].filter((scope) => scope === "global");
153
+ return [...scopes];
154
+ }
155
+ function identity(command) {
156
+ return `${command.type ?? ApplicationCommandType.ChatInput}:${command.name}`;
157
+ }
158
+ function comparable(command) {
159
+ return {
160
+ type: command.type ?? ApplicationCommandType.ChatInput,
161
+ name: command.name,
162
+ description: "description" in command && command.description || "",
163
+ nameLocalizations: command.name_localizations ?? {},
164
+ descriptionLocalizations: "description_localizations" in command && command.description_localizations || {},
165
+ contexts: [...command.contexts ?? [0, 1, 2]].sort(),
166
+ permissions: command.default_member_permissions ?? null,
167
+ nsfw: command.nsfw ?? false,
168
+ options: ("options" in command ? command.options ?? [] : []).map(optionShape)
169
+ };
170
+ }
171
+ function optionShape(option) {
172
+ return {
173
+ type: option.type,
174
+ name: option.name,
175
+ description: option.description,
176
+ names: option.name_localizations ?? {},
177
+ descriptions: option.description_localizations ?? {},
178
+ required: option.required ?? false,
179
+ autocomplete: "autocomplete" in option && !!option.autocomplete,
180
+ min: "min_value" in option ? option.min_value : void 0,
181
+ max: "max_value" in option ? option.max_value : void 0,
182
+ minLength: "min_length" in option ? option.min_length : void 0,
183
+ maxLength: "max_length" in option ? option.max_length : void 0,
184
+ channels: "channel_types" in option ? option.channel_types : void 0,
185
+ choices: ("choices" in option ? option.choices ?? [] : []).map((choice) => ({
186
+ name: choice.name,
187
+ value: choice.value,
188
+ names: choice.name_localizations ?? {}
189
+ })),
190
+ options: ("options" in option ? option.options ?? [] : []).map(optionShape)
191
+ };
192
+ }
193
+ function schemaRows(command, scope) {
194
+ const rows = /* @__PURE__ */ new Map();
195
+ function visit(row, schema) {
196
+ rows.set(row.name, { row, schema });
197
+ for (const option of row.options) {
198
+ if (option.type === ApplicationCommandOptionType.Subcommand || option.type === ApplicationCommandOptionType.SubcommandGroup) {
199
+ visit({ scope, name: `${row.name} ${option.name}`, description: option.description, options: option.options ?? [] }, optionShape(option));
200
+ }
201
+ }
202
+ }
203
+ visit({
204
+ scope,
205
+ name: command.name,
206
+ description: "description" in command && command.description || "",
207
+ options: "options" in command && command.options || [],
208
+ id: "id" in command ? command.id : void 0
209
+ }, comparable(command));
210
+ return rows;
211
+ }
212
+ function localRows(command, scope, name = command.name) {
213
+ return [{ ...command, scope, name }, ...(command.subcommands ?? []).flatMap((sub) => localRows(sub, scope, `${name} ${sub.name}`))];
214
+ }
215
+ function duplicates(entries) {
216
+ const seen = /* @__PURE__ */ new Set();
217
+ const repeated = /* @__PURE__ */ new Set();
218
+ for (const { body } of entries) {
219
+ const key = identity(body);
220
+ if (seen.has(key))
221
+ repeated.add(key);
222
+ seen.add(key);
223
+ }
224
+ return repeated;
225
+ }
226
+ export class CommandRegistration {
227
+ constructor(rest, appId, store, onError) {
228
+ this.rest = rest;
229
+ this.appId = appId;
230
+ this.store = store;
231
+ this.onError = onError;
232
+ }
233
+ confirmed = /* @__PURE__ */ new Map();
234
+ queue = Promise.resolve();
235
+ route(scope) {
236
+ return scope === "global" ? Routes.applicationCommands(this.appId) : Routes.applicationGuildCommands(this.appId, scope);
237
+ }
238
+ async read(scope) {
239
+ const query = new URLSearchParams({ with_localizations: "true" });
240
+ return await this.rest.get(this.route(scope), { query });
241
+ }
242
+ async diff(plan) {
243
+ const added = [];
244
+ const removed = [];
245
+ const changed = [];
246
+ const synced = [];
247
+ const conflict = plan.unassigned.map((command) => ({ ...command, scope: "unconfigured guild" }));
248
+ let menuChanges = plan.unassignedMenus.length;
249
+ for (const scope of scopesToReconcile(plan, await this.store.load() ?? [])) {
250
+ const desired = plan.scopes.get(scope) ?? [];
251
+ const remote = await this.read(scope);
252
+ const existing = new Map(remote.map((cmd) => [identity(cmd), cmd]));
253
+ const duplicate = duplicates(desired);
254
+ for (const { local, body } of desired) {
255
+ const key = identity(body);
256
+ const current = existing.get(key);
257
+ existing.delete(key);
258
+ if (!local) {
259
+ if (!current || !isDeepStrictEqual(comparable(body), comparable(current)))
260
+ menuChanges++;
261
+ continue;
262
+ }
263
+ const rows = localRows(local, scope);
264
+ if (duplicate.has(key)) {
265
+ conflict.push(...rows);
266
+ continue;
267
+ }
268
+ if (!current) {
269
+ added.push(...rows);
270
+ continue;
271
+ }
272
+ const wanted = schemaRows(body, scope);
273
+ const existingRows = schemaRows(current, scope);
274
+ for (const row of rows) {
275
+ const match = existingRows.get(row.name);
276
+ existingRows.delete(row.name);
277
+ if (match) {
278
+ const list = isDeepStrictEqual(wanted.get(row.name)?.schema, match.schema) ? synced : changed;
279
+ list.push({ local: row, remote: match.row });
280
+ } else {
281
+ added.push(row);
282
+ }
283
+ }
284
+ for (const { row } of existingRows.values())
285
+ removed.push(row);
286
+ }
287
+ for (const cmd of existing.values()) {
288
+ if (cmd.type === ApplicationCommandType.ChatInput)
289
+ removed.push(...Array.from(schemaRows(cmd, scope).values(), (entry) => entry.row));
290
+ else
291
+ menuChanges++;
292
+ }
293
+ }
294
+ return { added, removed, changed, synced, conflict, menuChanges };
295
+ }
296
+ sync(plan, changedOnly = false) {
297
+ const pending = this.queue.then(() => this.apply(plan, changedOnly));
298
+ this.queue = pending.then(() => {
299
+ }, () => {
300
+ });
301
+ return pending;
302
+ }
303
+ async apply(plan, changedOnly) {
304
+ const managed = new Set(await this.store.load() ?? []);
305
+ const results = [];
306
+ const missingTargets = [...plan.unassigned.map((cmd) => `/${cmd.name}`), ...plan.unassignedMenus];
307
+ if (missingTargets.length) {
308
+ const error = new Error(`Set discord.guilds or DISCORD_GUILD_ID for ${missingTargets.join(", ")}`);
309
+ this.onError(error);
310
+ results.push({ scope: "unconfigured guild", commands: [], error: error.message });
311
+ }
312
+ for (const scope of scopesToReconcile(plan, [...managed])) {
313
+ const desired = plan.scopes.get(scope) ?? [];
314
+ try {
315
+ if (duplicates(desired).size)
316
+ throw new Error("Duplicate command names in this scope");
317
+ for (const [type, max] of [[ApplicationCommandType.ChatInput, 100], [ApplicationCommandType.User, 15], [ApplicationCommandType.Message, 15]]) {
318
+ if (desired.filter(({ body: body2 }) => (body2.type ?? ApplicationCommandType.ChatInput) === type).length > max)
319
+ throw new Error(`Discord allows up to ${max} ${ApplicationCommandType[type]} commands per scope`);
320
+ }
321
+ const body = desired.map((entry) => entry.body);
322
+ const schema = body.map(comparable);
323
+ if (changedOnly && isDeepStrictEqual(this.confirmed.get(scope), schema))
324
+ continue;
325
+ let commands = await this.read(scope);
326
+ const byKey = new Map(commands.map((cmd) => [identity(cmd), cmd]));
327
+ const matches = body.length === commands.length && body.every((cmd, index) => {
328
+ const existing = byKey.get(identity(cmd));
329
+ return existing && isDeepStrictEqual(schema[index], comparable(existing));
330
+ });
331
+ if (!matches)
332
+ commands = await this.rest.put(this.route(scope), { body });
333
+ const returned = new Map(commands.map((cmd) => [identity(cmd), cmd.id]));
334
+ for (const { local, body: body2 } of desired) {
335
+ if (local)
336
+ local.id = returned.get(identity(body2));
337
+ }
338
+ if (managed.has(scope) !== body.length > 0) {
339
+ if (body.length)
340
+ managed.add(scope);
341
+ else managed.delete(scope);
342
+ await this.store.save([...managed]);
343
+ }
344
+ this.confirmed.set(scope, schema);
345
+ results.push({ scope, commands });
346
+ } catch (error) {
347
+ this.confirmed.delete(scope);
348
+ this.onError(error);
349
+ results.push({ scope, commands: [], error: error instanceof Error ? error.message : String(error) });
350
+ }
351
+ }
352
+ return results;
353
+ }
354
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, import("../../utils/client.js").ActivityLogEntry[]>;
2
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import { defineEventHandler } from "h3";
2
+ import { useDiscordClient } from "../../utils/useDiscordClient.js";
3
+ export default defineEventHandler(() => {
4
+ const client = useDiscordClient();
5
+ return client.getActivityLog();
6
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, any>;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import catalog from "discord/catalog";
2
+ import { defineEventHandler } from "h3";
3
+ export default defineEventHandler(() => catalog);
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<import("discord.js").ApplicationCommandOptionChoiceData<string | number>[]>>;
2
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import { defineEventHandler, readBody } from "h3";
2
+ import { simulateInteraction } from "../../../utils/simulateInteraction.js";
3
+ import { useDiscordClient } from "../../../utils/useDiscordClient.js";
4
+ export default defineEventHandler(async (event) => {
5
+ const body = await readBody(event);
6
+ if (!body?.command || !body.option)
7
+ return [];
8
+ const result = await simulateInteraction(
9
+ useDiscordClient(),
10
+ { name: body.command, options: body.options },
11
+ { option: body.option, value: body.value ?? "" }
12
+ );
13
+ return result.choices;
14
+ });
@@ -1,2 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<import("discord.js").RESTPutAPIApplicationCommandsResult | PromiseSettledResult<import("discord.js").APIApplicationCommand>[]>>;
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<import("../../../../registration.js").RegistrationResult[]>>;
2
2
  export default _default;
@@ -2,5 +2,5 @@ import { defineEventHandler } from "h3";
2
2
  import { useDiscordClient } from "../../../utils/useDiscordClient.js";
3
3
  export default defineEventHandler(async () => {
4
4
  const client = useDiscordClient();
5
- return client.registerSlashCommands();
5
+ return client.syncCommandRegistrations();
6
6
  });
@@ -1,4 +1,4 @@
1
1
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
- commands: import("discord.js").RESTGetAPIApplicationCommandsResult;
2
+ commands: import("discord.js").APIApplicationCommand[];
3
3
  }>>;
4
4
  export default _default;
@@ -1,239 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
- added: (import("../../../../../types.js").SlashCommandRuntime | import("../../../../../types.js").SlashCommandSubcommandRuntime | import("../../../../../types.js").SlashCommandSubcommandGroupRuntime)[];
3
- removed: ({
4
- name: string;
5
- subcommands: never[];
6
- options?: import("discord.js").APIApplicationCommandBasicOption[];
7
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
8
- name_localizations?: import("discord.js").LocalizationMap | null;
9
- description: string;
10
- description_localizations?: import("discord.js").LocalizationMap | null;
11
- required?: boolean;
12
- } | {
13
- name: string;
14
- subcommands: {
15
- name: string;
16
- subcommands: never[];
17
- options?: import("discord.js").APIApplicationCommandBasicOption[];
18
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
19
- name_localizations?: import("discord.js").LocalizationMap | null;
20
- description: string;
21
- description_localizations?: import("discord.js").LocalizationMap | null;
22
- required?: boolean;
23
- }[];
24
- options?: import("discord.js").APIApplicationCommandSubcommandOption[];
25
- type: import("discord.js").ApplicationCommandOptionType.SubcommandGroup;
26
- name_localizations?: import("discord.js").LocalizationMap | null;
27
- description: string;
28
- description_localizations?: import("discord.js").LocalizationMap | null;
29
- required?: boolean;
30
- } | {
31
- subcommands: ({
32
- name: string;
33
- subcommands: never[];
34
- options?: import("discord.js").APIApplicationCommandBasicOption[];
35
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
36
- name_localizations?: import("discord.js").LocalizationMap | null;
37
- description: string;
38
- description_localizations?: import("discord.js").LocalizationMap | null;
39
- required?: boolean;
40
- } | {
41
- name: string;
42
- subcommands: {
43
- name: string;
44
- subcommands: never[];
45
- options?: import("discord.js").APIApplicationCommandBasicOption[];
46
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
47
- name_localizations?: import("discord.js").LocalizationMap | null;
48
- description: string;
49
- description_localizations?: import("discord.js").LocalizationMap | null;
50
- required?: boolean;
51
- }[];
52
- options?: import("discord.js").APIApplicationCommandSubcommandOption[];
53
- type: import("discord.js").ApplicationCommandOptionType.SubcommandGroup;
54
- name_localizations?: import("discord.js").LocalizationMap | null;
55
- description: string;
56
- description_localizations?: import("discord.js").LocalizationMap | null;
57
- required?: boolean;
58
- })[];
59
- id: import("discord.js").Snowflake;
60
- type: import("discord.js").ApplicationCommandType;
61
- application_id: import("discord.js").Snowflake;
62
- guild_id?: import("discord.js").Snowflake;
63
- name: string;
64
- name_localizations?: import("discord.js").LocalizationMap | null;
65
- name_localized?: string;
66
- description: string;
67
- description_localizations?: import("discord.js").LocalizationMap | null;
68
- description_localized?: string;
69
- options?: import("discord.js").APIApplicationCommandOption[];
70
- default_member_permissions: import("discord.js").Permissions | null;
71
- dm_permission?: boolean;
72
- default_permission?: boolean;
73
- nsfw?: boolean;
74
- integration_types?: import("discord.js").ApplicationIntegrationType[];
75
- contexts?: import("discord.js").InteractionContextType[] | null;
76
- version: import("discord.js").Snowflake;
77
- handler?: import("discord.js").EntryPointCommandHandlerType;
78
- })[];
79
- changed: {
80
- local: import("../../../../../types.js").SlashCommandRuntime | import("../../../../../types.js").SlashCommandSubcommandRuntime | import("../../../../../types.js").SlashCommandSubcommandGroupRuntime;
81
- remote: {
82
- name: string;
83
- subcommands: never[];
84
- options?: import("discord.js").APIApplicationCommandBasicOption[];
85
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
86
- name_localizations?: import("discord.js").LocalizationMap | null;
87
- description: string;
88
- description_localizations?: import("discord.js").LocalizationMap | null;
89
- required?: boolean;
90
- } | {
91
- name: string;
92
- subcommands: {
93
- name: string;
94
- subcommands: never[];
95
- options?: import("discord.js").APIApplicationCommandBasicOption[];
96
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
97
- name_localizations?: import("discord.js").LocalizationMap | null;
98
- description: string;
99
- description_localizations?: import("discord.js").LocalizationMap | null;
100
- required?: boolean;
101
- }[];
102
- options?: import("discord.js").APIApplicationCommandSubcommandOption[];
103
- type: import("discord.js").ApplicationCommandOptionType.SubcommandGroup;
104
- name_localizations?: import("discord.js").LocalizationMap | null;
105
- description: string;
106
- description_localizations?: import("discord.js").LocalizationMap | null;
107
- required?: boolean;
108
- } | {
109
- subcommands: ({
110
- name: string;
111
- subcommands: never[];
112
- options?: import("discord.js").APIApplicationCommandBasicOption[];
113
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
114
- name_localizations?: import("discord.js").LocalizationMap | null;
115
- description: string;
116
- description_localizations?: import("discord.js").LocalizationMap | null;
117
- required?: boolean;
118
- } | {
119
- name: string;
120
- subcommands: {
121
- name: string;
122
- subcommands: never[];
123
- options?: import("discord.js").APIApplicationCommandBasicOption[];
124
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
125
- name_localizations?: import("discord.js").LocalizationMap | null;
126
- description: string;
127
- description_localizations?: import("discord.js").LocalizationMap | null;
128
- required?: boolean;
129
- }[];
130
- options?: import("discord.js").APIApplicationCommandSubcommandOption[];
131
- type: import("discord.js").ApplicationCommandOptionType.SubcommandGroup;
132
- name_localizations?: import("discord.js").LocalizationMap | null;
133
- description: string;
134
- description_localizations?: import("discord.js").LocalizationMap | null;
135
- required?: boolean;
136
- })[];
137
- id: import("discord.js").Snowflake;
138
- type: import("discord.js").ApplicationCommandType;
139
- application_id: import("discord.js").Snowflake;
140
- guild_id?: import("discord.js").Snowflake;
141
- name: string;
142
- name_localizations?: import("discord.js").LocalizationMap | null;
143
- name_localized?: string;
144
- description: string;
145
- description_localizations?: import("discord.js").LocalizationMap | null;
146
- description_localized?: string;
147
- options?: import("discord.js").APIApplicationCommandOption[];
148
- default_member_permissions: import("discord.js").Permissions | null;
149
- dm_permission?: boolean;
150
- default_permission?: boolean;
151
- nsfw?: boolean;
152
- integration_types?: import("discord.js").ApplicationIntegrationType[];
153
- contexts?: import("discord.js").InteractionContextType[] | null;
154
- version: import("discord.js").Snowflake;
155
- handler?: import("discord.js").EntryPointCommandHandlerType;
156
- };
157
- }[];
158
- synced: {
159
- local: import("../../../../../types.js").SlashCommandRuntime | import("../../../../../types.js").SlashCommandSubcommandRuntime | import("../../../../../types.js").SlashCommandSubcommandGroupRuntime;
160
- remote: {
161
- name: string;
162
- subcommands: never[];
163
- options?: import("discord.js").APIApplicationCommandBasicOption[];
164
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
165
- name_localizations?: import("discord.js").LocalizationMap | null;
166
- description: string;
167
- description_localizations?: import("discord.js").LocalizationMap | null;
168
- required?: boolean;
169
- } | {
170
- name: string;
171
- subcommands: {
172
- name: string;
173
- subcommands: never[];
174
- options?: import("discord.js").APIApplicationCommandBasicOption[];
175
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
176
- name_localizations?: import("discord.js").LocalizationMap | null;
177
- description: string;
178
- description_localizations?: import("discord.js").LocalizationMap | null;
179
- required?: boolean;
180
- }[];
181
- options?: import("discord.js").APIApplicationCommandSubcommandOption[];
182
- type: import("discord.js").ApplicationCommandOptionType.SubcommandGroup;
183
- name_localizations?: import("discord.js").LocalizationMap | null;
184
- description: string;
185
- description_localizations?: import("discord.js").LocalizationMap | null;
186
- required?: boolean;
187
- } | {
188
- subcommands: ({
189
- name: string;
190
- subcommands: never[];
191
- options?: import("discord.js").APIApplicationCommandBasicOption[];
192
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
193
- name_localizations?: import("discord.js").LocalizationMap | null;
194
- description: string;
195
- description_localizations?: import("discord.js").LocalizationMap | null;
196
- required?: boolean;
197
- } | {
198
- name: string;
199
- subcommands: {
200
- name: string;
201
- subcommands: never[];
202
- options?: import("discord.js").APIApplicationCommandBasicOption[];
203
- type: import("discord.js").ApplicationCommandOptionType.Subcommand;
204
- name_localizations?: import("discord.js").LocalizationMap | null;
205
- description: string;
206
- description_localizations?: import("discord.js").LocalizationMap | null;
207
- required?: boolean;
208
- }[];
209
- options?: import("discord.js").APIApplicationCommandSubcommandOption[];
210
- type: import("discord.js").ApplicationCommandOptionType.SubcommandGroup;
211
- name_localizations?: import("discord.js").LocalizationMap | null;
212
- description: string;
213
- description_localizations?: import("discord.js").LocalizationMap | null;
214
- required?: boolean;
215
- })[];
216
- id: import("discord.js").Snowflake;
217
- type: import("discord.js").ApplicationCommandType;
218
- application_id: import("discord.js").Snowflake;
219
- guild_id?: import("discord.js").Snowflake;
220
- name: string;
221
- name_localizations?: import("discord.js").LocalizationMap | null;
222
- name_localized?: string;
223
- description: string;
224
- description_localizations?: import("discord.js").LocalizationMap | null;
225
- description_localized?: string;
226
- options?: import("discord.js").APIApplicationCommandOption[];
227
- default_member_permissions: import("discord.js").Permissions | null;
228
- dm_permission?: boolean;
229
- default_permission?: boolean;
230
- nsfw?: boolean;
231
- integration_types?: import("discord.js").ApplicationIntegrationType[];
232
- contexts?: import("discord.js").InteractionContextType[] | null;
233
- version: import("discord.js").Snowflake;
234
- handler?: import("discord.js").EntryPointCommandHandlerType;
235
- };
236
- }[];
237
- conflict: (import("../../../../../types.js").SlashCommandRuntime | import("../../../../../types.js").SlashCommandSubcommandRuntime | import("../../../../../types.js").SlashCommandSubcommandGroupRuntime)[];
238
- }>>;
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<import("../../../../registration.js").RegistrationDiff>>;
239
2
  export default _default;
@@ -2,7 +2,9 @@ import { defineEventHandler, readBody } from "h3";
2
2
  import { useDiscordClient } from "../../../utils/useDiscordClient.js";
3
3
  export default defineEventHandler(async (event) => {
4
4
  const client = useDiscordClient();
5
- const body = await readBody(event);
5
+ if (!import.meta.dev)
6
+ return client.diffRemoteSlashCommands();
7
+ const body = await readBody(event) ?? {};
6
8
  const diff = await client.diffRemoteSlashCommands(body?.commands);
7
9
  return diff;
8
10
  });