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.
- package/README.md +249 -171
- package/dist/module.d.mts +146 -10
- package/dist/module.json +3 -3
- package/dist/module.mjs +1077 -348
- package/dist/runtime/acknowledgement.d.ts +11 -0
- package/dist/runtime/acknowledgement.js +156 -0
- package/dist/runtime/client/chat-theme.css +52 -0
- package/dist/runtime/client/components/ChatAvatar.d.vue.ts +6 -0
- package/dist/runtime/client/components/ChatAvatar.vue +11 -0
- package/dist/runtime/client/components/ChatAvatar.vue.d.ts +6 -0
- package/dist/runtime/client/components/CommandPicker.d.vue.ts +24 -0
- package/dist/runtime/client/components/CommandPicker.vue +67 -0
- package/dist/runtime/client/components/CommandPicker.vue.d.ts +24 -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.d.vue.ts +60 -0
- package/dist/runtime/client/components/CommandTestBar.vue +332 -0
- package/dist/runtime/client/components/CommandTestBar.vue.d.ts +60 -0
- package/dist/runtime/client/components/CommandTranscript.d.vue.ts +39 -0
- package/dist/runtime/client/components/CommandTranscript.vue +147 -0
- package/dist/runtime/client/components/CommandTranscript.vue.d.ts +39 -0
- package/dist/runtime/client/components/ProjectLogo.d.vue.ts +3 -0
- package/dist/runtime/client/components/ProjectLogo.vue +31 -0
- package/dist/runtime/client/components/ProjectLogo.vue.d.ts +3 -0
- package/dist/runtime/client/components/ReferenceContent.d.ts +26 -0
- package/dist/runtime/client/components/ReferenceContent.js +73 -0
- package/dist/runtime/client/components/TheHeader.d.vue.ts +3 -0
- package/dist/runtime/client/components/TheHeader.vue +53 -16
- package/dist/runtime/client/components/TheHeader.vue.d.ts +2 -2
- package/dist/runtime/client/components/appearance-select.d.ts +17 -0
- package/dist/runtime/client/components/appearance-select.js +15 -0
- package/dist/runtime/client/pages/activity.d.vue.ts +3 -0
- package/dist/runtime/client/pages/activity.vue +202 -0
- package/dist/runtime/client/pages/activity.vue.d.ts +3 -0
- package/dist/runtime/client/pages/context-menus.d.vue.ts +3 -0
- package/dist/runtime/client/pages/context-menus.vue +120 -0
- package/dist/runtime/client/pages/context-menus.vue.d.ts +3 -0
- package/dist/runtime/client/pages/listeners.d.vue.ts +3 -0
- package/dist/runtime/client/pages/listeners.vue +68 -0
- package/dist/runtime/client/pages/listeners.vue.d.ts +3 -0
- package/dist/runtime/client/pages/overview.d.vue.ts +3 -0
- package/dist/runtime/client/pages/overview.vue +280 -0
- package/dist/runtime/client/pages/overview.vue.d.ts +3 -0
- package/dist/runtime/client/pages/slash-commands.d.vue.ts +3 -0
- package/dist/runtime/client/pages/slash-commands.vue +185 -359
- package/dist/runtime/client/pages/slash-commands.vue.d.ts +2 -3
- package/dist/runtime/client/reference.css +46 -0
- package/dist/runtime/client/style.css +4 -1
- package/dist/runtime/client/useActivityLog.d.ts +7 -0
- package/dist/runtime/client/useActivityLog.js +76 -0
- package/dist/runtime/client/useCommandRegistry.d.ts +7 -0
- package/dist/runtime/client/useCommandRegistry.js +34 -0
- package/dist/runtime/client/useDashboardCatalog.d.ts +5 -0
- package/dist/runtime/client/useDashboardCatalog.js +9 -0
- package/dist/runtime/client/useDiscordCommandReference.d.ts +2 -0
- package/dist/runtime/client/useDiscordCommandReference.js +6 -0
- package/dist/runtime/dashboard/auth.d.ts +4 -0
- package/dist/runtime/dashboard/auth.js +55 -0
- package/dist/runtime/dashboard/oauth.d.ts +17 -0
- package/dist/runtime/dashboard/oauth.js +172 -0
- package/dist/runtime/dashboard/origin.d.ts +3 -0
- package/dist/runtime/dashboard/origin.js +15 -0
- package/dist/runtime/dashboard/permissions.d.ts +4 -0
- package/dist/runtime/dashboard/permissions.js +84 -0
- package/dist/runtime/dashboard/signin.d.ts +3 -0
- package/dist/runtime/dashboard/signin.js +42 -0
- package/dist/runtime/diagnostics.d.ts +4 -0
- package/dist/runtime/diagnostics.js +24 -0
- package/dist/runtime/discordInvocation.d.ts +14 -0
- package/dist/runtime/discordInvocation.js +28 -0
- package/dist/runtime/middleware.d.ts +1 -0
- package/dist/runtime/middleware.js +12 -0
- package/dist/runtime/reference/access.d.ts +6 -0
- package/dist/runtime/reference/access.js +143 -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 +22 -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/registration.d.ts +65 -0
- package/dist/runtime/registration.js +354 -0
- package/dist/runtime/server/api/discord/activity.get.d.ts +2 -0
- package/dist/runtime/server/api/discord/activity.get.js +6 -0
- package/dist/runtime/server/api/discord/catalog.get.d.ts +2 -0
- package/dist/runtime/server/api/discord/catalog.get.js +3 -0
- package/dist/runtime/server/api/discord/slash-command/autocomplete.post.d.ts +2 -0
- package/dist/runtime/server/api/discord/slash-command/autocomplete.post.js +14 -0
- package/dist/runtime/server/api/discord/slash-command/register.post.d.ts +1 -1
- package/dist/runtime/server/api/discord/slash-command/register.post.js +1 -1
- package/dist/runtime/server/api/discord/slash-command/remote-all.get.d.ts +1 -1
- package/dist/runtime/server/api/discord/slash-command/remote-diff.post.d.ts +1 -238
- package/dist/runtime/server/api/discord/slash-command/remote-diff.post.js +3 -1
- package/dist/runtime/server/api/discord/slash-command/test.post.d.ts +20 -0
- package/dist/runtime/server/api/discord/slash-command/test.post.js +19 -0
- package/dist/runtime/server/plugins/discord.js +95 -31
- package/dist/runtime/server/utils/client.d.ts +59 -246
- package/dist/runtime/server/utils/client.js +413 -451
- package/dist/runtime/server/utils/defineContextMenu.d.ts +49 -0
- package/dist/runtime/server/utils/defineContextMenu.js +12 -0
- package/dist/runtime/server/utils/defineListener.d.ts +24 -0
- package/dist/runtime/server/utils/defineListener.js +7 -0
- package/dist/runtime/server/utils/defineMiddleware.d.ts +29 -0
- package/dist/runtime/server/utils/defineMiddleware.js +24 -0
- package/dist/runtime/server/utils/describeCommand.d.ts +2 -0
- package/dist/runtime/server/utils/describeOption.d.ts +1 -1
- package/dist/runtime/server/utils/messageSender.d.ts +37 -0
- package/dist/runtime/server/utils/messageSender.js +149 -0
- package/dist/runtime/server/utils/middleware/cooldown.d.ts +1 -0
- package/dist/runtime/server/utils/middleware/cooldown.js +39 -0
- package/dist/runtime/server/utils/middleware/guildOnly.d.ts +1 -0
- package/dist/runtime/server/utils/middleware/guildOnly.js +6 -0
- package/dist/runtime/server/utils/middleware/ownerOnly.d.ts +1 -0
- package/dist/runtime/server/utils/middleware/ownerOnly.js +10 -0
- package/dist/runtime/server/utils/middleware/requireRole.d.ts +1 -0
- package/dist/runtime/server/utils/middleware/requireRole.js +15 -0
- package/dist/runtime/server/utils/reply.d.ts +13 -3
- package/dist/runtime/server/utils/reply.js +111 -162
- package/dist/runtime/server/utils/simulateInteraction.d.ts +20 -0
- package/dist/runtime/server/utils/simulateInteraction.js +127 -0
- package/dist/runtime/server/utils/useTextChannel.d.ts +56 -0
- package/dist/runtime/server/utils/useTextChannel.js +105 -0
- package/dist/types.d.mts +11 -1
- package/dist/types.d.ts +11 -1
- package/package.json +62 -44
- package/dist/runtime/client/components/TheHeader.css +0 -1
- package/dist/runtime/client/pages/slash-commands.css +0 -1
- package/dist/runtime/client/uno.config.d.ts +0 -2
- package/dist/runtime/client/uno.config.js +0 -10
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ChatInputCommandInteraction, TextBasedChannel } from 'discord.js';
|
|
2
|
+
import type { EffectScope } from 'vue';
|
|
3
|
+
interface Invocation {
|
|
4
|
+
scope?: EffectScope;
|
|
5
|
+
interaction?: ChatInputCommandInteraction;
|
|
6
|
+
channel?: TextBasedChannel | null;
|
|
7
|
+
middleware?: Record<string, unknown> | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function currentInvocation(): Invocation | undefined;
|
|
10
|
+
export declare function runInvocation<T>(scope: EffectScope, context: Invocation, fn: () => T): T;
|
|
11
|
+
export declare function setInvocationFields(fields: Partial<Invocation>): void;
|
|
12
|
+
export declare function onInvocationDispose(dispose: () => void): void;
|
|
13
|
+
export declare function bindInvocation<T extends unknown[], R>(fn: (...args: T) => R): (...args: T) => false | R;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { getCurrentScope, onScopeDispose } from "vue";
|
|
3
|
+
const storage = new AsyncLocalStorage();
|
|
4
|
+
export function currentInvocation() {
|
|
5
|
+
const invocation = storage.getStore();
|
|
6
|
+
return invocation?.scope?.active === false ? void 0 : invocation;
|
|
7
|
+
}
|
|
8
|
+
export function runInvocation(scope, context, fn) {
|
|
9
|
+
return storage.run({ ...context, scope }, () => scope.run(fn));
|
|
10
|
+
}
|
|
11
|
+
export function setInvocationFields(fields) {
|
|
12
|
+
storage.enterWith({ ...currentInvocation(), ...fields });
|
|
13
|
+
}
|
|
14
|
+
export function onInvocationDispose(dispose) {
|
|
15
|
+
if (getCurrentScope()) {
|
|
16
|
+
onScopeDispose(dispose);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const scope = storage.getStore()?.scope;
|
|
20
|
+
if (scope?.active)
|
|
21
|
+
scope.run(() => onScopeDispose(dispose));
|
|
22
|
+
else if (scope)
|
|
23
|
+
dispose();
|
|
24
|
+
}
|
|
25
|
+
export function bindInvocation(fn) {
|
|
26
|
+
const invocation = currentInvocation();
|
|
27
|
+
return (...args) => invocation?.scope ? invocation.scope.active && runInvocation(invocation.scope, invocation, () => fn(...args)) : fn(...args);
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveMiddlewareTags(names: string[] | undefined, path: string): import("../types.js").MiddlewareDefinition[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { cooldown } from "./server/utils/middleware/cooldown.js";
|
|
2
|
+
import { guildOnly } from "./server/utils/middleware/guildOnly.js";
|
|
3
|
+
import { ownerOnly } from "./server/utils/middleware/ownerOnly.js";
|
|
4
|
+
import { requireRole } from "./server/utils/middleware/requireRole.js";
|
|
5
|
+
const builtins = { cooldown, guildOnly, ownerOnly, requireRole };
|
|
6
|
+
export function resolveMiddlewareTags(names = [], path) {
|
|
7
|
+
return names.map((name) => {
|
|
8
|
+
if (!Object.hasOwn(builtins, name))
|
|
9
|
+
throw new Error(`Unknown @middleware "${name}" in ${path}. Use a built-in name or pass your middleware to useMiddleware().`);
|
|
10
|
+
return builtins[name];
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import type { DiscordReferenceOptions } from '../../types.js';
|
|
3
|
+
export declare function referenceRequest(path: string, method: string, options: DiscordReferenceOptions): boolean;
|
|
4
|
+
export declare function memberAccessFor(userId: string, guilds: string[]): Promise<"read" | "forbidden" | "unavailable">;
|
|
5
|
+
export declare function authorizeReference(event: H3Event, policy: DiscordReferenceOptions, document?: boolean): Promise<string | undefined>;
|
|
6
|
+
export declare function referenceOAuth(event: H3Event, policy: DiscordReferenceOptions): Promise<string | undefined>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { createError, getMethod, getQuery, setResponseHeaders, setResponseStatus } from "h3";
|
|
3
|
+
import { getDiscordSession, handleDashboardOAuth } from "../dashboard/oauth.js";
|
|
4
|
+
import { acceptsOrigin, configuredOrigin } from "../dashboard/origin.js";
|
|
5
|
+
import { dashboardAccessFor } from "../dashboard/permissions.js";
|
|
6
|
+
import { renderReferenceAccessPage } from "../dashboard/signin.js";
|
|
7
|
+
import { useDiscordClient } from "../server/utils/useDiscordClient.js";
|
|
8
|
+
const authPaths = ["/__discord-reference/login", "/__discord-reference/callback", "/__discord-reference/logout"];
|
|
9
|
+
export function referenceRequest(path, method, options) {
|
|
10
|
+
if (method === "GET" || method === "HEAD") {
|
|
11
|
+
if (path === "/api/discord/reference" || options.page !== false && path === "/commands")
|
|
12
|
+
return true;
|
|
13
|
+
if (method === "GET" && options.access !== "public" && authPaths.slice(0, 2).includes(path))
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return method === "POST" && options.access !== "public" && path === authPaths[2];
|
|
17
|
+
}
|
|
18
|
+
function referenceHeaders(event) {
|
|
19
|
+
setResponseHeaders(event, {
|
|
20
|
+
"cache-control": "private, no-store",
|
|
21
|
+
"cross-origin-resource-policy": "same-origin",
|
|
22
|
+
"referrer-policy": "no-referrer",
|
|
23
|
+
"x-content-type-options": "nosniff",
|
|
24
|
+
"x-frame-options": "DENY"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function signInConfig(event, policy) {
|
|
28
|
+
const url = configuredOrigin(process.env.DISCORD_REFERENCE_ORIGIN ?? process.env.DISCORD_DASHBOARD_ORIGIN);
|
|
29
|
+
const clientId = process.env.DISCORD_CLIENT_ID;
|
|
30
|
+
if (!url || !clientId || !/^[1-9]\d{0,19}$/.test(clientId) || policy.access !== "authenticated" && !process.env.DISCORD_TOKEN)
|
|
31
|
+
throw createError({ statusCode: 503, statusMessage: "Command reference sign-in is not configured." });
|
|
32
|
+
if (!acceptsOrigin(event, url))
|
|
33
|
+
throw createError({ statusCode: 403, statusMessage: "Forbidden" });
|
|
34
|
+
return { url, clientId };
|
|
35
|
+
}
|
|
36
|
+
let verifiedBot;
|
|
37
|
+
async function botIdentityMatches(clientId, token) {
|
|
38
|
+
if (verifiedBot?.token === token && verifiedBot.clientId === clientId)
|
|
39
|
+
return true;
|
|
40
|
+
try {
|
|
41
|
+
const response = await fetch("https://discord.com/api/v10/users/@me", {
|
|
42
|
+
headers: { Authorization: `Bot ${token}` },
|
|
43
|
+
redirect: "error",
|
|
44
|
+
signal: AbortSignal.timeout(5e3)
|
|
45
|
+
});
|
|
46
|
+
const user = response.ok && await response.json();
|
|
47
|
+
if (user?.id === clientId && user.bot === true) {
|
|
48
|
+
verifiedBot = { token, clientId };
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
} catch {
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
export async function memberAccessFor(userId, guilds) {
|
|
56
|
+
let unavailable = false;
|
|
57
|
+
const deadline = Date.now() + 5e3;
|
|
58
|
+
for (const guild of guilds) {
|
|
59
|
+
const remaining = deadline - Date.now();
|
|
60
|
+
if (remaining <= 0)
|
|
61
|
+
return "unavailable";
|
|
62
|
+
try {
|
|
63
|
+
const response = await fetch(`https://discord.com/api/v10/guilds/${guild}/members/${userId}`, {
|
|
64
|
+
headers: { Authorization: `Bot ${process.env.DISCORD_TOKEN}` },
|
|
65
|
+
cache: "no-store",
|
|
66
|
+
redirect: "error",
|
|
67
|
+
signal: AbortSignal.timeout(remaining)
|
|
68
|
+
});
|
|
69
|
+
if (response.status === 404)
|
|
70
|
+
continue;
|
|
71
|
+
if (response.ok && (await response.json())?.user?.id === userId)
|
|
72
|
+
return "read";
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
unavailable = true;
|
|
76
|
+
}
|
|
77
|
+
return unavailable ? "unavailable" : "forbidden";
|
|
78
|
+
}
|
|
79
|
+
export async function authorizeReference(event, policy, document = false) {
|
|
80
|
+
referenceHeaders(event);
|
|
81
|
+
if (policy.access === "public")
|
|
82
|
+
return;
|
|
83
|
+
const { url, clientId } = signInConfig(event, policy);
|
|
84
|
+
const session = getDiscordSession(event, url, "reference");
|
|
85
|
+
let access = "anonymous";
|
|
86
|
+
if (session) {
|
|
87
|
+
if (policy.access === "private") {
|
|
88
|
+
access = await dashboardAccessFor(session.userId, "GET", "/__discord-auth/session");
|
|
89
|
+
} else if (policy.access === "members") {
|
|
90
|
+
access = policy.guilds && !await botIdentityMatches(clientId, process.env.DISCORD_TOKEN) ? "unavailable" : await memberAccessFor(session.userId, policy.guilds ?? session.guilds ?? []);
|
|
91
|
+
} else {
|
|
92
|
+
access = "read";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (access === "unavailable")
|
|
96
|
+
throw createError({ statusCode: 503, statusMessage: "Discord access verification is temporarily unavailable." });
|
|
97
|
+
if (access === "anonymous" || access === "forbidden") {
|
|
98
|
+
const status = access === "anonymous" ? 401 : 403;
|
|
99
|
+
if (document) {
|
|
100
|
+
setResponseStatus(event, status);
|
|
101
|
+
return renderReferenceAccessPage(status);
|
|
102
|
+
}
|
|
103
|
+
throw createError({ statusCode: status, statusMessage: access === "anonymous" ? "Sign in to the command reference." : "Forbidden" });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function returnPath(value, origin, fallback) {
|
|
107
|
+
if (value === void 0)
|
|
108
|
+
return fallback;
|
|
109
|
+
let path = "";
|
|
110
|
+
if (typeof value === "string" && value.length <= 2048 && !/%(?:2f|5c|25)/i.test(value)) {
|
|
111
|
+
try {
|
|
112
|
+
path = decodeURIComponent(value);
|
|
113
|
+
} catch {
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!/^\/[\p{L}\p{N}._~/-]*$/u.test(path) || path.includes("//") || path.split("/").some((part) => part === "." || part === ".."))
|
|
117
|
+
throw createError({ statusCode: 400, statusMessage: "Invalid return path." });
|
|
118
|
+
return new URL(path, origin).pathname;
|
|
119
|
+
}
|
|
120
|
+
export function referenceOAuth(event, policy) {
|
|
121
|
+
referenceHeaders(event);
|
|
122
|
+
const path = event.path.split("?")[0];
|
|
123
|
+
if (!referenceRequest(path, getMethod(event), policy) || !authPaths.includes(path))
|
|
124
|
+
throw createError({ statusCode: 404 });
|
|
125
|
+
const { url, clientId } = signInConfig(event, policy);
|
|
126
|
+
let sharedGuilds;
|
|
127
|
+
if (policy.access === "members" && !policy.guilds && !path.endsWith("/logout")) {
|
|
128
|
+
let client;
|
|
129
|
+
try {
|
|
130
|
+
client = useDiscordClient().internalClient;
|
|
131
|
+
} catch {
|
|
132
|
+
}
|
|
133
|
+
if (!client?.isReady() || client.user.id !== clientId)
|
|
134
|
+
throw createError({ statusCode: 503, statusMessage: "The bot is unavailable for shared server verification." });
|
|
135
|
+
const guilds = client.guilds.cache;
|
|
136
|
+
sharedGuilds = (ids) => ids.filter((id) => guilds.has(id));
|
|
137
|
+
}
|
|
138
|
+
return handleDashboardOAuth(event, url, clientId, {
|
|
139
|
+
audience: "reference",
|
|
140
|
+
landing: returnPath(getQuery(event).returnTo, url, policy.page === false ? "/" : "/commands"),
|
|
141
|
+
sharedGuilds
|
|
142
|
+
});
|
|
143
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getCatalog, policy } from "discord/reference";
|
|
2
|
+
import { createError, defineEventHandler } from "h3";
|
|
3
|
+
import { authorizeReference } from "./access.js";
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
if (event.path.split("?")[0] !== "/api/discord/reference")
|
|
6
|
+
throw createError({ statusCode: 404 });
|
|
7
|
+
await authorizeReference(event, policy);
|
|
8
|
+
return getCatalog();
|
|
9
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getCatalog, policy, styles } from "discord/reference";
|
|
2
|
+
import { createError, defineEventHandler, setResponseHeaders } from "h3";
|
|
3
|
+
import { h } from "vue";
|
|
4
|
+
import { renderToString } from "vue/server-renderer";
|
|
5
|
+
import ReferenceContent from "../client/components/ReferenceContent.js";
|
|
6
|
+
import { authorizeReference } from "./access.js";
|
|
7
|
+
export default defineEventHandler(async (event) => {
|
|
8
|
+
if (policy.page === false || event.path.split("?")[0] !== "/commands")
|
|
9
|
+
throw createError({ statusCode: 404 });
|
|
10
|
+
setResponseHeaders(event, {
|
|
11
|
+
"content-type": "text/html; charset=utf-8",
|
|
12
|
+
"content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'"
|
|
13
|
+
});
|
|
14
|
+
const denied = await authorizeReference(event, policy, true);
|
|
15
|
+
if (denied)
|
|
16
|
+
return denied;
|
|
17
|
+
const slots = policy.access === "public" ? void 0 : {
|
|
18
|
+
default: () => h("form", { method: "post", action: "/__discord-reference/logout" }, h("button", { type: "submit" }, "Sign out"))
|
|
19
|
+
};
|
|
20
|
+
const body = await renderToString(h(ReferenceContent, { catalog: await getCatalog() }, slots));
|
|
21
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="color-scheme" content="light dark"><title>Command reference</title><style>${styles}</style></head><body><main>${body}</main></body></html>`;
|
|
22
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { policy } from "discord/reference";
|
|
2
|
+
import { defineEventHandler, getMethod } from "h3";
|
|
3
|
+
import dashboardAuth from "../dashboard/auth.js";
|
|
4
|
+
import { referenceOAuth, referenceRequest } from "./access.js";
|
|
5
|
+
import catalog from "./catalog.js";
|
|
6
|
+
import document from "./document.js";
|
|
7
|
+
export default defineEventHandler((event) => {
|
|
8
|
+
const path = event.path.split("?")[0];
|
|
9
|
+
if (!referenceRequest(path, getMethod(event), policy))
|
|
10
|
+
return dashboardAuth(event);
|
|
11
|
+
if (path === "/api/discord/reference")
|
|
12
|
+
return catalog(event);
|
|
13
|
+
if (path === "/commands")
|
|
14
|
+
return document(event);
|
|
15
|
+
return referenceOAuth(event, policy);
|
|
16
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { APIApplicationCommand, APIApplicationCommandOption, REST, RESTPostAPIApplicationCommandsJSONBody } from 'discord.js';
|
|
2
|
+
import type { SlashCommandRuntime, SlashCommandSubcommandGroupRuntime, SlashCommandSubcommandRuntime } from '../types.js';
|
|
3
|
+
import type { ContextMenuDefinition } from './server/utils/defineContextMenu.js';
|
|
4
|
+
type Payload = RESTPostAPIApplicationCommandsJSONBody;
|
|
5
|
+
type LocalCommand = SlashCommandRuntime | SlashCommandSubcommandRuntime | SlashCommandSubcommandGroupRuntime;
|
|
6
|
+
interface Entry {
|
|
7
|
+
body: Payload;
|
|
8
|
+
local?: SlashCommandRuntime;
|
|
9
|
+
}
|
|
10
|
+
type ScopePlan = Map<string, Entry[]>;
|
|
11
|
+
export declare function commandScopes(targets: true | string[] | undefined, guilds: string[]): string[];
|
|
12
|
+
export declare function planRegistrations(commands: SlashCommandRuntime[], menus: (ContextMenuDefinition & {
|
|
13
|
+
name: string;
|
|
14
|
+
})[], guilds: string[]): {
|
|
15
|
+
scopes: ScopePlan;
|
|
16
|
+
unassigned: SlashCommandRuntime[];
|
|
17
|
+
unassignedMenus: string[];
|
|
18
|
+
};
|
|
19
|
+
type Plan = ReturnType<typeof planRegistrations>;
|
|
20
|
+
type LocalRow = LocalCommand & {
|
|
21
|
+
scope: string;
|
|
22
|
+
};
|
|
23
|
+
interface RemoteRow {
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
scope: string;
|
|
27
|
+
id?: string;
|
|
28
|
+
options: APIApplicationCommandOption[];
|
|
29
|
+
}
|
|
30
|
+
interface Match {
|
|
31
|
+
local: LocalRow;
|
|
32
|
+
remote: RemoteRow;
|
|
33
|
+
}
|
|
34
|
+
export interface RegistrationDiff {
|
|
35
|
+
added: LocalRow[];
|
|
36
|
+
removed: RemoteRow[];
|
|
37
|
+
changed: Match[];
|
|
38
|
+
synced: Match[];
|
|
39
|
+
conflict: LocalRow[];
|
|
40
|
+
menuChanges: number;
|
|
41
|
+
}
|
|
42
|
+
interface ScopeStore {
|
|
43
|
+
load: () => Promise<string[] | null>;
|
|
44
|
+
save: (scopes: string[]) => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export interface RegistrationResult {
|
|
47
|
+
scope: string;
|
|
48
|
+
commands: APIApplicationCommand[];
|
|
49
|
+
error?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare class CommandRegistration {
|
|
52
|
+
private rest;
|
|
53
|
+
private appId;
|
|
54
|
+
private store;
|
|
55
|
+
private onError;
|
|
56
|
+
private confirmed;
|
|
57
|
+
private queue;
|
|
58
|
+
constructor(rest: Pick<REST, 'get' | 'put'>, appId: string, store: ScopeStore, onError: (error: unknown) => void);
|
|
59
|
+
private route;
|
|
60
|
+
read(scope: string): Promise<APIApplicationCommand[]>;
|
|
61
|
+
diff(plan: Plan): Promise<RegistrationDiff>;
|
|
62
|
+
sync(plan: Plan, changedOnly?: boolean): Promise<RegistrationResult[]>;
|
|
63
|
+
private apply;
|
|
64
|
+
}
|
|
65
|
+
export {};
|