nuxt-discord 0.0.15 → 0.0.16

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-discord",
3
3
  "configKey": "discord",
4
- "version": "0.0.15",
4
+ "version": "0.0.16",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
@@ -32,4 +32,5 @@ type ReplyFunction = SlashCommandCustomReturnHandler & {
32
32
  send: ReplyFunction;
33
33
  };
34
34
  export declare const reply: ReplyFunction;
35
+ export declare function deepToRaw<T extends Record<string, any>>(sourceObj: T): T;
35
36
  export {};
@@ -1,10 +1,9 @@
1
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
- } = {}) {
2
+ import { computed, isProxy, isReactive, isRef, reactive, toRaw, toValue, watch } from "vue";
3
+ import { logger } from "../../logger.js";
4
+ function createReplyFunction(defaultOptions = {}) {
7
5
  const reply2 = (...args) => {
6
+ const { buttons, ...restOptions } = defaultOptions;
8
7
  const buttonComponents = computed(() => getButtonComponent(buttons ?? []));
9
8
  let buttonInteractionCollectors = [];
10
9
  function registerButtonCollectors(msg) {
@@ -12,7 +11,7 @@ function createReplyFunction({
12
11
  collector.stop();
13
12
  }
14
13
  buttonInteractionCollectors = [];
15
- for (const [_, handler, options] of buttons ?? []) {
14
+ for (const [_, buttonHandler, options] of buttons ?? []) {
16
15
  let collectorOptions;
17
16
  if (options && "collector" in options && options.collector) {
18
17
  collectorOptions = options.collector;
@@ -31,7 +30,7 @@ function createReplyFunction({
31
30
  buttonInteractionCollectors[buttonInteractionCollectors.length - 1].on("collect", async (buttonInteraction) => {
32
31
  if (options?.defer ?? true)
33
32
  buttonInteraction.deferUpdate();
34
- await handler(buttonInteraction);
33
+ await buttonHandler(buttonInteraction);
35
34
  });
36
35
  }
37
36
  }
@@ -41,17 +40,19 @@ function createReplyFunction({
41
40
  const replyOptions = reactive({
42
41
  content: text,
43
42
  ...buttonComponents.value.length > 0 ? { components: buttonComponents } : {},
44
- ...defaultOptions,
43
+ ...restOptions,
45
44
  ...options
46
45
  });
47
46
  const handler = (interaction) => {
48
47
  const method = interaction.replied ? "followUp" : interaction.deferred ? "editReply" : "reply";
49
- message = interaction[method](
50
- replyOptions
51
- ).then((msg) => {
48
+ const opts = deepToRaw(replyOptions);
49
+ message = interaction[method](opts).then((msg) => {
52
50
  registerButtonCollectors(msg);
53
51
  return msg;
54
- }).catch((err) => err);
52
+ }).catch((err) => {
53
+ logger.error(err);
54
+ return err;
55
+ });
55
56
  return message;
56
57
  };
57
58
  Object.defineProperty(handler, Symbol.iterator, {
@@ -66,28 +67,35 @@ function createReplyFunction({
66
67
  })
67
68
  });
68
69
  watch(replyOptions, async (options2) => {
69
- const msg = await message;
70
- if ("edit" in msg)
71
- msg.edit(options2);
70
+ let msg = await message;
71
+ if ("resource" in msg)
72
+ msg = await msg.resource.message.edit(deepToRaw(options2));
72
73
  else
73
- msg.resource?.message?.edit(options2);
74
+ msg = await msg.edit(deepToRaw(options2));
74
75
  registerButtonCollectors(msg);
75
76
  }, { deep: true, flush: "sync" });
76
77
  return handler;
77
78
  } else {
78
79
  const interaction = args[0];
79
80
  const method = interaction.replied ? "followUp" : interaction.deferred ? "editReply" : "reply";
80
- const options = reactive(defaultOptions);
81
- const messagePromise = interaction[method](options).catch((err) => err);
81
+ const options = reactive({
82
+ ...buttonComponents.value.length > 0 ? { components: buttonComponents } : {},
83
+ ...restOptions
84
+ });
85
+ const messagePromise = interaction[method](deepToRaw(options)).then((msg) => {
86
+ registerButtonCollectors(msg);
87
+ return msg;
88
+ }).catch((err) => {
89
+ logger.error(err);
90
+ return err;
91
+ });
82
92
  watch(options, async (opts) => {
83
- const message = await messagePromise;
84
- if (!message)
85
- return;
86
- if ("edit" in message)
87
- message.edit(opts);
93
+ let msg = await messagePromise;
94
+ if ("resource" in msg)
95
+ msg = await msg.resource.message.edit(deepToRaw(opts));
88
96
  else
89
- message.resource?.message?.edit(opts);
90
- registerButtonCollectors(message);
97
+ msg = await msg.edit(deepToRaw(opts));
98
+ registerButtonCollectors(msg);
91
99
  }, { deep: true, flush: "sync" });
92
100
  return {
93
101
  [Symbol.iterator]: () => ({
@@ -134,7 +142,7 @@ function createReplyFunction({
134
142
  return createReplyFunction({
135
143
  ...defaultOptions,
136
144
  buttons: [
137
- ...buttons ?? [],
145
+ ...defaultOptions.buttons ?? [],
138
146
  args
139
147
  ]
140
148
  });
@@ -149,7 +157,7 @@ function getButtonComponent(buttons) {
149
157
  return [];
150
158
  let row = new ActionRowBuilder();
151
159
  const rows = [row];
152
- const it = Iterator.from(buttons).filter(([, , options]) => !(toValue(options?.hide) ?? false)).map(([label, , options]) => {
160
+ const it = Iterator.from(buttons).filter(([, , options]) => !toValue(options?.hide ?? false)).map(([label, , options]) => {
153
161
  if (options == null) {
154
162
  options = {};
155
163
  }
@@ -158,7 +166,7 @@ function getButtonComponent(buttons) {
158
166
  }
159
167
  if (options.style === ButtonStyle.Primary) {
160
168
  if (!("customId" in options) || options.customId == null) {
161
- options.customId = `${Date.now()}`;
169
+ options.customId = `button-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
162
170
  }
163
171
  }
164
172
  return new ButtonBuilder(
@@ -172,7 +180,7 @@ function getButtonComponent(buttons) {
172
180
  );
173
181
  });
174
182
  for (let i = 0; i < 5; i++) {
175
- row.addComponents(...Array.from(it.take(5)));
183
+ row.addComponents(...it.take(5));
176
184
  if (row.components.length >= 5) {
177
185
  row = new ActionRowBuilder();
178
186
  rows.push(row);
@@ -182,3 +190,29 @@ function getButtonComponent(buttons) {
182
190
  rows.pop();
183
191
  return rows;
184
192
  }
193
+ export function deepToRaw(sourceObj) {
194
+ const cycleDetector = /* @__PURE__ */ new WeakSet();
195
+ const objectIterator = (input) => {
196
+ if (cycleDetector.has(input)) {
197
+ return input;
198
+ }
199
+ if (Array.isArray(input)) {
200
+ cycleDetector.add(input);
201
+ return input.map((item) => objectIterator(item));
202
+ }
203
+ if (isRef(input) || isReactive(input) || isProxy(input)) {
204
+ cycleDetector.add(input);
205
+ return objectIterator(isRef(input) ? toValue(input) : toRaw(input));
206
+ }
207
+ if (input && typeof input === "object") {
208
+ cycleDetector.add(input);
209
+ const copy = Object.fromEntries(
210
+ Object.entries(input).map(([key, value]) => [key, objectIterator(value)])
211
+ );
212
+ Object.setPrototypeOf(copy, Object.getPrototypeOf(input));
213
+ return copy;
214
+ }
215
+ return input;
216
+ };
217
+ return objectIterator(sourceObj);
218
+ }
@@ -0,0 +1,9 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.mjs'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default, type slashCommandOptionTypeIdentifiers, type typeIdentifierToEnum } from './module.mjs'
8
+
9
+ export { type DiscordRuntimeConfig, type NuxtDiscordContext, type NuxtDiscordOptions, type SlashCommand, type SlashCommandBooleanOption, type SlashCommandCustomReturnHandler, type SlashCommandIntegerOption, type SlashCommandNumberOption, type SlashCommandOption, type SlashCommandOptionBase, type SlashCommandOptionType, type SlashCommandOptionTypeIdentifier, type SlashCommandReturnType, type SlashCommandRuntime, type SlashCommandStringOption, type integer } from './module.mjs'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-discord",
3
3
  "type": "module",
4
- "version": "0.0.15",
4
+ "version": "0.0.16",
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",
@@ -16,7 +16,11 @@
16
16
  ".": {
17
17
  "types": "./dist/module.d.mts",
18
18
  "import": "./dist/module.mjs"
19
- }
19
+ },
20
+ "./types": {
21
+ "types": "./dist/types.d.mts"
22
+ },
23
+ "./*": "./*"
20
24
  },
21
25
  "main": "./dist/module.mjs",
22
26
  "types": "./dist/module.d.mts",
@@ -34,32 +38,32 @@
34
38
  "discord.js": "^14.21.0"
35
39
  },
36
40
  "dependencies": {
37
- "@nuxt/kit": "^3.17.6",
41
+ "@nuxt/kit": "^3.17.7",
38
42
  "@nuxt/ui": "^3.2.0",
39
43
  "ansis": "^4.1.0",
40
44
  "chokidar": "^4.0.3",
41
45
  "defu": "^6.1.4",
42
46
  "knitwork": "^1.2.0",
43
47
  "listhen": "^1.9.0",
44
- "rollup": "^4.45.0",
45
- "simple-icons": "^15.5.0",
48
+ "rollup": "^4.45.1",
49
+ "simple-icons": "^15.6.0",
46
50
  "unocss": "^66.3.3",
47
51
  "ws": "^8.18.3"
48
52
  },
49
53
  "devDependencies": {
50
- "@antfu/eslint-config": "^4.16.2",
54
+ "@antfu/eslint-config": "^4.17.0",
51
55
  "@nuxt/devtools": "^2.6.2",
52
- "@nuxt/eslint-config": "^1.5.2",
56
+ "@nuxt/eslint-config": "^1.6.0",
53
57
  "@nuxt/module-builder": "^1.0.1",
54
- "@nuxt/schema": "^3.17.6",
58
+ "@nuxt/schema": "^3.17.7",
55
59
  "@nuxt/test-utils": "^3.19.2",
56
- "@types/node": "^24.0.13",
60
+ "@types/node": "^24.0.15",
57
61
  "@unocss/eslint-plugin": "^66.3.3",
58
62
  "@vueuse/core": "^13.5.0",
59
63
  "changelogen": "^0.6.2",
60
64
  "eslint": "^9.31.0",
61
65
  "lint-staged": "^16.1.2",
62
- "nuxt": "^3.17.6",
66
+ "nuxt": "^3.17.7",
63
67
  "simple-git-hooks": "^2.13.0",
64
68
  "typescript": "~5.8.3",
65
69
  "unbuild": "^3.5.0",
@@ -77,6 +81,7 @@
77
81
  },
78
82
  "scripts": {
79
83
  "dev": "pnpm run dev:prepare && nuxi dev playground",
84
+ "dev:debug": "pnpm run dev:prepare && NODE_OPTIONS='--inspect' nuxi dev playground",
80
85
  "dev:build": "nuxi build playground",
81
86
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
82
87
  "release": "pnpm run lint && pnpm run test && pnpm run prepack && changelogen --release && pnpm publish && git push --follow-tags",