nuxt-discord 0.0.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/LICENSE +21 -0
- package/README.md +292 -0
- package/dist/module.d.mts +128 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +508 -0
- package/dist/runtime/client/components/TheHeader.css +1 -0
- package/dist/runtime/client/components/TheHeader.vue +25 -0
- package/dist/runtime/client/components/TheHeader.vue.d.ts +3 -0
- package/dist/runtime/client/pages/slash-commands.css +1 -0
- package/dist/runtime/client/pages/slash-commands.vue +429 -0
- package/dist/runtime/client/pages/slash-commands.vue.d.ts +4 -0
- package/dist/runtime/client/style.css +1 -0
- package/dist/runtime/client/uno.config.d.ts +2 -0
- package/dist/runtime/client/uno.config.js +10 -0
- package/dist/runtime/server/api/discord/slash-command/all.get.d.ts +2 -0
- package/dist/runtime/server/api/discord/slash-command/all.get.js +8 -0
- package/dist/runtime/server/api/discord/slash-command/register.post.d.ts +2 -0
- package/dist/runtime/server/api/discord/slash-command/register.post.js +6 -0
- package/dist/runtime/server/api/discord/slash-command/remote-all.get.d.ts +2 -0
- package/dist/runtime/server/api/discord/slash-command/remote-all.get.js +8 -0
- package/dist/runtime/server/api/discord/slash-command/remote-diff.post.d.ts +20 -0
- package/dist/runtime/server/api/discord/slash-command/remote-diff.post.js +8 -0
- package/dist/runtime/server/plugins/discord.d.ts +2 -0
- package/dist/runtime/server/plugins/discord.js +38 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/server/utils/client.d.ts +59 -0
- package/dist/runtime/server/utils/client.js +396 -0
- package/dist/runtime/server/utils/defineSlashCommand.d.ts +10 -0
- package/dist/runtime/server/utils/defineSlashCommand.js +3 -0
- package/dist/runtime/server/utils/describeCommand.d.ts +19 -0
- package/dist/runtime/server/utils/describeCommand.js +2 -0
- package/dist/runtime/server/utils/describeOption.d.ts +36 -0
- package/dist/runtime/server/utils/describeOption.js +2 -0
- package/dist/runtime/server/utils/reply.d.ts +9 -0
- package/dist/runtime/server/utils/reply.js +27 -0
- package/dist/runtime/server/utils/useDiscordClient.d.ts +5 -0
- package/dist/runtime/server/utils/useDiscordClient.js +11 -0
- package/dist/types.d.mts +9 -0
- package/package.json +78 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref, useFetch, useRuntimeConfig, watchEffect } from "#imports";
|
|
3
|
+
import { useWebSocket } from "@vueuse/core";
|
|
4
|
+
import slashCommands from "discord/slashCommands";
|
|
5
|
+
import TheHeader from "../components/TheHeader.vue";
|
|
6
|
+
import "../style.css";
|
|
7
|
+
import "./slash-commands.css";
|
|
8
|
+
var ApplicationCommandOptionType = /* @__PURE__ */ ((ApplicationCommandOptionType2) => {
|
|
9
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["Subcommand"] = 1] = "Subcommand";
|
|
10
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["SubcommandGroup"] = 2] = "SubcommandGroup";
|
|
11
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["String"] = 3] = "String";
|
|
12
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["Integer"] = 4] = "Integer";
|
|
13
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["Boolean"] = 5] = "Boolean";
|
|
14
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["User"] = 6] = "User";
|
|
15
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["Channel"] = 7] = "Channel";
|
|
16
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["Role"] = 8] = "Role";
|
|
17
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["Mentionable"] = 9] = "Mentionable";
|
|
18
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["Number"] = 10] = "Number";
|
|
19
|
+
ApplicationCommandOptionType2[ApplicationCommandOptionType2["Attachment"] = 11] = "Attachment";
|
|
20
|
+
return ApplicationCommandOptionType2;
|
|
21
|
+
})(ApplicationCommandOptionType || {});
|
|
22
|
+
function getOptionTypeLabel(type) {
|
|
23
|
+
switch (type) {
|
|
24
|
+
case 3 /* String */:
|
|
25
|
+
return "text";
|
|
26
|
+
case 4 /* Integer */:
|
|
27
|
+
return "integer";
|
|
28
|
+
case 10 /* Number */:
|
|
29
|
+
return "number";
|
|
30
|
+
case 5 /* Boolean */:
|
|
31
|
+
return "boolean";
|
|
32
|
+
case 6 /* User */:
|
|
33
|
+
return "user";
|
|
34
|
+
case 7 /* Channel */:
|
|
35
|
+
return "channel";
|
|
36
|
+
case 8 /* Role */:
|
|
37
|
+
return "role";
|
|
38
|
+
case 9 /* Mentionable */:
|
|
39
|
+
return "mention";
|
|
40
|
+
case 11 /* Attachment */:
|
|
41
|
+
return "file";
|
|
42
|
+
default:
|
|
43
|
+
return "unknown";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function getOptionTypeColor(type) {
|
|
47
|
+
switch (type) {
|
|
48
|
+
case 3 /* String */:
|
|
49
|
+
return "primary";
|
|
50
|
+
case 4 /* Integer */:
|
|
51
|
+
case 10 /* Number */:
|
|
52
|
+
return "info";
|
|
53
|
+
case 5 /* Boolean */:
|
|
54
|
+
return "success";
|
|
55
|
+
case 6 /* User */:
|
|
56
|
+
case 8 /* Role */:
|
|
57
|
+
case 9 /* Mentionable */:
|
|
58
|
+
return "secondary";
|
|
59
|
+
case 7 /* Channel */:
|
|
60
|
+
return "warning";
|
|
61
|
+
case 11 /* Attachment */:
|
|
62
|
+
return "neutral";
|
|
63
|
+
default:
|
|
64
|
+
return "neutral";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function getRemoteId(command) {
|
|
68
|
+
if ("remote" in command && command.remote?.id) {
|
|
69
|
+
return command.remote.id;
|
|
70
|
+
}
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
const toast = useToast();
|
|
74
|
+
const commands = ref(slashCommands);
|
|
75
|
+
const {
|
|
76
|
+
data: diff,
|
|
77
|
+
refresh: refreshDiff
|
|
78
|
+
} = useFetch(
|
|
79
|
+
"/api/discord/slash-command/remote-diff",
|
|
80
|
+
{
|
|
81
|
+
method: "post",
|
|
82
|
+
body: {
|
|
83
|
+
commands
|
|
84
|
+
},
|
|
85
|
+
immediate: import.meta.dev
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
const commandsWithStatus = computed(() => {
|
|
89
|
+
if (!diff.value) {
|
|
90
|
+
return commands.value.map((cmd) => ({
|
|
91
|
+
...cmd,
|
|
92
|
+
status: "synced"
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
return [
|
|
96
|
+
...diff.value.conflict.map((cmd) => ({
|
|
97
|
+
...cmd,
|
|
98
|
+
status: "conflict"
|
|
99
|
+
})),
|
|
100
|
+
...diff.value.added.map((cmd) => ({
|
|
101
|
+
...cmd,
|
|
102
|
+
status: "added"
|
|
103
|
+
})),
|
|
104
|
+
...diff.value.removed.map((cmd) => ({
|
|
105
|
+
name: cmd.name,
|
|
106
|
+
description: cmd.description,
|
|
107
|
+
path: "unknown",
|
|
108
|
+
options: cmd.options,
|
|
109
|
+
status: "removed",
|
|
110
|
+
remote: cmd
|
|
111
|
+
})),
|
|
112
|
+
...diff.value.changed.map(({ remote, local }) => ({
|
|
113
|
+
...local,
|
|
114
|
+
status: "changed",
|
|
115
|
+
remote
|
|
116
|
+
})),
|
|
117
|
+
...diff.value.synced.map(({ remote, local }) => ({
|
|
118
|
+
...local,
|
|
119
|
+
status: "synced",
|
|
120
|
+
remote
|
|
121
|
+
}))
|
|
122
|
+
];
|
|
123
|
+
});
|
|
124
|
+
const allSynced = computed(() => commandsWithStatus.value.every((cmd) => cmd.status === "synced"));
|
|
125
|
+
const stats = computed(() => commandsWithStatus.value.reduce((acc, cmd) => {
|
|
126
|
+
if (cmd.status === "added")
|
|
127
|
+
acc.added++;
|
|
128
|
+
else if (cmd.status === "removed")
|
|
129
|
+
acc.removed++;
|
|
130
|
+
else if (cmd.status === "changed")
|
|
131
|
+
acc.changed++;
|
|
132
|
+
else if (cmd.status === "synced")
|
|
133
|
+
acc.synced++;
|
|
134
|
+
else if (cmd.status === "conflict")
|
|
135
|
+
acc.conflict++;
|
|
136
|
+
return acc;
|
|
137
|
+
}, { added: 0, removed: 0, changed: 0, synced: 0, conflict: 0 }));
|
|
138
|
+
const pendingSync = ref(false);
|
|
139
|
+
async function syncCommands() {
|
|
140
|
+
try {
|
|
141
|
+
pendingSync.value = true;
|
|
142
|
+
await $fetch("/api/discord/slash-command/register", { method: "POST" });
|
|
143
|
+
await refreshDiff();
|
|
144
|
+
} catch (error) {
|
|
145
|
+
toast.add({
|
|
146
|
+
title: "Error registering commands",
|
|
147
|
+
description: error.statusMessage || "An unknown error occurred",
|
|
148
|
+
color: "error",
|
|
149
|
+
icon: "i-lucide-triangle-alert"
|
|
150
|
+
});
|
|
151
|
+
} finally {
|
|
152
|
+
pendingSync.value = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const runtimeConfig = useRuntimeConfig();
|
|
156
|
+
let ws;
|
|
157
|
+
if (import.meta.dev && runtimeConfig.public.discord?.wsUrl) {
|
|
158
|
+
if (!("WebSocket" in window)) {
|
|
159
|
+
console.warn("Could not enable hot reload, your browser does not support WebSocket");
|
|
160
|
+
} else {
|
|
161
|
+
ws = useWebSocket(runtimeConfig.public.discord.wsUrl, {
|
|
162
|
+
autoReconnect: true,
|
|
163
|
+
onConnected: () => {
|
|
164
|
+
console.log("WebSocket connection established for slash command hot reload");
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
ws?.send(JSON.stringify({ event: "full-update" }));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
watchEffect(() => {
|
|
171
|
+
const message = ws?.data.value;
|
|
172
|
+
if (!message)
|
|
173
|
+
return;
|
|
174
|
+
const data = JSON.parse(message);
|
|
175
|
+
if (data.event === "full-update") {
|
|
176
|
+
commands.value = data.commands;
|
|
177
|
+
} else {
|
|
178
|
+
ws?.send(JSON.stringify({ event: "full-update" }));
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
const statusColors = {
|
|
182
|
+
synced: "primary",
|
|
183
|
+
added: "secondary",
|
|
184
|
+
changed: "warning",
|
|
185
|
+
removed: "neutral",
|
|
186
|
+
conflict: "error"
|
|
187
|
+
};
|
|
188
|
+
const statusClasses = {
|
|
189
|
+
synced: "",
|
|
190
|
+
added: "ring-0 border border-dashed border-[var(--ui-secondary)]/50 divide-[var(--ui-secondary)]/50 divide-dashed",
|
|
191
|
+
changed: "ring-0 border border-dashed border-[var(--ui-warning)]/50 divide-[var(--ui-warning)]/50 divide-dashed",
|
|
192
|
+
removed: "ring-0 border border-dashed border-[var(--ui-neutral)]/50 divide-[var(--ui-neutral)]/50 divide-dashed",
|
|
193
|
+
conflict: "ring-0 border border-dashed border-[var(--ui-error)]/50 divide-[var(--ui-error)]/50 divide-dashed"
|
|
194
|
+
};
|
|
195
|
+
</script>
|
|
196
|
+
|
|
197
|
+
<template>
|
|
198
|
+
<UApp>
|
|
199
|
+
<TheHeader />
|
|
200
|
+
<div class="mx-auto mb-16 px-6 container">
|
|
201
|
+
<!-- Title Section -->
|
|
202
|
+
<div class="my-6">
|
|
203
|
+
<h1 class="text-3xl text-gray-900 font-bold mb-2 dark:text-white">
|
|
204
|
+
Discord Slash Commands
|
|
205
|
+
</h1>
|
|
206
|
+
<p class="text-sm text-gray-600 dark:text-gray-400">
|
|
207
|
+
Manage and view your registered Discord slash commands
|
|
208
|
+
</p>
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<!-- Commands Count Badge -->
|
|
212
|
+
<div class="mb-6 flex w-full items-center justify-between">
|
|
213
|
+
<div class="flex gap-2 items-center">
|
|
214
|
+
<UBadge
|
|
215
|
+
:label="`${stats.synced} ${stats.synced === 1 ? 'command' : 'commands'} synced`"
|
|
216
|
+
variant="subtle"
|
|
217
|
+
color="primary"
|
|
218
|
+
size="lg"
|
|
219
|
+
/>
|
|
220
|
+
<UBadge
|
|
221
|
+
v-if="stats.conflict > 0"
|
|
222
|
+
:label="`${stats.conflict} conflict${stats.conflict === 1 ? '' : 's'}`"
|
|
223
|
+
variant="outline"
|
|
224
|
+
color="error"
|
|
225
|
+
size="lg"
|
|
226
|
+
/>
|
|
227
|
+
<UBadge
|
|
228
|
+
v-if="stats.added > 0"
|
|
229
|
+
:label="`${stats.added} added`"
|
|
230
|
+
variant="outline"
|
|
231
|
+
color="secondary"
|
|
232
|
+
size="lg"
|
|
233
|
+
/>
|
|
234
|
+
<UBadge
|
|
235
|
+
v-if="stats.changed > 0"
|
|
236
|
+
:label="`${stats.changed} changed`"
|
|
237
|
+
variant="outline"
|
|
238
|
+
color="warning"
|
|
239
|
+
size="lg"
|
|
240
|
+
/>
|
|
241
|
+
<UBadge
|
|
242
|
+
v-if="stats.removed > 0"
|
|
243
|
+
:label="`${stats.removed} removed`"
|
|
244
|
+
variant="outline"
|
|
245
|
+
color="neutral"
|
|
246
|
+
size="lg"
|
|
247
|
+
/>
|
|
248
|
+
</div>
|
|
249
|
+
|
|
250
|
+
<!-- <UButton icon="i-lucide-circle" @click="test" /> -->
|
|
251
|
+
<UButton
|
|
252
|
+
v-if="!allSynced"
|
|
253
|
+
:icon="pendingSync ? 'i-lucide-refresh-ccw' : 'i-lucide-cloud-upload'"
|
|
254
|
+
variant="outline"
|
|
255
|
+
color="secondary"
|
|
256
|
+
class="hover:cursor-pointer disabled:hover:cursor-not-allowed"
|
|
257
|
+
:disabled="stats.conflict > 0"
|
|
258
|
+
:title="stats.conflict > 0 ? 'Resolve conflicts before syncing' : 'Register out of sync commands'"
|
|
259
|
+
:ui="{ leadingIcon: pendingSync ? 'animate-spin' : '' }"
|
|
260
|
+
@click="syncCommands"
|
|
261
|
+
>
|
|
262
|
+
Sync
|
|
263
|
+
</UButton>
|
|
264
|
+
</div>
|
|
265
|
+
|
|
266
|
+
<!-- Commands List -->
|
|
267
|
+
<div v-if="commandsWithStatus.length > 0" class="flex flex-col gap-4">
|
|
268
|
+
<UCard
|
|
269
|
+
v-for="command in commandsWithStatus.sort((a, b) => a.name.localeCompare(b.name))"
|
|
270
|
+
:key="command.name"
|
|
271
|
+
class="transition-shadow duration-200 overflow-hidden"
|
|
272
|
+
:class="statusClasses[command.status]"
|
|
273
|
+
:ui="{ body: 'pt-2' }"
|
|
274
|
+
>
|
|
275
|
+
<template #header>
|
|
276
|
+
<div class="flex items-center justify-between">
|
|
277
|
+
<div class="flex gap-3 items-center">
|
|
278
|
+
<UIcon name="i-heroicons-command-line" class="text-primary-500 h-5 w-5" />
|
|
279
|
+
<div>
|
|
280
|
+
<h3
|
|
281
|
+
class="text-lg text-gray-700 font-semibold dark:text-gray-200"
|
|
282
|
+
:class="command.status === 'conflict' && 'text-[var(--ui-error)]!'"
|
|
283
|
+
>
|
|
284
|
+
/{{ command.name }}
|
|
285
|
+
</h3>
|
|
286
|
+
<p class="text-sm text-gray-600 dark:text-gray-400">
|
|
287
|
+
{{ command.description }}
|
|
288
|
+
</p>
|
|
289
|
+
<UBadge
|
|
290
|
+
v-if="command.options.length > 0"
|
|
291
|
+
:label="`${command.options.length} option${command.options.length === 1 ? '' : 's'}`"
|
|
292
|
+
variant="soft"
|
|
293
|
+
color="neutral"
|
|
294
|
+
size="sm"
|
|
295
|
+
/>
|
|
296
|
+
</div>
|
|
297
|
+
</div>
|
|
298
|
+
|
|
299
|
+
<div class="flex gap-2 items-center">
|
|
300
|
+
<UBadge
|
|
301
|
+
:label="command.status"
|
|
302
|
+
:color="statusColors[command.status]"
|
|
303
|
+
size="sm"
|
|
304
|
+
variant="soft"
|
|
305
|
+
/>
|
|
306
|
+
</div>
|
|
307
|
+
</div>
|
|
308
|
+
</template>
|
|
309
|
+
|
|
310
|
+
<!-- Command Options -->
|
|
311
|
+
<div v-if="command.options.length > 0" class="mt-4">
|
|
312
|
+
<h4 class="text-sm text-gray-700 font-medium mb-3 dark:text-gray-300">
|
|
313
|
+
Command Options:
|
|
314
|
+
</h4>
|
|
315
|
+
<div class="gap-3 grid lg:grid-cols-3 sm:grid-cols-2">
|
|
316
|
+
<UCard
|
|
317
|
+
v-for="option in command.options"
|
|
318
|
+
:key="option.name"
|
|
319
|
+
variant="soft"
|
|
320
|
+
class="transition-shadow duration-200 overflow-hidden"
|
|
321
|
+
>
|
|
322
|
+
<div class="mb-1 flex flex-wrap gap-2 items-center">
|
|
323
|
+
<span class="text-lg text-gray-900 dark:text-white">
|
|
324
|
+
{{ option.name + (!option.required ? "?" : "") }}
|
|
325
|
+
</span>
|
|
326
|
+
<UBadge
|
|
327
|
+
:label="getOptionTypeLabel(option.type)"
|
|
328
|
+
variant="soft"
|
|
329
|
+
:color="getOptionTypeColor(option.type)"
|
|
330
|
+
size="sm"
|
|
331
|
+
/>
|
|
332
|
+
<UBadge
|
|
333
|
+
v-if="option.required"
|
|
334
|
+
label="required"
|
|
335
|
+
variant="soft"
|
|
336
|
+
color="error"
|
|
337
|
+
size="sm"
|
|
338
|
+
/>
|
|
339
|
+
<!-- Restriction badges -->
|
|
340
|
+
<UBadge
|
|
341
|
+
v-if="'min' in option && option.min !== void 0"
|
|
342
|
+
:label="`min: ${option.min}`"
|
|
343
|
+
variant="outline"
|
|
344
|
+
color="neutral"
|
|
345
|
+
size="sm"
|
|
346
|
+
/>
|
|
347
|
+
<UBadge
|
|
348
|
+
v-if="'max' in option && option.max !== void 0"
|
|
349
|
+
:label="`max: ${option.max}`"
|
|
350
|
+
variant="outline"
|
|
351
|
+
color="neutral"
|
|
352
|
+
size="sm"
|
|
353
|
+
/>
|
|
354
|
+
<UBadge
|
|
355
|
+
v-if="'minLength' in option && option.minLength !== void 0"
|
|
356
|
+
:label="`min: ${option.minLength}`"
|
|
357
|
+
variant="outline"
|
|
358
|
+
color="neutral"
|
|
359
|
+
size="sm"
|
|
360
|
+
/>
|
|
361
|
+
<UBadge
|
|
362
|
+
v-if="'maxLength' in option && option.maxLength !== void 0"
|
|
363
|
+
:label="`max: ${option.maxLength}`"
|
|
364
|
+
variant="outline"
|
|
365
|
+
color="neutral"
|
|
366
|
+
size="sm"
|
|
367
|
+
/>
|
|
368
|
+
<!-- Choices dropdown -->
|
|
369
|
+
<UDropdownMenu
|
|
370
|
+
v-if="'choices' in option && option.choices && option.choices.length > 0"
|
|
371
|
+
:items="option.choices.map((choice) => ({ label: choice.name }))"
|
|
372
|
+
:popper="{ placement: 'bottom-start' }"
|
|
373
|
+
>
|
|
374
|
+
<UBadge
|
|
375
|
+
v-if="'choices' in option && option.choices && option.choices.length > 0"
|
|
376
|
+
:label="`${option.choices.length} choices`"
|
|
377
|
+
variant="outline"
|
|
378
|
+
color="info"
|
|
379
|
+
size="sm"
|
|
380
|
+
class="hover:cursor-pointer"
|
|
381
|
+
/>
|
|
382
|
+
</UDropdownMenu>
|
|
383
|
+
</div>
|
|
384
|
+
|
|
385
|
+
<p class="text-sm text-gray-600 dark:text-gray-400">
|
|
386
|
+
{{ option.description }}
|
|
387
|
+
</p>
|
|
388
|
+
</UCard>
|
|
389
|
+
</div>
|
|
390
|
+
</div>
|
|
391
|
+
<div v-else class="mt-4">
|
|
392
|
+
<p class="text-sm text-gray-500 dark:text-gray-400">
|
|
393
|
+
No parameters defined for this command
|
|
394
|
+
</p>
|
|
395
|
+
</div>
|
|
396
|
+
|
|
397
|
+
<!-- Command Path -->
|
|
398
|
+
<template #footer>
|
|
399
|
+
<div class="space-y-1">
|
|
400
|
+
<div class="text-xs text-gray-500 flex gap-2 items-center dark:text-gray-400">
|
|
401
|
+
<UIcon name="i-heroicons-folder" class="h-4 w-4" />
|
|
402
|
+
<span>{{ command.path }}</span>
|
|
403
|
+
</div>
|
|
404
|
+
<div v-if="getRemoteId(command)" class="text-xs text-gray-500 flex gap-2 items-center dark:text-gray-400">
|
|
405
|
+
<UIcon name="i-heroicons-cloud" class="h-4 w-4" />
|
|
406
|
+
<span>Command ID: {{ getRemoteId(command) }}</span>
|
|
407
|
+
</div>
|
|
408
|
+
</div>
|
|
409
|
+
</template>
|
|
410
|
+
</UCard>
|
|
411
|
+
</div>
|
|
412
|
+
|
|
413
|
+
<!-- No Command -->
|
|
414
|
+
<UCard v-else class="py-12 text-center">
|
|
415
|
+
<div class="flex flex-col gap-4 items-center">
|
|
416
|
+
<UIcon name="i-heroicons-command-line" class="text-gray-400 h-12 w-12" />
|
|
417
|
+
<div>
|
|
418
|
+
<h3 class="text-lg text-gray-900 font-medium mb-2 dark:text-white">
|
|
419
|
+
No commands found
|
|
420
|
+
</h3>
|
|
421
|
+
<p class="text-gray-600 dark:text-gray-400">
|
|
422
|
+
Create your first slash command to get started
|
|
423
|
+
</p>
|
|
424
|
+
</div>
|
|
425
|
+
</div>
|
|
426
|
+
</UCard>
|
|
427
|
+
</div>
|
|
428
|
+
</UApp>
|
|
429
|
+
</template>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import '../style.css.js';
|
|
2
|
+
import './slash-commands.css.js';
|
|
3
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
4
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "tailwindcss";@import "@nuxt/ui";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { defineEventHandler, useDiscordClient } from "#imports";
|
|
2
|
+
export default defineEventHandler(async () => {
|
|
3
|
+
const client = useDiscordClient();
|
|
4
|
+
const commands = client.getSlashCommands();
|
|
5
|
+
return {
|
|
6
|
+
commands: commands.map(({ execute, load, ...command }) => command)
|
|
7
|
+
};
|
|
8
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { APIApplicationCommand } from 'discord.js';
|
|
2
|
+
import type { SlashCommand, SlashCommandRuntime } from '~/src/types';
|
|
3
|
+
declare const _default: import("h3").EventHandler<{
|
|
4
|
+
body?: {
|
|
5
|
+
commands?: SlashCommand[];
|
|
6
|
+
};
|
|
7
|
+
}, Promise<{
|
|
8
|
+
added: SlashCommandRuntime[];
|
|
9
|
+
removed: APIApplicationCommand[];
|
|
10
|
+
changed: {
|
|
11
|
+
local: SlashCommandRuntime;
|
|
12
|
+
remote: APIApplicationCommand;
|
|
13
|
+
}[];
|
|
14
|
+
synced: {
|
|
15
|
+
local: SlashCommandRuntime;
|
|
16
|
+
remote: APIApplicationCommand;
|
|
17
|
+
}[];
|
|
18
|
+
conflict: SlashCommandRuntime[];
|
|
19
|
+
}>>;
|
|
20
|
+
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useDiscordClient } from "#imports";
|
|
2
|
+
import { defineEventHandler, readBody } from "h3";
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const client = useDiscordClient();
|
|
5
|
+
const body = await readBody(event);
|
|
6
|
+
const diff = await client.diffRemoteSlashCommands(body?.commands);
|
|
7
|
+
return diff;
|
|
8
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import slashCommands from "discord/slashCommands";
|
|
2
|
+
import { defineNitroPlugin, useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
+
import { DiscordClient } from "../utils/client.js";
|
|
4
|
+
export default defineNitroPlugin(async (nitro) => {
|
|
5
|
+
const runtimeConfig = useRuntimeConfig();
|
|
6
|
+
const client = new DiscordClient();
|
|
7
|
+
globalThis[Symbol.for("discord-client")] = client;
|
|
8
|
+
if ("wsUrl" in (runtimeConfig.public.discord ?? {}) && typeof runtimeConfig.public.discord.wsUrl === "string") {
|
|
9
|
+
const socket = new WebSocket(runtimeConfig.public.discord.wsUrl);
|
|
10
|
+
socket.addEventListener("error", (error) => {
|
|
11
|
+
console.error("WebSocket error:", error);
|
|
12
|
+
});
|
|
13
|
+
socket.addEventListener("message", async (event) => {
|
|
14
|
+
const data = JSON.parse(event.data);
|
|
15
|
+
if (data.event === "full-update") {
|
|
16
|
+
const commands = [];
|
|
17
|
+
for (const cmd of data.commands) {
|
|
18
|
+
const runtimeCommand = cmd;
|
|
19
|
+
runtimeCommand.load = () => import(cmd.path).then((m) => m.default);
|
|
20
|
+
commands.push(runtimeCommand);
|
|
21
|
+
}
|
|
22
|
+
client.clearSlashCommands();
|
|
23
|
+
client.addSlashCommands(commands);
|
|
24
|
+
} else {
|
|
25
|
+
socket.send(JSON.stringify({ event: "full-update" }));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
nitro.hooks.hook("close", () => socket.close());
|
|
29
|
+
}
|
|
30
|
+
client.addSlashCommands(slashCommands);
|
|
31
|
+
if (runtimeConfig.discord.sync) {
|
|
32
|
+
await client.registerSlashCommands();
|
|
33
|
+
}
|
|
34
|
+
if (runtimeConfig.discord.autoStart) {
|
|
35
|
+
const options = { intents: runtimeConfig.discord.intents };
|
|
36
|
+
await client.start(options);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { APIApplicationCommand, ChatInputCommandInteraction, ClientOptions, RESTGetAPIApplicationCommandsResult, RESTPutAPIApplicationCommandsResult } from 'discord.js';
|
|
2
|
+
import type { SlashCommandRuntime } from '~/src/types';
|
|
3
|
+
import { Client as InternalClient } from 'discord.js';
|
|
4
|
+
export interface DiscordClientErrorBase {
|
|
5
|
+
type: string;
|
|
6
|
+
client: DiscordClient;
|
|
7
|
+
}
|
|
8
|
+
export interface UnknownSlashCommandError extends DiscordClientErrorBase {
|
|
9
|
+
type: 'UnknownSlashCommandError';
|
|
10
|
+
interaction: ChatInputCommandInteraction;
|
|
11
|
+
}
|
|
12
|
+
export interface MissingRequiredOptionError extends DiscordClientErrorBase {
|
|
13
|
+
type: 'MissingRequiredOptionError';
|
|
14
|
+
interaction: ChatInputCommandInteraction;
|
|
15
|
+
command: SlashCommandRuntime;
|
|
16
|
+
option: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SlashCommandExecutionError extends DiscordClientErrorBase {
|
|
19
|
+
type: 'SlashCommandExecutionError';
|
|
20
|
+
interaction: ChatInputCommandInteraction;
|
|
21
|
+
command: SlashCommandRuntime;
|
|
22
|
+
error: unknown;
|
|
23
|
+
}
|
|
24
|
+
export interface SlashCommandRegistrationError extends DiscordClientErrorBase {
|
|
25
|
+
type: 'SlashCommandRegistrationError';
|
|
26
|
+
error: unknown;
|
|
27
|
+
command?: SlashCommandRuntime;
|
|
28
|
+
}
|
|
29
|
+
export type DiscordClientError = UnknownSlashCommandError | MissingRequiredOptionError | SlashCommandExecutionError | SlashCommandRegistrationError;
|
|
30
|
+
export declare function useInteraction(): ChatInputCommandInteraction | null;
|
|
31
|
+
export declare class DiscordClient {
|
|
32
|
+
#private;
|
|
33
|
+
get internalClient(): InternalClient<boolean> | null;
|
|
34
|
+
constructor();
|
|
35
|
+
start(options: ClientOptions): Promise<undefined>;
|
|
36
|
+
stop(): Promise<void>;
|
|
37
|
+
isReady(): boolean;
|
|
38
|
+
addSlashCommand(command: SlashCommandRuntime): void;
|
|
39
|
+
addSlashCommands(commands: SlashCommandRuntime[]): void;
|
|
40
|
+
removeSlashCommand(name: string): void;
|
|
41
|
+
clearSlashCommands(): void;
|
|
42
|
+
getSlashCommands(): SlashCommandRuntime[];
|
|
43
|
+
getSlashCommand(name: string): SlashCommandRuntime | undefined;
|
|
44
|
+
getRemoteSlashCommands(): Promise<RESTGetAPIApplicationCommandsResult>;
|
|
45
|
+
diffRemoteSlashCommands(localCommands?: SlashCommandRuntime[], forceRefresh?: boolean): Promise<{
|
|
46
|
+
added: SlashCommandRuntime[];
|
|
47
|
+
removed: APIApplicationCommand[];
|
|
48
|
+
changed: {
|
|
49
|
+
local: SlashCommandRuntime;
|
|
50
|
+
remote: APIApplicationCommand;
|
|
51
|
+
}[];
|
|
52
|
+
synced: {
|
|
53
|
+
local: SlashCommandRuntime;
|
|
54
|
+
remote: APIApplicationCommand;
|
|
55
|
+
}[];
|
|
56
|
+
conflict: SlashCommandRuntime[];
|
|
57
|
+
}>;
|
|
58
|
+
registerSlashCommands(): Promise<RESTPutAPIApplicationCommandsResult | PromiseSettledResult<APIApplicationCommand>[]>;
|
|
59
|
+
}
|