commandkit 0.0.4 → 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/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
6
6
|
|
|
7
|
+
## [0.0.5] - 2023-07-02
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Ability to automatically update application commands (guilds and global) when there's changes to the description or number of options (slash commands only).
|
|
12
|
+
|
|
7
13
|
## [0.0.4] - 2023-07-01
|
|
8
14
|
|
|
9
15
|
### Updated
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ _Tested with Discord.js version `v14.11.0`_
|
|
|
8
8
|
|
|
9
9
|
- Very beginner friendly 🚀
|
|
10
10
|
- Support for slash and context menu commands ✅
|
|
11
|
-
- Automatic command
|
|
11
|
+
- Automatic command registration, edits, and deletion 🤖
|
|
12
12
|
- Supports multiple development servers 🤝
|
|
13
13
|
- Supports multiple users as bot developers 👥
|
|
14
14
|
- Object oriented 💻
|
package/dist/CommandKit.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class CommandKit {
|
|
|
9
9
|
name_localizations?: any;
|
|
10
10
|
description: string;
|
|
11
11
|
dm_permission?: boolean | undefined;
|
|
12
|
-
options
|
|
12
|
+
options?: import("discord.js").APIApplicationCommandOption[] | undefined;
|
|
13
13
|
};
|
|
14
14
|
options?: {
|
|
15
15
|
guildOnly?: boolean | undefined;
|
|
@@ -7,5 +7,6 @@ export declare class CommandHandler {
|
|
|
7
7
|
_buildCommands(): void;
|
|
8
8
|
_registerCommands(): void;
|
|
9
9
|
_handleCommands(): void;
|
|
10
|
+
_areSlashCommandsDifferent(appCommand: any, localCommand: any): true | undefined;
|
|
10
11
|
getCommands(): (SlashCommandObject | ContextCommandObject)[];
|
|
11
12
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandHandler = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
4
|
const get_paths_1 = require("../../utils/get-paths");
|
|
6
5
|
class CommandHandler {
|
|
7
6
|
_data;
|
|
@@ -54,28 +53,73 @@ class CommandHandler {
|
|
|
54
53
|
devGuildCommands.push(guildCommands);
|
|
55
54
|
}
|
|
56
55
|
for (const command of commands) {
|
|
57
|
-
const commandData = command.data;
|
|
58
|
-
if (commandData instanceof discord_js_1.SlashCommandBuilder ||
|
|
59
|
-
commandData instanceof discord_js_1.ContextMenuCommandBuilder) {
|
|
60
|
-
try {
|
|
61
|
-
commandData.toJSON();
|
|
62
|
-
}
|
|
63
|
-
catch (error) { }
|
|
64
|
-
}
|
|
65
56
|
// <!-- Delete command if options.deleted -->
|
|
66
57
|
if (command.options?.deleted) {
|
|
67
58
|
const targetCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
|
|
68
|
-
targetCommand
|
|
69
|
-
console.log(
|
|
70
|
-
}
|
|
59
|
+
if (!targetCommand) {
|
|
60
|
+
console.log(`⏩ Ignoring: Command "${command.data.name}" is globally marked as deleted.`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
targetCommand.delete().then(() => {
|
|
64
|
+
console.log(`🚮 Deleted command "${command.data.name}" globally.`);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
71
67
|
for (const guildCommands of devGuildCommands) {
|
|
72
68
|
const targetCommand = guildCommands.cache.find((cmd) => cmd.name === command.data.name);
|
|
73
|
-
targetCommand
|
|
74
|
-
console.log(
|
|
75
|
-
}
|
|
69
|
+
if (!targetCommand) {
|
|
70
|
+
console.log(`⏩ Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
targetCommand.delete().then(() => {
|
|
74
|
+
console.log(`🚮 Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
76
77
|
}
|
|
77
78
|
continue;
|
|
78
79
|
}
|
|
80
|
+
// <!-- Edit command if there's any changes -->
|
|
81
|
+
let commandData = command.data;
|
|
82
|
+
let editedCommand = false;
|
|
83
|
+
(() => {
|
|
84
|
+
// global
|
|
85
|
+
const appGlobalCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
|
|
86
|
+
if (appGlobalCommand) {
|
|
87
|
+
const commandsAreDifferent = this._areSlashCommandsDifferent(appGlobalCommand, commandData);
|
|
88
|
+
if (commandsAreDifferent) {
|
|
89
|
+
appGlobalCommand
|
|
90
|
+
.edit(commandData)
|
|
91
|
+
.then(() => {
|
|
92
|
+
console.log(`✅ Edited command "${commandData.name}" globally.`);
|
|
93
|
+
})
|
|
94
|
+
.catch((error) => {
|
|
95
|
+
console.log(`❌ Failed to edit command "${commandData.name}" globally.`);
|
|
96
|
+
console.error(error);
|
|
97
|
+
});
|
|
98
|
+
editedCommand = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// guilds
|
|
102
|
+
for (const guildCommands of devGuildCommands) {
|
|
103
|
+
const appGuildCommand = guildCommands.cache.find((cmd) => cmd.name === commandData.name);
|
|
104
|
+
if (appGuildCommand) {
|
|
105
|
+
const commandsAreDifferent = this._areSlashCommandsDifferent(appGuildCommand, commandData);
|
|
106
|
+
if (commandsAreDifferent) {
|
|
107
|
+
appGuildCommand
|
|
108
|
+
.edit(commandData)
|
|
109
|
+
.then(() => {
|
|
110
|
+
console.log(`✅ Edited command "${commandData.name}" in ${guildCommands.guild.name}.`);
|
|
111
|
+
})
|
|
112
|
+
.catch((error) => {
|
|
113
|
+
console.log(`❌ Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`);
|
|
114
|
+
console.error(error);
|
|
115
|
+
});
|
|
116
|
+
editedCommand = true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
if (editedCommand)
|
|
122
|
+
continue;
|
|
79
123
|
// <!-- Registration -->
|
|
80
124
|
// guild-based command registration
|
|
81
125
|
if (command.options?.devOnly) {
|
|
@@ -191,6 +235,20 @@ class CommandHandler {
|
|
|
191
235
|
}
|
|
192
236
|
});
|
|
193
237
|
}
|
|
238
|
+
_areSlashCommandsDifferent(appCommand, localCommand) {
|
|
239
|
+
if (!appCommand.options)
|
|
240
|
+
appCommand.options = [];
|
|
241
|
+
if (!localCommand.options)
|
|
242
|
+
localCommand.options = [];
|
|
243
|
+
if (!appCommand.description)
|
|
244
|
+
appCommand.description = '';
|
|
245
|
+
if (!localCommand.description)
|
|
246
|
+
localCommand.description = '';
|
|
247
|
+
if (localCommand.description !== appCommand.description ||
|
|
248
|
+
localCommand.options.length !== appCommand.options.length) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
194
252
|
getCommands() {
|
|
195
253
|
return this._data.commands;
|
|
196
254
|
}
|
package/package.json
CHANGED
package/typings.d.ts
CHANGED