nv-kit 1.0.2 → 1.0.4

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/ABOUT.md ADDED
@@ -0,0 +1,110 @@
1
+ # nv-kit
2
+
3
+ A beginner-friendly Discord.js command handler framework.
4
+
5
+ Install once. Build commands instantly.
6
+
7
+ ---
8
+
9
+ ## 📦 Installation
10
+
11
+ ```bash
12
+ npm install nv-kit
13
+ ```
14
+
15
+ ---
16
+
17
+ ## 🚀 What is nv-kit?
18
+
19
+ nv-kit is a structured command handler for Discord.js that simplifies:
20
+
21
+ - Slash commands
22
+ - Prefix (legacy) commands
23
+ - Cooldowns
24
+ - Permission checks
25
+ - Owner-only commands
26
+ - Test server restriction
27
+ - Optional MongoDB integration
28
+ - Built-in administrative utilities
29
+
30
+ It removes boilerplate so you can focus on writing commands.
31
+
32
+ ---
33
+
34
+ ## Handler
35
+
36
+ The handler automatically:
37
+
38
+ - Registers slash commands
39
+ - Handles interactions
40
+ - Parses arguments
41
+ - Applies cooldowns
42
+ - Validates permissions
43
+
44
+ ---
45
+
46
+ ## ⚙ Command Options
47
+
48
+ Each command may include:
49
+
50
+ - description
51
+ - type (SLASH | LEGACY | BOTH)
52
+ - guildOnly
53
+ - testOnly
54
+ - ownerOnly
55
+ - permissions
56
+ - minArgs / maxArgs
57
+ - expectedArgs
58
+ - correctSyntax
59
+ - aliases
60
+ - cooldowns
61
+ - deferReply
62
+ - init()
63
+ - callback()
64
+
65
+ ---
66
+
67
+ ## 🗂 Default Commands
68
+
69
+ nv-kit includes optional built-in commands:
70
+
71
+ - prefix
72
+ - togglecommand
73
+ - customcommand
74
+ - delcustomcmd
75
+ - requiredpermissions
76
+ - requiredroles
77
+ - channelcommand
78
+
79
+ Disable them during initialization:
80
+
81
+ ```js
82
+ new NV({
83
+ client,
84
+ disabledDefaultCommands: ["prefix", "togglecommand"]
85
+ });
86
+ ```
87
+
88
+ ---
89
+
90
+ ## 🗄 MongoDB
91
+
92
+ MongoDB is **required**! This is used for:
93
+
94
+ - Custom prefixes
95
+ - Custom commands
96
+ - Role requirements
97
+ - Command toggling
98
+ - Persistent guild settings
99
+
100
+ If you do not need dynamic configuration, Mongo can be removed with minor edits.
101
+
102
+ ---
103
+
104
+ ## 👤 Who Is This For?
105
+
106
+ - Beginners learning Discord.js
107
+ - Developers who want structure without complexity
108
+ - Bots growing beyond single-file scripts
109
+
110
+ ---
package/README.md CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nv-kit",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Beginner-friendly Discord.js command handler with slash/prefix commands, cooldowns, permissions, and optional MongoDB.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,59 @@
1
+ const fs = require("fs")
2
+ const path = require("path")
3
+
4
+ const getAllFiles = (dir) => {
5
+ const entries = fs.readdirSync(dir, { withFileTypes: true })
6
+ let files = []
7
+
8
+ for (const ent of entries) {
9
+ const full = path.join(dir, ent.name)
10
+ if (ent.isDirectory()) files = files.concat(getAllFiles(full))
11
+ else if (ent.isFile() && full.endsWith(".js")) files.push(full)
12
+ }
13
+
14
+ return files
15
+ }
16
+
17
+ class ButtonHandler {
18
+ constructor(instance, buttonsDir, client) {
19
+ this._instance = instance
20
+ this._client = client
21
+ this._buttons = new Map()
22
+
23
+ const abs = path.isAbsolute(buttonsDir)
24
+ ? buttonsDir
25
+ : path.join(process.cwd(), buttonsDir)
26
+
27
+ if (!fs.existsSync(abs)) {
28
+ console.warn(`[nv-kit] buttonsDir not found: ${abs}`)
29
+ return
30
+ }
31
+
32
+ const files = getAllFiles(abs)
33
+
34
+ for (const file of files) {
35
+ delete require.cache[require.resolve(file)]
36
+ const btn = require(file)
37
+
38
+ if (!btn || typeof btn !== "object") continue
39
+ if (!btn.id || typeof btn.id !== "string") {
40
+ console.warn(`[nv-kit] Button missing "id" in: ${file}`)
41
+ continue
42
+ }
43
+ if (typeof btn.callback !== "function") {
44
+ console.warn(`[nv-kit] Button missing "callback" in: ${file}`)
45
+ continue
46
+ }
47
+
48
+ this._buttons.set(btn.id, btn)
49
+ }
50
+
51
+ console.log(`[nv-kit] Loaded ${this._buttons.size} button handlers.`)
52
+ }
53
+
54
+ getButton(id) {
55
+ return this._buttons.get(id)
56
+ }
57
+ }
58
+
59
+ module.exports = ButtonHandler
@@ -1,3 +1,16 @@
1
- module.exports = (interaction) => {
2
- interaction.reply('testing')
3
- }
1
+ module.exports = async (instance, interaction, client) => {
2
+ const btn = instance.buttonHandler?.getButton(interaction.customId)
3
+ if (!btn) return
4
+
5
+ try {
6
+ await btn.callback({ interaction, client, instance })
7
+ } catch (e) {
8
+ console.error(`[nv-kit] Button handler error (${interaction.customId})`, e)
9
+
10
+ if (!interaction.replied && !interaction.deferred) {
11
+ await interaction
12
+ .reply({ content: "Button error.", ephemeral: true })
13
+ .catch(() => {})
14
+ }
15
+ }
16
+ }
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ const CommandHandler = require('./command-handler/CommandHandler')
4
4
  const Cooldowns = require('./util/Cooldowns')
5
5
  const EventHandler = require('./event-handler/EventHandler')
6
6
  const FeatureHandler = require('./util/FeatureHandler')
7
+ const ButtonHandler = require("./button-handler/ButtonHandler")
7
8
 
8
9
  class Main {
9
10
  constructor(obj) {
@@ -14,6 +15,7 @@ class Main {
14
15
  client,
15
16
  mongoUri,
16
17
  commandsDir,
18
+ buttonsDir,
17
19
  featuresDir,
18
20
  testServers = [],
19
21
  botOwners = [],
@@ -45,6 +47,10 @@ class Main {
45
47
  this._commandHandler = new CommandHandler(this, commandsDir, client)
46
48
  }
47
49
 
50
+ if (buttonsDir) {
51
+ this._buttonHandler = new ButtonHandler(this, buttonsDir, client)
52
+ }
53
+
48
54
  if (featuresDir) {
49
55
  new FeatureHandler(this, featuresDir, client)
50
56
  }
@@ -72,6 +78,10 @@ class Main {
72
78
  return this._commandHandler
73
79
  }
74
80
 
81
+ get buttonHandler() {
82
+ return this._buttonHandler
83
+ }
84
+
75
85
  get eventHandler() {
76
86
  return this._eventHandler
77
87
  }