nuxt-discord 0.0.3 → 0.0.5

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 CHANGED
@@ -10,7 +10,6 @@ A Nuxt module for building Discord bots with slash commands, featuring hot modul
10
10
 
11
11
  - 🤖 **Discord Bot Integration** - Seamlessly integrate Discord.js with your Nuxt application
12
12
  - ⚡ **Slash Commands** - Type-safe slash command definitions with automatic registration
13
- - 🔥 **Hot Module Replacement** - Real-time command updates during development
14
13
  - 🎯 **Auto-sync** - Automatically sync commands with Discord's servers
15
14
  - 🖥️ **Web Interface** - Beautiful UI for managing and viewing slash commands
16
15
  - 🔄 **Real-time Updates** - WebSocket-based live updates in development
@@ -20,7 +19,7 @@ A Nuxt module for building Discord bots with slash commands, featuring hot modul
20
19
  Install the module to your Nuxt application:
21
20
 
22
21
  ```bash
23
- npm install nuxt-discord discord.js
22
+ pnpm install nuxt-discord discord.js
24
23
  ```
25
24
 
26
25
  Add the module to your `nuxt.config.ts`:
@@ -66,6 +65,8 @@ export default function ping() {
66
65
  }
67
66
  ```
68
67
 
68
+ Defining a command this way this module automatically deduces the name and description from the JSDoc comments. The command name is inferred following this set of priorities: `describeCommand` macro > `@name` JSDoc tag > function name > file name.
69
+
69
70
  ### Commands with Parameters
70
71
 
71
72
  ```ts
@@ -276,7 +277,7 @@ Here's what's planned for future releases:
276
277
  - [@nuxt/content](https://github.com/nuxt/content)
277
278
  - [@nuxtjs/i18n](https://github.com/nuxt-modules/i18n)
278
279
  - [@nuxt/devtools](https://github.com/nuxt/devtools)
279
- - UI components are based on [Nuxt UI](https://nuxtui.com) and [UnoCSS](https://unocss.dev/)
280
+ - UI components are based on [Nuxt UI](https://ui.nuxt.com/) and [UnoCSS](https://unocss.dev/)
280
281
 
281
282
  ## License
282
283
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-discord",
3
3
  "configKey": "discord",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
package/dist/module.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { useLogger, createResolver, installModule, extendPages, updateTemplates, addVitePlugin, isIgnored, addServerTemplate, addTemplate, addTypeTemplate, defineNuxtModule, addServerScanDir, addImports } from '@nuxt/kit';
2
2
  import { ApplicationCommandOptionType, GatewayIntentBits } from 'discord.js';
3
3
  import { globSync, readFileSync, existsSync, writeFileSync } from 'node:fs';
4
+ import path from 'node:path';
4
5
  import ts from 'typescript';
5
6
  import { listen } from 'listhen';
6
7
  import { WebSocketServer } from 'ws';
@@ -171,9 +172,11 @@ function processCommandFile(ctx, file) {
171
172
  ctx.logger.warn(`No command definition found for ${file}`);
172
173
  return;
173
174
  }
175
+ const { name } = path.parse(file);
174
176
  const command = {
175
177
  path: file,
176
- options: []
178
+ options: [],
179
+ name
177
180
  };
178
181
  if ((ts.isFunctionDeclaration(commandDefinition) || ts.isFunctionExpression(commandDefinition)) && !!commandDefinition.name && ts.isIdentifier(commandDefinition.name) && commandDefinition.name.escapedText) {
179
182
  command.name = commandDefinition.name.escapedText;
@@ -188,15 +191,15 @@ function processCommandFile(ctx, file) {
188
191
  return;
189
192
  }
190
193
  for (const param of commandDefinition.parameters) {
191
- const name = param.name.getText(sourceFile);
194
+ const name2 = param.name.getText(sourceFile);
192
195
  let type = param.type?.getText(sourceFile);
193
196
  if (!type || !(type in typeIdentifierToEnum)) {
194
- ctx.logger.warn(`Unknown slash command option type: ${type} for parameter ${name} in ${file}, defaulting to string`);
197
+ ctx.logger.warn(`Unknown slash command option type: ${type} for parameter ${name2} in ${file}, defaulting to string`);
195
198
  type = "string";
196
199
  }
197
- const jsdocDescription = jsDocTags.find((tag) => ts.isJSDocParameterTag(tag) && tag.name.getText() === name)?.comment?.toString() ?? "";
200
+ const jsdocDescription = jsDocTags.find((tag) => ts.isJSDocParameterTag(tag) && tag.name.getText() === name2)?.comment?.toString() ?? "";
198
201
  command.options.push({
199
- name,
202
+ name: name2,
200
203
  // TODO: remove this type assertion
201
204
  type: typeIdentifierToEnum[type],
202
205
  description: jsdocDescription,
@@ -1,4 +1,3 @@
1
- import slashCommands from "discord/slashCommands";
2
1
  import { defineNitroPlugin, useRuntimeConfig } from "nitropack/runtime";
3
2
  import { DiscordClient } from "../utils/client.js";
4
3
  export default defineNitroPlugin(async (nitro) => {
@@ -25,9 +24,11 @@ export default defineNitroPlugin(async (nitro) => {
25
24
  socket.send(JSON.stringify({ event: "full-update" }));
26
25
  }
27
26
  });
27
+ socket.addEventListener("open", () => {
28
+ socket.send(JSON.stringify({ event: "full-update" }));
29
+ });
28
30
  nitro.hooks.hook("close", () => socket.close());
29
31
  }
30
- client.addSlashCommands(slashCommands);
31
32
  if (runtimeConfig.discord.sync) {
32
33
  await client.registerSlashCommands();
33
34
  }
@@ -336,7 +336,6 @@ export class DiscordClient {
336
336
  })
337
337
  );
338
338
  results.forEach((result, i) => {
339
- logger.log(result);
340
339
  if (result.status === "rejected") {
341
340
  this.#nitro.hooks.callHook("discord:client:error", {
342
341
  type: "SlashCommandRegistrationError",
@@ -363,7 +362,7 @@ function propsEqual(a, b, props) {
363
362
  return true;
364
363
  }
365
364
  function optionEqual(a, b) {
366
- if (a.name !== b.name || a.description !== b.description || a.required !== b.required || a.type !== b.type) {
365
+ if (a.name !== b.name || a.description !== b.description || a.required !== !!b.required || a.type !== b.type) {
367
366
  return false;
368
367
  }
369
368
  if (!!("choices" in a && a.choices) !== !!("choices" in b && b.choices)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-discord",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
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",
@@ -77,11 +77,10 @@
77
77
  "dev": "pnpm run dev:prepare && nuxi dev playground",
78
78
  "dev:build": "nuxi build playground",
79
79
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
80
- "release": "pnpm run lint && pnpm run test && pnpm run prepack && changelogen --release && pnpm publish --force && git push --follow-tags",
80
+ "release": "pnpm run lint && pnpm run test && pnpm run prepack && changelogen --release && pnpm publish && git push --follow-tags",
81
81
  "lint": "eslint .",
82
82
  "test": "vitest run",
83
83
  "test:watch": "vitest watch",
84
- "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
85
- "postinstall": "npx simple-git-hooks"
84
+ "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
86
85
  }
87
86
  }