nuxt-discord 0.1.0 → 0.2.1
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/dist/module.d.mts +41 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +131 -11
- package/dist/runtime/acknowledgement.d.ts +2 -1
- package/dist/runtime/acknowledgement.js +44 -12
- package/dist/runtime/client/components/CommandCard.d.ts +29 -0
- package/dist/runtime/client/components/CommandCard.js +75 -0
- package/dist/runtime/client/components/CommandReference.d.vue.ts +20 -0
- package/dist/runtime/client/components/CommandReference.vue +21 -0
- package/dist/runtime/client/components/CommandReference.vue.d.ts +20 -0
- package/dist/runtime/client/components/CommandTestBar.vue +0 -3
- package/dist/runtime/client/components/CommandsHeading.d.ts +24 -0
- package/dist/runtime/client/components/CommandsHeading.js +17 -0
- package/dist/runtime/client/components/DashboardHeader.d.ts +32 -0
- package/dist/runtime/client/components/DashboardHeader.js +32 -0
- package/dist/runtime/client/components/ProjectLogo.d.ts +4 -0
- package/dist/runtime/client/components/ProjectLogo.js +31 -0
- package/dist/runtime/client/components/ReferenceContent.d.ts +22 -0
- package/dist/runtime/client/components/ReferenceContent.js +45 -0
- package/dist/runtime/client/components/TheHeader.vue +33 -52
- package/dist/runtime/client/components/appearance-select.d.ts +1 -1
- package/dist/runtime/client/components/appearance-select.js +1 -1
- package/dist/runtime/client/pages/slash-commands.vue +28 -110
- package/dist/runtime/client/reference.css +133 -0
- package/dist/runtime/client/useDiscordCommandReference.d.ts +2 -0
- package/dist/runtime/client/useDiscordCommandReference.js +6 -0
- package/dist/runtime/dashboard/auth.js +10 -17
- package/dist/runtime/dashboard/oauth.d.ts +15 -1
- package/dist/runtime/dashboard/oauth.js +42 -21
- package/dist/runtime/dashboard/origin.d.ts +2 -0
- package/dist/runtime/dashboard/origin.js +8 -0
- package/dist/runtime/dashboard/signin.d.ts +2 -1
- package/dist/runtime/dashboard/signin.js +7 -2
- package/dist/runtime/dashboard/urls.d.ts +2 -0
- package/dist/runtime/dashboard/urls.js +8 -0
- package/dist/runtime/reference/access.d.ts +6 -0
- package/dist/runtime/reference/access.js +144 -0
- package/dist/runtime/reference/catalog.d.ts +2 -0
- package/dist/runtime/reference/catalog.js +9 -0
- package/dist/runtime/reference/document.d.ts +2 -0
- package/dist/runtime/reference/document.js +25 -0
- package/dist/runtime/reference/hosted.d.ts +2 -0
- package/dist/runtime/reference/hosted.js +16 -0
- package/dist/runtime/reference/oauth.d.ts +2 -0
- package/dist/runtime/reference/oauth.js +4 -0
- package/dist/runtime/server/plugins/discord.js +2 -0
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/dist/runtime/client/components/ProjectLogo.d.vue.ts +0 -3
- package/dist/runtime/client/components/ProjectLogo.vue +0 -31
- package/dist/runtime/client/components/ProjectLogo.vue.d.ts +0 -3
package/dist/module.d.mts
CHANGED
|
@@ -47,6 +47,8 @@ interface NuxtDiscordOptions {
|
|
|
47
47
|
autoStart: boolean;
|
|
48
48
|
/** Build the authenticated dashboard into the production Node server. */
|
|
49
49
|
dashboard?: boolean;
|
|
50
|
+
/** Publish the generated command reference. Disabled by default. */
|
|
51
|
+
reference?: false | DiscordReferenceOptions;
|
|
50
52
|
/**
|
|
51
53
|
* Timeout in milliseconds before an interaction's reactive scope is disposed.
|
|
52
54
|
* This cleans up watchers (reactive replies) and component collectors (buttons).
|
|
@@ -174,6 +176,7 @@ interface SlashCommand {
|
|
|
174
176
|
nsfw?: boolean;
|
|
175
177
|
/** Middleware names from @middleware JSDoc tags */
|
|
176
178
|
middleware?: string[];
|
|
179
|
+
hasRuntimeMiddleware?: boolean;
|
|
177
180
|
/** Interaction contexts where this command is available (Guild=0, BotDM=1, PrivateChannel=2) */
|
|
178
181
|
contexts?: number[];
|
|
179
182
|
defaultMemberPermissions?: string | null;
|
|
@@ -233,8 +236,45 @@ interface ContextMenu {
|
|
|
233
236
|
guilds?: true | string[];
|
|
234
237
|
/** Middleware names from @middleware JSDoc tags */
|
|
235
238
|
middleware?: string[];
|
|
239
|
+
hasRuntimeMiddleware?: boolean;
|
|
236
240
|
nameLocalizations?: LocalizationMap;
|
|
237
241
|
}
|
|
242
|
+
type DiscordReferenceOptions = {
|
|
243
|
+
page?: boolean;
|
|
244
|
+
/** Origin of a separately hosted administrative dashboard, including an HTTP loopback tunnel. */
|
|
245
|
+
dashboardOrigin?: string;
|
|
246
|
+
} & ({
|
|
247
|
+
access: 'public' | 'private' | 'authenticated';
|
|
248
|
+
} | {
|
|
249
|
+
access: 'members';
|
|
250
|
+
guilds?: string[];
|
|
251
|
+
});
|
|
252
|
+
interface DiscordReferenceOption {
|
|
253
|
+
name: string;
|
|
254
|
+
description: string;
|
|
255
|
+
type: 'string' | 'integer' | 'number' | 'boolean' | 'user' | 'channel' | 'role' | 'mentionable' | 'attachment';
|
|
256
|
+
required: boolean;
|
|
257
|
+
hasAutocomplete: boolean;
|
|
258
|
+
choices?: {
|
|
259
|
+
name: string;
|
|
260
|
+
value: string | number;
|
|
261
|
+
}[];
|
|
262
|
+
min?: number;
|
|
263
|
+
max?: number;
|
|
264
|
+
minLength?: number;
|
|
265
|
+
maxLength?: number;
|
|
266
|
+
}
|
|
267
|
+
interface DiscordCommandReference {
|
|
268
|
+
commands: {
|
|
269
|
+
name: string;
|
|
270
|
+
description: string;
|
|
271
|
+
options: DiscordReferenceOption[];
|
|
272
|
+
}[];
|
|
273
|
+
menus: {
|
|
274
|
+
name: string;
|
|
275
|
+
type: 'user' | 'message';
|
|
276
|
+
}[];
|
|
277
|
+
}
|
|
238
278
|
interface DashboardCatalog {
|
|
239
279
|
commands: SlashCommand[];
|
|
240
280
|
menus: ContextMenu[];
|
|
@@ -256,4 +296,4 @@ interface NuxtDiscordContext {
|
|
|
256
296
|
declare const _default: _nuxt_schema.NuxtModule<NuxtDiscordOptions, NuxtDiscordOptions, false>;
|
|
257
297
|
|
|
258
298
|
export { _default as default, slashCommandOptionTypeIdentifiers, typeIdentifierToEnum };
|
|
259
|
-
export type { ContextMenu, DashboardCatalog, DiscordRuntimeConfig, Listener, Mentionable, MiddlewareEntry, NuxtDiscordContext, NuxtDiscordOptions, SlashCommand, SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandChannelOption, SlashCommandCustomReturnHandler, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandOption, SlashCommandOptionBase, SlashCommandOptionType, SlashCommandOptionTypeIdentifier, SlashCommandReturnType, SlashCommandRoleOption, SlashCommandRuntime, SlashCommandStringOption, SlashCommandSubcommand, SlashCommandSubcommandGroup, SlashCommandSubcommandGroupRuntime, SlashCommandSubcommandRuntime, SlashCommandUserOption, integer };
|
|
299
|
+
export type { ContextMenu, DashboardCatalog, DiscordCommandReference, DiscordReferenceOption, DiscordReferenceOptions, DiscordRuntimeConfig, Listener, Mentionable, MiddlewareEntry, NuxtDiscordContext, NuxtDiscordOptions, SlashCommand, SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandChannelOption, SlashCommandCustomReturnHandler, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandOption, SlashCommandOptionBase, SlashCommandOptionType, SlashCommandOptionTypeIdentifier, SlashCommandReturnType, SlashCommandRoleOption, SlashCommandRuntime, SlashCommandStringOption, SlashCommandSubcommand, SlashCommandSubcommandGroup, SlashCommandSubcommandGroupRuntime, SlashCommandSubcommandRuntime, SlashCommandUserOption, integer };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs, { globSync, readFileSync, writeFileSync, renameSync } from 'node:fs';
|
|
2
|
+
import path, { relative, sep, join } from 'node:path';
|
|
3
|
+
import { createResolver, extendPages, addServerTemplate, addTemplate, addTypeTemplate, updateTemplates, isIgnored, defineNuxtModule, addImports, addComponent, addServerHandler, extendRouteRules, addServerScanDir, addServerPlugin, addServerImportsDir, loadNuxtModuleInstance } from '@nuxt/kit';
|
|
2
4
|
import { ApplicationCommandOptionType, Locale, GatewayIntentBits } from 'discord.js';
|
|
3
5
|
import { logger } from '../dist/runtime/logger.js';
|
|
4
|
-
import fs, { globSync, readFileSync } from 'node:fs';
|
|
5
|
-
import path, { relative, sep } from 'node:path';
|
|
6
6
|
import ts from 'typescript';
|
|
7
7
|
import '../dist/runtime/server/utils/defineMiddleware.js';
|
|
8
8
|
import { resolveMiddlewareTags } from '../dist/runtime/middleware.js';
|
|
9
|
-
import { rm } from 'node:fs/promises';
|
|
9
|
+
import { rm, mkdir } from 'node:fs/promises';
|
|
10
10
|
import { pathToFileURL } from 'node:url';
|
|
11
11
|
import chokidar from 'chokidar';
|
|
12
12
|
import { listen } from 'listhen';
|
|
13
13
|
import { rollup } from 'rollup';
|
|
14
14
|
import { WebSocketServer } from 'ws';
|
|
15
|
+
import { configuredOrigin, dashboardCommandsPath } from '../dist/runtime/dashboard/urls.js';
|
|
15
16
|
import { genSafeVariableName, genImport, genString, genArrayFromRaw } from 'knitwork';
|
|
16
17
|
|
|
17
18
|
function createContext(options, nuxt) {
|
|
@@ -35,13 +36,11 @@ function prepareClient(ctx) {
|
|
|
35
36
|
"lucide:blocks",
|
|
36
37
|
"lucide:circle-x",
|
|
37
38
|
"lucide:eye",
|
|
38
|
-
"lucide:gift",
|
|
39
39
|
"lucide:pin",
|
|
40
40
|
"lucide:plus",
|
|
41
41
|
"lucide:send-horizontal",
|
|
42
42
|
"lucide:shapes",
|
|
43
43
|
"lucide:smile",
|
|
44
|
-
"lucide:sticker",
|
|
45
44
|
"simple-icons:discord",
|
|
46
45
|
"simple-icons:github"
|
|
47
46
|
]) icons.add(name);
|
|
@@ -166,6 +165,7 @@ const macros = {
|
|
|
166
165
|
}
|
|
167
166
|
},
|
|
168
167
|
useMiddleware(_ctx, _node, command) {
|
|
168
|
+
command.hasRuntimeMiddleware = true;
|
|
169
169
|
command.middleware ??= [];
|
|
170
170
|
}
|
|
171
171
|
};
|
|
@@ -632,6 +632,7 @@ function processContextMenuFile(ctx, file) {
|
|
|
632
632
|
const sourceFile = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true);
|
|
633
633
|
let type;
|
|
634
634
|
let nameFromDefine;
|
|
635
|
+
let hasRuntimeMiddleware = false;
|
|
635
636
|
ts.forEachChild(sourceFile, (node) => {
|
|
636
637
|
if (ts.isExportAssignment(node) && ts.isCallExpression(node.expression)) {
|
|
637
638
|
const call = node.expression;
|
|
@@ -643,6 +644,7 @@ function processContextMenuFile(ctx, file) {
|
|
|
643
644
|
type = "message";
|
|
644
645
|
}
|
|
645
646
|
if (type && call.arguments.length > 0) {
|
|
647
|
+
hasRuntimeMiddleware = call.arguments.length >= 3;
|
|
646
648
|
const firstArg = call.arguments[0];
|
|
647
649
|
if (ts.isStringLiteral(firstArg)) {
|
|
648
650
|
nameFromDefine = firstArg.text;
|
|
@@ -668,7 +670,7 @@ function processContextMenuFile(ctx, file) {
|
|
|
668
670
|
const middleware = readMiddlewareTags(sourceFile);
|
|
669
671
|
const definition = sourceFile.statements.find(ts.isExportAssignment);
|
|
670
672
|
const guilds = readGuildTags(ts.getJSDocTags(definition));
|
|
671
|
-
return { name, type, path: file, ...guilds && { guilds }, ...middleware.length > 0 ? { middleware } : {} };
|
|
673
|
+
return { name, type, path: file, ...hasRuntimeMiddleware ? { hasRuntimeMiddleware: true } : {}, ...guilds && { guilds }, ...middleware.length > 0 ? { middleware } : {} };
|
|
672
674
|
}
|
|
673
675
|
function getJSDocTag(sourceFile, tagName) {
|
|
674
676
|
let result;
|
|
@@ -815,6 +817,67 @@ function reuseCommandDependencies(entries, updated, changed) {
|
|
|
815
817
|
};
|
|
816
818
|
}
|
|
817
819
|
|
|
820
|
+
function resolveReference(options) {
|
|
821
|
+
if (options === void 0 || options === false)
|
|
822
|
+
return;
|
|
823
|
+
if (!options || !["public", "private", "authenticated", "members"].includes(options.access) || options.page !== void 0 && typeof options.page !== "boolean") {
|
|
824
|
+
throw new Error("discord.reference requires a valid access mode and an optional boolean page setting.");
|
|
825
|
+
}
|
|
826
|
+
if (Object.keys(options).some((key) => !["access", "page", "guilds", "dashboardOrigin"].includes(key)))
|
|
827
|
+
throw new Error("discord.reference accepts access, page, guilds and dashboardOrigin.");
|
|
828
|
+
const { dashboardOrigin } = options;
|
|
829
|
+
if (dashboardOrigin !== void 0 && (typeof dashboardOrigin !== "string" || !configuredOrigin(dashboardOrigin)))
|
|
830
|
+
throw new Error("discord.reference.dashboardOrigin must be an HTTPS origin or an HTTP loopback origin, with no path or trailing slash.");
|
|
831
|
+
const policy = { access: options.access, page: options.page ?? true, ...dashboardOrigin && { dashboardOrigin } };
|
|
832
|
+
if (options.access === "members") {
|
|
833
|
+
if (options.guilds === void 0)
|
|
834
|
+
return policy;
|
|
835
|
+
if (!Array.isArray(options.guilds) || !options.guilds.length || options.guilds.some((id) => typeof id !== "string" || !/^[1-9]\d{0,19}$/.test(id)))
|
|
836
|
+
throw new Error("discord.reference.guilds requires Discord server IDs for members access.");
|
|
837
|
+
return { ...policy, guilds: [...new Set(options.guilds)] };
|
|
838
|
+
}
|
|
839
|
+
if ("guilds" in options)
|
|
840
|
+
throw new Error("discord.reference.guilds is used only with members access.");
|
|
841
|
+
return policy;
|
|
842
|
+
}
|
|
843
|
+
function referenceDashboardHref(options, hostedDashboard) {
|
|
844
|
+
if (options.dashboardOrigin)
|
|
845
|
+
return new URL(dashboardCommandsPath, options.dashboardOrigin).href;
|
|
846
|
+
return hostedDashboard ? dashboardCommandsPath : void 0;
|
|
847
|
+
}
|
|
848
|
+
function restricted(item) {
|
|
849
|
+
return Boolean(item.guilds || item.hasRuntimeMiddleware || item.middleware?.some((name) => name !== "cooldown" && name !== "guildOnly") || "nsfw" in item && item.nsfw || "defaultMemberPermissions" in item && item.defaultMemberPermissions != null);
|
|
850
|
+
}
|
|
851
|
+
function projectOption(option) {
|
|
852
|
+
const type = ApplicationCommandOptionType[option.type].toLowerCase();
|
|
853
|
+
return {
|
|
854
|
+
name: option.name,
|
|
855
|
+
description: option.description,
|
|
856
|
+
type,
|
|
857
|
+
required: option.required,
|
|
858
|
+
hasAutocomplete: option.hasAutocomplete,
|
|
859
|
+
..."min" in option && { min: option.min },
|
|
860
|
+
..."max" in option && { max: option.max },
|
|
861
|
+
..."minLength" in option && { minLength: option.minLength },
|
|
862
|
+
..."maxLength" in option && { maxLength: option.maxLength },
|
|
863
|
+
..."choices" in option && { choices: option.choices?.map(({ name, value }) => ({ name, value })) }
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
function projectReference(commands, menus, access) {
|
|
867
|
+
function leaves(tree, prefix = "") {
|
|
868
|
+
return tree.flatMap((command) => {
|
|
869
|
+
if (access !== "private" && restricted(command))
|
|
870
|
+
return [];
|
|
871
|
+
const name = prefix + command.name;
|
|
872
|
+
return command.subcommands.length ? leaves(command.subcommands, `${name} `) : [{ name, description: command.description, options: command.options.map(projectOption) }];
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
return {
|
|
876
|
+
commands: leaves(commands).sort((a, b) => a.name.localeCompare(b.name)),
|
|
877
|
+
menus: menus.filter((menu) => access === "private" || !restricted(menu)).map(({ name, type }) => ({ name, type })).sort((a, b) => a.name.localeCompare(b.name))
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
|
|
818
881
|
function prepareTemplates(ctx) {
|
|
819
882
|
addServerTemplate({
|
|
820
883
|
filename: "discord/catalog",
|
|
@@ -898,6 +961,12 @@ function prepareTemplates(ctx) {
|
|
|
898
961
|
addTypeTemplate({
|
|
899
962
|
filename: "discord/types.d.ts",
|
|
900
963
|
getContents: () => `
|
|
964
|
+
declare module 'discord/reference' {
|
|
965
|
+
export function getCatalog(): import('nuxt-discord').DiscordCommandReference | Promise<import('nuxt-discord').DiscordCommandReference>
|
|
966
|
+
export const policy: import('nuxt-discord').DiscordReferenceOptions
|
|
967
|
+
export const dashboardHref: string | undefined
|
|
968
|
+
export const styles: string
|
|
969
|
+
}
|
|
901
970
|
declare module 'discord/catalog' {
|
|
902
971
|
const catalog: import('nuxt-discord').DashboardCatalog
|
|
903
972
|
export default catalog
|
|
@@ -1061,10 +1130,11 @@ function createRuntimeExport(handler, originalBody) {
|
|
|
1061
1130
|
);
|
|
1062
1131
|
}
|
|
1063
1132
|
|
|
1064
|
-
function prepareHMR(ctx) {
|
|
1133
|
+
function prepareHMR(ctx, liveReferenceFile) {
|
|
1065
1134
|
const { nuxt, options } = ctx;
|
|
1066
1135
|
const watching = nuxt.options.dev && options.watch.enabled;
|
|
1067
1136
|
const commandsDir = ctx.resolve.root(options.dir, "commands") + path.sep;
|
|
1137
|
+
const commandIdPrefix = commandsDir.split(path.sep).join("/");
|
|
1068
1138
|
const hotDir = path.join(nuxt.options.buildDir, "discord", "hmr");
|
|
1069
1139
|
let dependencies = /* @__PURE__ */ new Set();
|
|
1070
1140
|
const updated = /* @__PURE__ */ new Map();
|
|
@@ -1085,6 +1155,13 @@ function prepareHMR(ctx) {
|
|
|
1085
1155
|
});
|
|
1086
1156
|
});
|
|
1087
1157
|
if (watching) {
|
|
1158
|
+
let publishReference = function(snapshot) {
|
|
1159
|
+
if (liveReferenceFile && options.reference) {
|
|
1160
|
+
const catalog = projectReference(snapshot.slashCommands, snapshot.contextMenus, options.reference.access);
|
|
1161
|
+
writeFileSync(`${liveReferenceFile}.tmp`, JSON.stringify(catalog));
|
|
1162
|
+
renameSync(`${liveReferenceFile}.tmp`, liveReferenceFile);
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1088
1165
|
const ignoreCommandsDir = (file) => {
|
|
1089
1166
|
if (file === commandsDir.slice(0, -1) || file.startsWith(commandsDir)) {
|
|
1090
1167
|
return true;
|
|
@@ -1121,6 +1198,10 @@ function prepareHMR(ctx) {
|
|
|
1121
1198
|
nuxt.hook("nitro:init", async (nitro) => {
|
|
1122
1199
|
websocket = createWebSocket();
|
|
1123
1200
|
await rm(hotDir, { recursive: true, force: true });
|
|
1201
|
+
if (liveReferenceFile) {
|
|
1202
|
+
await mkdir(hotDir, { recursive: true });
|
|
1203
|
+
publishReference(ctx);
|
|
1204
|
+
}
|
|
1124
1205
|
listener = await listen(() => "Nuxt Discord", websocketOptions);
|
|
1125
1206
|
nitro.options.runtimeConfig.public.discord = {
|
|
1126
1207
|
wsUrl: listener.url.replace("http", "ws")
|
|
@@ -1169,6 +1250,14 @@ function prepareHMR(ctx) {
|
|
|
1169
1250
|
const outputDir = path.join(hotDir, String(version));
|
|
1170
1251
|
try {
|
|
1171
1252
|
const snapshot = { ...ctx };
|
|
1253
|
+
if (liveReferenceFile) {
|
|
1254
|
+
collectContextMenus(snapshot);
|
|
1255
|
+
if (![...changed].some((file) => file.startsWith(commandIdPrefix))) {
|
|
1256
|
+
publishReference(snapshot);
|
|
1257
|
+
ctx.contextMenus = snapshot.contextMenus;
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1172
1261
|
collectSlashCommands(snapshot, changed);
|
|
1173
1262
|
const source = getSlashCommandTemplateContent(snapshot, true);
|
|
1174
1263
|
const additions = await buildCommandUpdate(rollupConfig, source, outputDir, initial, updated, changed);
|
|
@@ -1176,6 +1265,10 @@ function prepareHMR(ctx) {
|
|
|
1176
1265
|
changed.forEach((file) => dirty.add(file));
|
|
1177
1266
|
continue;
|
|
1178
1267
|
}
|
|
1268
|
+
if (liveReferenceFile) {
|
|
1269
|
+
publishReference(snapshot);
|
|
1270
|
+
ctx.contextMenus = snapshot.contextMenus;
|
|
1271
|
+
}
|
|
1179
1272
|
ctx.slashCommands = snapshot.slashCommands;
|
|
1180
1273
|
for (const id of changed)
|
|
1181
1274
|
updated.delete(id);
|
|
@@ -1196,7 +1289,8 @@ function prepareHMR(ctx) {
|
|
|
1196
1289
|
building = false;
|
|
1197
1290
|
}
|
|
1198
1291
|
}
|
|
1199
|
-
const
|
|
1292
|
+
const watched = liveReferenceFile ? [commandsDir, ctx.resolve.root(options.dir, "context-menus")] : [commandsDir];
|
|
1293
|
+
const watcher = chokidar.watch(watched, { ignoreInitial: true }).on("all", (event, file) => {
|
|
1200
1294
|
if (["add", "change", "unlink"].includes(event) && file.endsWith(".ts")) {
|
|
1201
1295
|
const id = path.resolve(file).split(path.sep).join("/");
|
|
1202
1296
|
dirty.add(id);
|
|
@@ -1349,8 +1443,34 @@ const module$1 = defineNuxtModule({
|
|
|
1349
1443
|
const ctx = createContext(discordOptions, nuxt);
|
|
1350
1444
|
const development = nuxt.options.dev || nuxt.options._prepare;
|
|
1351
1445
|
const hostedDashboard = !development && discordOptions.dashboard === true;
|
|
1446
|
+
const reference = resolveReference(discordOptions.reference);
|
|
1447
|
+
const liveReferenceFile = reference && nuxt.options.dev && discordOptions.watch.enabled ? join(nuxt.options.buildDir, "discord", "hmr", "reference.json") : void 0;
|
|
1448
|
+
if (reference) {
|
|
1449
|
+
addImports({ name: "useDiscordCommandReference", from: ctx.resolve.module("runtime/client/useDiscordCommandReference") });
|
|
1450
|
+
addComponent({ name: "DiscordCommandReference", filePath: ctx.resolve.module("runtime/client/components/CommandReference.vue") });
|
|
1451
|
+
addServerTemplate({
|
|
1452
|
+
filename: "discord/reference",
|
|
1453
|
+
getContents: () => [
|
|
1454
|
+
liveReferenceFile ? `import { readFile } from 'node:fs/promises'; export async function getCatalog() { return JSON.parse(await readFile(${JSON.stringify(liveReferenceFile)}, 'utf8')) }` : `const catalog = ${JSON.stringify(projectReference(ctx.slashCommands, ctx.contextMenus, reference.access))}; export const getCatalog = () => catalog`,
|
|
1455
|
+
`export const policy = ${JSON.stringify(reference)}`,
|
|
1456
|
+
`export const dashboardHref = ${JSON.stringify(referenceDashboardHref(reference, hostedDashboard))}`,
|
|
1457
|
+
`export const styles = ${JSON.stringify(readFileSync(ctx.resolve.module("runtime/client/reference.css"), "utf8"))}`
|
|
1458
|
+
].join("\n")
|
|
1459
|
+
});
|
|
1460
|
+
const routes = [{ route: "/api/discord/reference", handler: "catalog" }];
|
|
1461
|
+
if (reference.page)
|
|
1462
|
+
routes.push({ route: "/commands", handler: "document" });
|
|
1463
|
+
if (reference.access !== "public") {
|
|
1464
|
+
for (const action of ["login", "callback", "logout"])
|
|
1465
|
+
routes.push({ route: `/__discord-reference/${action}`, handler: "oauth" });
|
|
1466
|
+
}
|
|
1467
|
+
for (const { route, handler } of routes) {
|
|
1468
|
+
addServerHandler({ route, method: route.endsWith("/logout") ? "post" : "get", handler: ctx.resolve.module(`runtime/reference/${handler}`) });
|
|
1469
|
+
extendRouteRules(route, { prerender: false, cache: false, isr: false, swr: false }, { override: true });
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1352
1472
|
if (hostedDashboard) {
|
|
1353
|
-
addServerHandler({ middleware: true, handler: ctx.resolve.module("runtime/dashboard/auth") });
|
|
1473
|
+
addServerHandler({ middleware: true, handler: ctx.resolve.module(reference ? "runtime/reference/hosted" : "runtime/dashboard/auth") });
|
|
1354
1474
|
for (const route of ["/discord", "/discord/**", "/api/discord", "/api/discord/**"])
|
|
1355
1475
|
extendRouteRules(route, { prerender: false, cache: false }, { override: true });
|
|
1356
1476
|
for (const [path, method] of [
|
|
@@ -1460,7 +1580,7 @@ const module$1 = defineNuxtModule({
|
|
|
1460
1580
|
collectContextMenus(ctx);
|
|
1461
1581
|
collectListeners(ctx);
|
|
1462
1582
|
prepareTemplates(ctx);
|
|
1463
|
-
prepareHMR(ctx);
|
|
1583
|
+
prepareHMR(ctx, liveReferenceFile);
|
|
1464
1584
|
}
|
|
1465
1585
|
});
|
|
1466
1586
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { CommandInteraction, InteractionReplyOptions, MessageCreateOptions, ModalSubmitInteraction } from 'discord.js';
|
|
2
2
|
import type { MessageSenderConfig, SentMessage } from './server/utils/messageSender.js';
|
|
3
|
+
import { MessagePayload } from 'discord.js';
|
|
3
4
|
type ReplyInteraction = CommandInteraction | ModalSubmitInteraction;
|
|
4
5
|
export type DeferPolicy = 'public' | 'private' | 'manual';
|
|
5
6
|
export declare function scheduleAcknowledgement(interaction: ReplyInteraction, policy?: DeferPolicy, allowTimer?: boolean): () => void;
|
|
6
7
|
export declare function wasAutomaticallyDeferred(interaction: ReplyInteraction): boolean;
|
|
7
|
-
export declare function interactionSender(interaction: ReplyInteraction): Omit<MessageSenderConfig, 'send'> & {
|
|
8
|
+
export declare function interactionSender(interaction: ReplyInteraction, source?: MessagePayload): Omit<MessageSenderConfig, 'send'> & {
|
|
8
9
|
send: (opts: InteractionReplyOptions | MessageCreateOptions) => Promise<SentMessage>;
|
|
9
10
|
};
|
|
10
11
|
export {};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { MessageFlags, MessageFlagsBitField, MessagePayload } from "discord.js";
|
|
2
2
|
import { logDiscordFailure } from "./diagnostics.js";
|
|
3
|
-
const
|
|
3
|
+
const policies = /* @__PURE__ */ new WeakMap();
|
|
4
4
|
const automatic = /* @__PURE__ */ new WeakMap();
|
|
5
5
|
export function scheduleAcknowledgement(interaction, policy, allowTimer = true) {
|
|
6
|
+
if (policy)
|
|
7
|
+
policies.set(interaction, policy);
|
|
6
8
|
if (policy === "manual")
|
|
7
9
|
return () => {
|
|
8
10
|
};
|
|
9
|
-
if (policy === "private")
|
|
10
|
-
privateByDefault.add(interaction);
|
|
11
11
|
const elapsed = Date.now() - (interaction.createdTimestamp ?? Date.now());
|
|
12
12
|
const originalDefer = interaction.deferReply;
|
|
13
13
|
const restoreMethods = [];
|
|
@@ -35,13 +35,18 @@ export function scheduleAcknowledgement(interaction, policy, allowTimer = true)
|
|
|
35
35
|
value(...args) {
|
|
36
36
|
cancel();
|
|
37
37
|
const ack = automatic.get(this);
|
|
38
|
-
if (method === "reply"
|
|
38
|
+
if (method === "reply") {
|
|
39
39
|
const payload = args[0];
|
|
40
40
|
const options = typeof payload === "string" ? { content: payload } : payload instanceof MessagePayload ? payload.options : payload;
|
|
41
|
-
const opts = options;
|
|
41
|
+
const opts = policy === "private" ? withPrivateFlag(options) : options;
|
|
42
|
+
const source = payload instanceof MessagePayload ? payload : void 0;
|
|
42
43
|
if (ack)
|
|
43
|
-
return interactionSender(this).send(opts);
|
|
44
|
-
|
|
44
|
+
return interactionSender(this, source).send(opts);
|
|
45
|
+
if (!this.deferred && !this.replied && canDeferFiles(opts)) {
|
|
46
|
+
return sendInitialFiles(this, opts, source).then(({ response, message }) => opts.fetchReply ? message : response);
|
|
47
|
+
}
|
|
48
|
+
if (policy === "private")
|
|
49
|
+
return Reflect.apply(original, this, [opts]);
|
|
45
50
|
}
|
|
46
51
|
if (method === "deferReply") {
|
|
47
52
|
const opts = args[0] ?? {};
|
|
@@ -84,33 +89,60 @@ function editOptions(options) {
|
|
|
84
89
|
const writable = bits & (MessageFlags.SuppressEmbeds | MessageFlags.IsComponentsV2);
|
|
85
90
|
return { ...editable, flags: writable };
|
|
86
91
|
}
|
|
92
|
+
function canDeferFiles(opts) {
|
|
93
|
+
return opts.files?.length && !opts.withResponse && !opts.tts && !new MessageFlagsBitField(opts.flags).any(MessageFlags.SuppressNotifications | MessageFlags.IsVoiceMessage);
|
|
94
|
+
}
|
|
95
|
+
function withResolvedFiles(interaction, opts, source) {
|
|
96
|
+
if (!source?.files && !source?.body)
|
|
97
|
+
return opts;
|
|
98
|
+
const payload = MessagePayload.create(interaction.webhook, opts);
|
|
99
|
+
payload.files = source.files;
|
|
100
|
+
if (source.body) {
|
|
101
|
+
payload.body = {
|
|
102
|
+
...source.body,
|
|
103
|
+
flags: opts.flags == null ? void 0 : new MessageFlagsBitField(opts.flags).bitfield,
|
|
104
|
+
tts: "tts" in opts ? opts.tts : void 0
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return payload;
|
|
108
|
+
}
|
|
109
|
+
async function sendInitialFiles(interaction, opts, source) {
|
|
110
|
+
const response = await interaction.deferReply(isPrivate(opts) ? { flags: MessageFlags.Ephemeral } : {});
|
|
111
|
+
const message = await interaction.editReply(withResolvedFiles(interaction, editOptions(opts), source));
|
|
112
|
+
return { response, message };
|
|
113
|
+
}
|
|
87
114
|
export function wasAutomaticallyDeferred(interaction) {
|
|
88
115
|
return automatic.has(interaction);
|
|
89
116
|
}
|
|
90
|
-
export function interactionSender(interaction) {
|
|
117
|
+
export function interactionSender(interaction, source) {
|
|
91
118
|
let method;
|
|
92
119
|
return {
|
|
93
120
|
async send(options) {
|
|
94
121
|
let opts = options;
|
|
95
|
-
|
|
122
|
+
const policy = policies.get(interaction);
|
|
123
|
+
if (!interaction.replied && policy === "private" && !isPrivate(opts))
|
|
96
124
|
opts = withPrivateFlag(opts);
|
|
97
125
|
const ack = automatic.get(interaction);
|
|
98
126
|
if (ack)
|
|
99
127
|
await ack.pending;
|
|
100
128
|
method = interaction.replied ? "followUp" : interaction.deferred ? "editReply" : "reply";
|
|
129
|
+
if (method === "reply" && policy !== "manual" && canDeferFiles(opts)) {
|
|
130
|
+
method = "editReply";
|
|
131
|
+
return (await sendInitialFiles(interaction, opts)).message;
|
|
132
|
+
}
|
|
101
133
|
if (method === "editReply") {
|
|
102
134
|
const explicitlyPrivate = isPrivate(opts);
|
|
103
135
|
const originalPrivate = ack ? ack.policy !== "public" : interaction.ephemeral;
|
|
104
136
|
if (explicitlyPrivate && originalPrivate === false || ack && explicitlyPrivate !== originalPrivate) {
|
|
105
137
|
await interaction.editReply({ content: "Preparing reply\u2026" });
|
|
106
138
|
method = "followUp";
|
|
107
|
-
const message = await interaction.followUp(opts);
|
|
139
|
+
const message = await interaction.followUp(withResolvedFiles(interaction, opts, source));
|
|
108
140
|
await interaction.deleteReply().catch((error) => logDiscordFailure("Could not remove acknowledgement:", error));
|
|
109
141
|
return message;
|
|
110
142
|
}
|
|
111
|
-
return interaction.editReply(editOptions(opts));
|
|
143
|
+
return interaction.editReply(withResolvedFiles(interaction, editOptions(opts), source));
|
|
112
144
|
}
|
|
113
|
-
return interaction[method](opts);
|
|
145
|
+
return interaction[method](withResolvedFiles(interaction, opts, source));
|
|
114
146
|
},
|
|
115
147
|
edit(msg, options) {
|
|
116
148
|
const opts = editOptions(options);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PropType } from 'vue';
|
|
2
|
+
import type { DiscordReferenceOption } from '../../../types.js';
|
|
3
|
+
type Option = Omit<DiscordReferenceOption, 'type'> & {
|
|
4
|
+
type: number | DiscordReferenceOption['type'];
|
|
5
|
+
};
|
|
6
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
7
|
+
command: {
|
|
8
|
+
type: PropType<{
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
options: Option[];
|
|
12
|
+
}>;
|
|
13
|
+
required: true;
|
|
14
|
+
};
|
|
15
|
+
anchor: StringConstructor;
|
|
16
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
19
|
+
command: {
|
|
20
|
+
type: PropType<{
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
options: Option[];
|
|
24
|
+
}>;
|
|
25
|
+
required: true;
|
|
26
|
+
};
|
|
27
|
+
anchor: StringConstructor;
|
|
28
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
29
|
+
export default _default;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { defineComponent, h } from "vue";
|
|
2
|
+
const types = {
|
|
3
|
+
string: ["str", "primary"],
|
|
4
|
+
integer: ["int", "info"],
|
|
5
|
+
number: ["num", "info"],
|
|
6
|
+
boolean: ["bool", "success"],
|
|
7
|
+
user: ["user", "secondary"],
|
|
8
|
+
channel: ["chan", "warning"],
|
|
9
|
+
role: ["role", "secondary"],
|
|
10
|
+
mentionable: ["@", "secondary"],
|
|
11
|
+
attachment: ["file", "neutral"]
|
|
12
|
+
};
|
|
13
|
+
const discordTypes = {
|
|
14
|
+
3: "string",
|
|
15
|
+
4: "integer",
|
|
16
|
+
5: "boolean",
|
|
17
|
+
6: "user",
|
|
18
|
+
7: "channel",
|
|
19
|
+
8: "role",
|
|
20
|
+
9: "mentionable",
|
|
21
|
+
10: "number",
|
|
22
|
+
11: "attachment"
|
|
23
|
+
};
|
|
24
|
+
function optionChip(option) {
|
|
25
|
+
const type = typeof option.type === "number" ? discordTypes[option.type] : option.type;
|
|
26
|
+
const [label, color] = type ? types[type] : ["?", "neutral"];
|
|
27
|
+
const limits = [
|
|
28
|
+
[option.min, ">=", "Minimum"],
|
|
29
|
+
[option.max, "<=", "Maximum"],
|
|
30
|
+
[option.minLength, "len>=", "Minimum length"],
|
|
31
|
+
[option.maxLength, "len<=", "Maximum length"]
|
|
32
|
+
];
|
|
33
|
+
return h("details", { key: option.name, class: "nd-option" }, [
|
|
34
|
+
h("summary", [
|
|
35
|
+
h("span", { class: "nd-option-name" }, option.name),
|
|
36
|
+
!option.required && h("span", { "class": "nd-optional", "aria-hidden": "true" }, "?"),
|
|
37
|
+
h("span", { class: ["nd-badge", "nd-type", `nd-${color}`], title: type }, label),
|
|
38
|
+
...limits.filter(([value]) => value !== void 0).map(([value, prefix, title]) => h("span", { class: "nd-badge", title: `${title} ${value}` }, `${prefix}${value}`)),
|
|
39
|
+
option.choices?.length ? h("span", { class: "nd-badge" }, `${option.choices.length} ${option.choices.length === 1 ? "choice" : "choices"}`) : null,
|
|
40
|
+
option.hasAutocomplete && h("span", { class: "nd-badge nd-auto", title: "Autocomplete" }, "auto")
|
|
41
|
+
]),
|
|
42
|
+
h("div", { class: "nd-option-detail" }, [
|
|
43
|
+
h("p", option.description),
|
|
44
|
+
h("p", [type, option.required ? "Required" : "Optional", option.hasAutocomplete && "Autocomplete"].filter(Boolean).join(" \xB7 ")),
|
|
45
|
+
option.choices?.length ? h("p", `Choices \xB7 ${option.choices.map((choice) => choice.name).join(", ")}`) : null
|
|
46
|
+
])
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
export default defineComponent({
|
|
50
|
+
name: "DiscordCommandCard",
|
|
51
|
+
props: {
|
|
52
|
+
command: { type: Object, required: true },
|
|
53
|
+
anchor: String
|
|
54
|
+
},
|
|
55
|
+
setup(props, { slots }) {
|
|
56
|
+
return () => {
|
|
57
|
+
const command = props.command;
|
|
58
|
+
const name = h("code", `/${command.name}`);
|
|
59
|
+
return h("article", { id: props.anchor, class: "nd-command-card" }, [
|
|
60
|
+
h("div", { class: "nd-card-header" }, [
|
|
61
|
+
h("div", { class: "nd-card-intro" }, [
|
|
62
|
+
h("div", { class: "nd-card-title" }, [
|
|
63
|
+
h("h2", props.anchor ? [h("a", { href: `#${encodeURIComponent(props.anchor)}` }, [name])] : [name]),
|
|
64
|
+
slots.badges?.()
|
|
65
|
+
]),
|
|
66
|
+
h("p", { class: "nd-description" }, command.description)
|
|
67
|
+
]),
|
|
68
|
+
slots.meta?.()
|
|
69
|
+
]),
|
|
70
|
+
command.options.length ? h("div", { class: "nd-card-options" }, command.options.map(optionChip)) : null,
|
|
71
|
+
slots.footer && h("div", { class: "nd-card-footer" }, slots.footer())
|
|
72
|
+
]);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DiscordCommandReference } from '../../../types.js';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
catalog: DiscordCommandReference;
|
|
4
|
+
title?: string;
|
|
5
|
+
};
|
|
6
|
+
type __VLS_Slots = {
|
|
7
|
+
'default'?: () => unknown;
|
|
8
|
+
'command-footer'?: (props: {
|
|
9
|
+
command: DiscordCommandReference['commands'][number];
|
|
10
|
+
}) => unknown;
|
|
11
|
+
};
|
|
12
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
13
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
14
|
+
declare const _default: typeof __VLS_export;
|
|
15
|
+
export default _default;
|
|
16
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
17
|
+
new (): {
|
|
18
|
+
$slots: S;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import ReferenceContent from "./ReferenceContent";
|
|
3
|
+
defineProps({
|
|
4
|
+
catalog: { type: Object, required: true },
|
|
5
|
+
title: { type: String, required: false }
|
|
6
|
+
});
|
|
7
|
+
defineSlots();
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<ReferenceContent :catalog="catalog" :title="title">
|
|
12
|
+
<slot />
|
|
13
|
+
<template v-if="$slots['command-footer']" #command-footer="{ command }">
|
|
14
|
+
<slot name="command-footer" :command="command" />
|
|
15
|
+
</template>
|
|
16
|
+
</ReferenceContent>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<style src="../reference.css">
|
|
20
|
+
|
|
21
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DiscordCommandReference } from '../../../types.js';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
catalog: DiscordCommandReference;
|
|
4
|
+
title?: string;
|
|
5
|
+
};
|
|
6
|
+
type __VLS_Slots = {
|
|
7
|
+
'default'?: () => unknown;
|
|
8
|
+
'command-footer'?: (props: {
|
|
9
|
+
command: DiscordCommandReference['commands'][number];
|
|
10
|
+
}) => unknown;
|
|
11
|
+
};
|
|
12
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
13
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
14
|
+
declare const _default: typeof __VLS_export;
|
|
15
|
+
export default _default;
|
|
16
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
17
|
+
new (): {
|
|
18
|
+
$slots: S;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -303,9 +303,6 @@ function setField(name, el) {
|
|
|
303
303
|
</button>
|
|
304
304
|
</div>
|
|
305
305
|
<div class="flex shrink-0 items-center gap-3 text-chat-muted sm:gap-4">
|
|
306
|
-
<div v-if="!command" aria-hidden="true" class="hidden items-center gap-4 sm:flex" title="Discord media controls">
|
|
307
|
-
<UIcon name="i-lucide-gift" class="size-5" /><span class="rounded-[3px] border-2 px-px text-[.625rem] leading-[1.1] font-extrabold">GIF</span><UIcon name="i-lucide-sticker" class="size-5" />
|
|
308
|
-
</div>
|
|
309
306
|
<UPopover v-if="!command || option" v-model:open="emojis" :content="{ side: 'top', align: 'end' }" :ui="{ content: 'grid grid-cols-4 gap-1 rounded-lg bg-chat-panel p-2 ring-chat-line' }">
|
|
310
307
|
<button type="button" aria-label="Add emoji" class="grid size-6 cursor-pointer place-items-center hover:text-chat-text">
|
|
311
308
|
<UIcon name="i-lucide-smile" class="size-5" />
|