nuxt-discord 0.0.14 → 0.0.15
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.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createResolver, installModule, extendPages, updateTemplates, addVitePlugin, isIgnored, addServerTemplate, addTemplate, addTypeTemplate, defineNuxtModule, addServerScanDir, addImports } from '@nuxt/kit';
|
|
1
|
+
import { createResolver, installModule, extendPages, updateTemplates, addVitePlugin, isIgnored, resolveAlias, addServerTemplate, addTemplate, addTypeTemplate, defineNuxtModule, addServerScanDir, addImports } from '@nuxt/kit';
|
|
2
2
|
import { ApplicationCommandOptionType, GatewayIntentBits } from 'discord.js';
|
|
3
3
|
import { logger } from '../dist/runtime/logger.js';
|
|
4
4
|
import fs, { globSync, readFileSync } from 'node:fs';
|
|
@@ -629,8 +629,17 @@ async function generateDynamicCommandBuild(file, config, ctx) {
|
|
|
629
629
|
bundle = await rollup({
|
|
630
630
|
...config,
|
|
631
631
|
input: file,
|
|
632
|
-
|
|
633
|
-
|
|
632
|
+
plugins: [
|
|
633
|
+
config.plugins,
|
|
634
|
+
{
|
|
635
|
+
name: "discord:resolve-alias-and-externalize",
|
|
636
|
+
resolveId: (id) => {
|
|
637
|
+
if (!id.includes(file) && !id.endsWith(".ts")) {
|
|
638
|
+
return { id: resolveAlias(id), external: true };
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
]
|
|
634
643
|
});
|
|
635
644
|
const { output } = await bundle.generate({ ...config.output, sourcemap: false });
|
|
636
645
|
fs.mkdirSync(path.join(ctx.nuxt.options.buildDir, "discord", "commands"), { recursive: true });
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, ref, useFetch, useRuntimeConfig, watchEffect } from "#imports";
|
|
3
3
|
import { useWebSocket } from "@vueuse/core";
|
|
4
|
-
import slashCommands from "discord/slashCommands";
|
|
5
4
|
import TheHeader from "../components/TheHeader.vue";
|
|
6
5
|
import "../style.css";
|
|
7
6
|
import "./slash-commands.css";
|
|
@@ -70,7 +69,7 @@ function getRemoteId(command) {
|
|
|
70
69
|
}
|
|
71
70
|
return void 0;
|
|
72
71
|
}
|
|
73
|
-
const commands = ref(
|
|
72
|
+
const commands = ref([]);
|
|
74
73
|
const {
|
|
75
74
|
data: diff,
|
|
76
75
|
refresh: refreshDiff
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import type { BaseMessageOptions, InteractionCallbackResponse, InteractionReplyOptions, InteractionResponse, Message } from 'discord.js';
|
|
1
|
+
import type { BaseMessageOptions, ButtonComponentData, ButtonInteraction, InteractionCallbackResponse, InteractionReplyOptions, InteractionResponse, Message, MessageCollectorOptionsParams } from 'discord.js';
|
|
2
2
|
import type { MaybeRef } from 'vue';
|
|
3
3
|
import type { SlashCommandCustomReturnHandler } from '../../../types.js';
|
|
4
|
+
import { ComponentType } from 'discord.js';
|
|
4
5
|
type OmitPreservingCallSignature<T, K extends keyof T = keyof T> = Omit<T, K> & (T extends (...args: infer R) => infer S ? (...args: R) => S : unknown);
|
|
5
6
|
type File = NonNullable<BaseMessageOptions['files']>[number];
|
|
7
|
+
type ButtonCollectorOptions = Partial<Omit<MessageCollectorOptionsParams<ComponentType.Button>, 'componentType'>>;
|
|
8
|
+
type MaybeRefObject<T> = T extends any ? {
|
|
9
|
+
[K in keyof T]: MaybeRef<T[K]>;
|
|
10
|
+
} : never;
|
|
11
|
+
type DistributiveOmit<T, K extends keyof T> = T extends any ? Omit<T, K> : never;
|
|
6
12
|
type ReplyFunction = SlashCommandCustomReturnHandler & {
|
|
7
13
|
(text?: MaybeRef<string>, options?: InteractionReplyOptions): SlashCommandCustomReturnHandler & {
|
|
8
14
|
[Symbol.iterator]: () => {
|
|
@@ -16,6 +22,13 @@ type ReplyFunction = SlashCommandCustomReturnHandler & {
|
|
|
16
22
|
flags: (flags: MaybeRef<InteractionReplyOptions['flags']>) => ReplyFunction;
|
|
17
23
|
file: (file: MaybeRef<File>) => ReplyFunction;
|
|
18
24
|
files: (files: MaybeRef<File[]>) => ReplyFunction;
|
|
25
|
+
button: {
|
|
26
|
+
(label: MaybeRef<string>, handler: (interaction: ButtonInteraction) => void | Promise<void>, options?: Partial<MaybeRefObject<DistributiveOmit<ButtonComponentData, 'label' | 'type'>>> & {
|
|
27
|
+
defer?: boolean;
|
|
28
|
+
hide?: MaybeRef<boolean>;
|
|
29
|
+
collector?: ButtonCollectorOptions;
|
|
30
|
+
}): ReplyFunction;
|
|
31
|
+
};
|
|
19
32
|
send: ReplyFunction;
|
|
20
33
|
};
|
|
21
34
|
export declare const reply: ReplyFunction;
|
|
@@ -1,12 +1,46 @@
|
|
|
1
|
-
import { MessageFlags } from "discord.js";
|
|
2
|
-
import { isRef, reactive, watch } from "vue";
|
|
3
|
-
function createReplyFunction({
|
|
1
|
+
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, MessageFlags } from "discord.js";
|
|
2
|
+
import { computed, isRef, reactive, toValue, watch } from "vue";
|
|
3
|
+
function createReplyFunction({
|
|
4
|
+
buttons,
|
|
5
|
+
...defaultOptions
|
|
6
|
+
} = {}) {
|
|
4
7
|
const reply2 = (...args) => {
|
|
5
|
-
|
|
8
|
+
const buttonComponents = computed(() => getButtonComponent(buttons ?? []));
|
|
9
|
+
let buttonInteractionCollectors = [];
|
|
10
|
+
function registerButtonCollectors(msg) {
|
|
11
|
+
for (const collector of buttonInteractionCollectors) {
|
|
12
|
+
collector.stop();
|
|
13
|
+
}
|
|
14
|
+
buttonInteractionCollectors = [];
|
|
15
|
+
for (const [_, handler, options] of buttons ?? []) {
|
|
16
|
+
let collectorOptions;
|
|
17
|
+
if (options && "collector" in options && options.collector) {
|
|
18
|
+
collectorOptions = options.collector;
|
|
19
|
+
}
|
|
20
|
+
if ("resource" in msg) {
|
|
21
|
+
buttonInteractionCollectors.push(msg.resource.message.createMessageComponentCollector({
|
|
22
|
+
componentType: ComponentType.Button,
|
|
23
|
+
...collectorOptions
|
|
24
|
+
}));
|
|
25
|
+
} else {
|
|
26
|
+
buttonInteractionCollectors.push(msg.createMessageComponentCollector({
|
|
27
|
+
componentType: ComponentType.Button,
|
|
28
|
+
...collectorOptions
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
buttonInteractionCollectors[buttonInteractionCollectors.length - 1].on("collect", async (buttonInteraction) => {
|
|
32
|
+
if (options?.defer ?? true)
|
|
33
|
+
buttonInteraction.deferUpdate();
|
|
34
|
+
await handler(buttonInteraction);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (typeof args[0] === "string" || typeof args[0] === "undefined" || isRef(args[0])) {
|
|
6
39
|
const [text, options] = args;
|
|
7
40
|
let message;
|
|
8
41
|
const replyOptions = reactive({
|
|
9
42
|
content: text,
|
|
43
|
+
...buttonComponents.value.length > 0 ? { components: buttonComponents } : {},
|
|
10
44
|
...defaultOptions,
|
|
11
45
|
...options
|
|
12
46
|
});
|
|
@@ -14,7 +48,10 @@ function createReplyFunction({ ...defaultOptions } = {}) {
|
|
|
14
48
|
const method = interaction.replied ? "followUp" : interaction.deferred ? "editReply" : "reply";
|
|
15
49
|
message = interaction[method](
|
|
16
50
|
replyOptions
|
|
17
|
-
).
|
|
51
|
+
).then((msg) => {
|
|
52
|
+
registerButtonCollectors(msg);
|
|
53
|
+
return msg;
|
|
54
|
+
}).catch((err) => err);
|
|
18
55
|
return message;
|
|
19
56
|
};
|
|
20
57
|
Object.defineProperty(handler, Symbol.iterator, {
|
|
@@ -34,6 +71,7 @@ function createReplyFunction({ ...defaultOptions } = {}) {
|
|
|
34
71
|
msg.edit(options2);
|
|
35
72
|
else
|
|
36
73
|
msg.resource?.message?.edit(options2);
|
|
74
|
+
registerButtonCollectors(msg);
|
|
37
75
|
}, { deep: true, flush: "sync" });
|
|
38
76
|
return handler;
|
|
39
77
|
} else {
|
|
@@ -49,6 +87,7 @@ function createReplyFunction({ ...defaultOptions } = {}) {
|
|
|
49
87
|
message.edit(opts);
|
|
50
88
|
else
|
|
51
89
|
message.resource?.message?.edit(opts);
|
|
90
|
+
registerButtonCollectors(message);
|
|
52
91
|
}, { deep: true, flush: "sync" });
|
|
53
92
|
return {
|
|
54
93
|
[Symbol.iterator]: () => ({
|
|
@@ -70,33 +109,76 @@ function createReplyFunction({ ...defaultOptions } = {}) {
|
|
|
70
109
|
}
|
|
71
110
|
},
|
|
72
111
|
flags: {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
}
|
|
112
|
+
value: (flags) => createReplyFunction({
|
|
113
|
+
...defaultOptions,
|
|
114
|
+
flags
|
|
115
|
+
})
|
|
79
116
|
},
|
|
80
117
|
file: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
}
|
|
118
|
+
value: (file) => createReplyFunction({
|
|
119
|
+
...defaultOptions,
|
|
120
|
+
files: defaultOptions.files != null ? [...defaultOptions.files, file] : [file]
|
|
121
|
+
})
|
|
87
122
|
},
|
|
88
123
|
files: {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
94
|
-
}
|
|
124
|
+
value: (files) => createReplyFunction({
|
|
125
|
+
...defaultOptions,
|
|
126
|
+
files: defaultOptions.files != null ? [...defaultOptions.files, ...files] : files
|
|
127
|
+
})
|
|
95
128
|
},
|
|
96
129
|
send: {
|
|
97
130
|
value: reply2
|
|
131
|
+
},
|
|
132
|
+
button: {
|
|
133
|
+
value: (...args) => {
|
|
134
|
+
return createReplyFunction({
|
|
135
|
+
...defaultOptions,
|
|
136
|
+
buttons: [
|
|
137
|
+
...buttons ?? [],
|
|
138
|
+
args
|
|
139
|
+
]
|
|
140
|
+
});
|
|
141
|
+
}
|
|
98
142
|
}
|
|
99
143
|
});
|
|
100
144
|
return reply2;
|
|
101
145
|
}
|
|
102
146
|
export const reply = createReplyFunction();
|
|
147
|
+
function getButtonComponent(buttons) {
|
|
148
|
+
if (buttons.length === 0)
|
|
149
|
+
return [];
|
|
150
|
+
let row = new ActionRowBuilder();
|
|
151
|
+
const rows = [row];
|
|
152
|
+
const it = Iterator.from(buttons).filter(([, , options]) => !(toValue(options?.hide) ?? false)).map(([label, , options]) => {
|
|
153
|
+
if (options == null) {
|
|
154
|
+
options = {};
|
|
155
|
+
}
|
|
156
|
+
if (toValue(options.style) == null) {
|
|
157
|
+
options.style = ButtonStyle.Primary;
|
|
158
|
+
}
|
|
159
|
+
if (options.style === ButtonStyle.Primary) {
|
|
160
|
+
if (!("customId" in options) || options.customId == null) {
|
|
161
|
+
options.customId = `${Date.now()}`;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return new ButtonBuilder(
|
|
165
|
+
Object.fromEntries(
|
|
166
|
+
Object.entries({
|
|
167
|
+
label,
|
|
168
|
+
...options,
|
|
169
|
+
type: ComponentType.Button
|
|
170
|
+
}).map(([key, value]) => [key, toValue(value)])
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
for (let i = 0; i < 5; i++) {
|
|
175
|
+
row.addComponents(...Array.from(it.take(5)));
|
|
176
|
+
if (row.components.length >= 5) {
|
|
177
|
+
row = new ActionRowBuilder();
|
|
178
|
+
rows.push(row);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (row.components.length === 0)
|
|
182
|
+
rows.pop();
|
|
183
|
+
return rows;
|
|
184
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-discord",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.15",
|
|
5
5
|
"description": "A Nuxt module for building Discord bots",
|
|
6
6
|
"author": "Jize Zou <jeffzou2001@gmail.com> (https://github.com/zojize)",
|
|
7
7
|
"license": "MIT",
|
|
@@ -34,37 +34,37 @@
|
|
|
34
34
|
"discord.js": "^14.21.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nuxt/kit": "^3.17.
|
|
37
|
+
"@nuxt/kit": "^3.17.6",
|
|
38
38
|
"@nuxt/ui": "^3.2.0",
|
|
39
39
|
"ansis": "^4.1.0",
|
|
40
40
|
"chokidar": "^4.0.3",
|
|
41
41
|
"defu": "^6.1.4",
|
|
42
42
|
"knitwork": "^1.2.0",
|
|
43
43
|
"listhen": "^1.9.0",
|
|
44
|
-
"rollup": "^4.
|
|
45
|
-
"simple-icons": "^15.
|
|
46
|
-
"unocss": "^66.3.
|
|
47
|
-
"ws": "^8.18.
|
|
44
|
+
"rollup": "^4.45.0",
|
|
45
|
+
"simple-icons": "^15.5.0",
|
|
46
|
+
"unocss": "^66.3.3",
|
|
47
|
+
"ws": "^8.18.3"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@antfu/eslint-config": "^4.16.
|
|
51
|
-
"@nuxt/devtools": "^2.
|
|
52
|
-
"@nuxt/eslint-config": "^1.
|
|
50
|
+
"@antfu/eslint-config": "^4.16.2",
|
|
51
|
+
"@nuxt/devtools": "^2.6.2",
|
|
52
|
+
"@nuxt/eslint-config": "^1.5.2",
|
|
53
53
|
"@nuxt/module-builder": "^1.0.1",
|
|
54
|
-
"@nuxt/schema": "^3.17.
|
|
55
|
-
"@nuxt/test-utils": "^3.19.
|
|
56
|
-
"@types/node": "^24.0.
|
|
57
|
-
"@unocss/eslint-plugin": "^66.3.
|
|
58
|
-
"@vueuse/core": "^13.
|
|
59
|
-
"changelogen": "^0.6.
|
|
60
|
-
"eslint": "^9.
|
|
54
|
+
"@nuxt/schema": "^3.17.6",
|
|
55
|
+
"@nuxt/test-utils": "^3.19.2",
|
|
56
|
+
"@types/node": "^24.0.13",
|
|
57
|
+
"@unocss/eslint-plugin": "^66.3.3",
|
|
58
|
+
"@vueuse/core": "^13.5.0",
|
|
59
|
+
"changelogen": "^0.6.2",
|
|
60
|
+
"eslint": "^9.31.0",
|
|
61
61
|
"lint-staged": "^16.1.2",
|
|
62
|
-
"nuxt": "^3.17.
|
|
62
|
+
"nuxt": "^3.17.6",
|
|
63
63
|
"simple-git-hooks": "^2.13.0",
|
|
64
64
|
"typescript": "~5.8.3",
|
|
65
65
|
"unbuild": "^3.5.0",
|
|
66
66
|
"vitest": "^3.2.4",
|
|
67
|
-
"vue-tsc": "^2.2.
|
|
67
|
+
"vue-tsc": "^2.2.12"
|
|
68
68
|
},
|
|
69
69
|
"resolutions": {
|
|
70
70
|
"nuxt-discord": "workspace:*"
|