Skip to content

Commit decb154

Browse files
authored
Merge pull request #2 from underctrl-io/0.0.9
0.0.9
2 parents 29bab56 + 3ddba32 commit decb154

File tree

22 files changed

+810
-715
lines changed

22 files changed

+810
-715
lines changed

.github/workflows/publish.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'publish'
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
release:
9+
name: 🚀 publish
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: 📚 checkout
13+
uses: actions/checkout@v3
14+
- name: 🟢 node
15+
uses: actions/setup-node@v2
16+
with:
17+
node-version: 16
18+
registry-url: https://registry.npmjs.org
19+
- name: 🍳 prepare
20+
run: |
21+
npm install
22+
npm run build
23+
- name: 🚚 publish
24+
run: npm publish
25+
env:
26+
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

CHANGELOG.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,46 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66

7+
## [0.0.9] - 2023-08-09
8+
9+
### Added
10+
11+
- Support for developer role IDs
12+
- Ability to skip built-in validations by setting `skipBuiltInValidations` to true inside the `CommandKit` constructor
13+
14+
### Changed
15+
16+
- Change validations to run custom user validations first, then CommandKit's built-in validations.
17+
718
## [0.0.8] - 2023-07-03
819

920
### Added
1021

11-
- Support for nested files inside of each event folder.
22+
- Support for nested files inside of each event folder.
1223

1324
## [0.0.7] - 2023-07-02
1425

1526
### Changed
1627

17-
- Give validation functions access to the full command object (commandObj) excluding the run function (as that is handled by the command handler), as opposed to just the `data` and `options` properties.
28+
- Give validation functions access to the full command object (commandObj) excluding the run function (as that is handled by the command handler), as opposed to just the `data` and `options` properties.
1829

1930
## [0.0.6] - 2023-07-02
2031

2132
### Fixed
2233

23-
- Fixed a bug where wrong event names were being registered on Windows.
34+
- Fixed a bug where wrong event names were being registered on Windows.
2435

2536
## [0.0.5] - 2023-07-02
2637

2738
### Added
2839

29-
- Ability to automatically update application commands (guilds and global) when there's changes to the description or number of options (slash commands only).
40+
- Ability to automatically update application commands (guilds and global) when there's changes to the description or number of options (slash commands only).
3041

3142
## [0.0.4] - 2023-07-01
3243

3344
### Updated
3445

35-
- Update package.json with new URLs, scripts, and version
46+
- Update package.json with new URLs, scripts, and version
3647

3748
## [0.0.3] - 2023-07-01
3849

README.md

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# CommandKit
22

3-
CommandKit is a library that makes it easy to handle commands (+validations), and events in your Discord.js projects.
3+
CommandKit is a library that makes it easy to handle commands (+ validations), and events in your Discord.js projects.
44

5-
_Tested with Discord.js version `v14.11.0`_
5+
**Supports Discord.js version 14**
66

77
# Features
88

9-
- Very beginner friendly 🚀
10-
- Support for slash and context menu commands ✅
11-
- Automatic command registration, edits, and deletion 🤖
12-
- Supports multiple development servers 🤝
13-
- Supports multiple users as bot developers 👥
14-
- Object oriented 💻
9+
- Very beginner friendly 🚀
10+
- Support for slash and context menu commands ✅
11+
- Automatic command registration, edits, and deletion 🤖
12+
- Supports multiple development servers 🤝
13+
- Supports multiple users as bot developers 👥
14+
- Object oriented 💻
1515

1616
# Documentation
1717

@@ -37,38 +37,46 @@ yarn add commandkit
3737

3838
# Usage
3939

40-
This is a simple overview of how to set up this library with all the options.
41-
42-
**It's highly recommended you check out the [documentation](https://commandkit.underctrl.io) to fully understand how to work with this library.**
40+
This is a simple overview of how to set up this library with all the options. You can read more in the [full documentation](https://commandkit.underctrl.io)
4341

4442
```js
4543
// index.js
46-
const { Client, IntentsBitField } = require('discord.js');
44+
const { Client, GatewayIntentBits } = require('discord.js');
4745
const { CommandKit } = require('commandkit');
4846
const path = require('path');
4947

5048
const client = new Client({
51-
intents: [IntentsBitField.Flags.Guilds],
49+
intents: [
50+
GatewayIntentBits.Guilds,
51+
GatewayIntentBits.GuildMessages,
52+
GatewayIntentBits.MessageContent,
53+
],
5254
});
5355

5456
new CommandKit({
55-
// Your discord.js client object
56-
client,
57+
// Your discord.js client object
58+
client,
59+
60+
// Path to the commands folder
61+
commandsPath: path.join(__dirname, 'commands'),
62+
63+
// Path to the events folder
64+
eventsPath: path.join(__dirname, 'events'),
5765

58-
// Path to the commands folder
59-
commandsPath: path.join(__dirname, 'commands'),
66+
// Path to the validations folder (only valid if "commandsPath" was provided)
67+
validationsPath: path.join(__dirname, 'validations'),
6068

61-
// Path to the events folder
62-
eventsPath: path.join(__dirname, 'events'),
69+
// Array of development server IDs (used to register and run devOnly commands)
70+
devGuildIds: ['DEV_SERVER_ID_1', 'DEV_SERVER_ID_2'],
6371

64-
// Path to the validations folder (only valid if "commandsPath" was provided)
65-
validationsPath: path.join(__dirname, 'validations'),
72+
// Array of developer user IDs (used for devOnly commands)
73+
devUserIds: ['DEV_USER_ID_1', 'DEV_USER_ID_2'],
6674

67-
// Array of development server IDs (used to register and run devOnly commands)
68-
devGuildIds: ['DEV_SERVER_ID_1', 'DEV_SERVER_ID_2'],
75+
// Array of developer role IDs (used for devOnly commands)
76+
devRoleIds: ['DEV_ROLE_ID_1', 'DEV_ROLE_ID_2'],
6977

70-
// Array of developer user IDs (used for devOnly commands)
71-
devUserIds: ['DEV_USER_ID_1', 'DEV_USER_ID_2'],
78+
// A property that disables CommandKit's built-in validations
79+
skipBuiltInValidations: true,
7280
});
7381

7482
client.login('YOUR_TOKEN_HERE');

package.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
2-
"name": "commandkit",
3-
"version": "0.0.8",
4-
"main": "dist/index.js",
5-
"license": "MIT",
6-
"scripts": {
7-
"build": "tsc"
8-
},
9-
"repository": {
10-
"type": "git",
11-
"url": "https://github.com/notunderctrl/commandkit"
12-
},
13-
"homepage": "https://commandkit.underctrl.io",
14-
"keywords": [
15-
"discord.js",
16-
"command handler",
17-
"event handler",
18-
"command validations"
19-
],
20-
"dependencies": {},
21-
"devDependencies": {
22-
"discord.js": "^14.11.0",
23-
"tsc": "^2.0.4"
24-
}
2+
"name": "commandkit",
3+
"version": "0.0.9",
4+
"main": "dist/index.js",
5+
"license": "MIT",
6+
"scripts": {
7+
"build": "tsc"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/notunderctrl/commandkit"
12+
},
13+
"homepage": "https://commandkit.underctrl.io",
14+
"keywords": [
15+
"discord.js",
16+
"command handler",
17+
"event handler",
18+
"command validations"
19+
],
20+
"dependencies": {},
21+
"devDependencies": {
22+
"discord.js": "^14.12.1",
23+
"typescript": "^5.1.6"
24+
}
2525
}

src/CommandKit.ts

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,65 @@ import { CommandHandler, EventHandler, ValidationHandler } from './handlers';
22
import { CommandKitData, CommandKitOptions } from '../typings';
33

44
export class CommandKit {
5-
private _data: CommandKitData;
5+
private _data: CommandKitData;
66

7-
constructor({ ...options }: CommandKitOptions) {
8-
if (!options.client) {
9-
throw new Error('"client" is required when instantiating CommandKit.');
10-
}
11-
12-
if (options.validationsPath && !options.commandsPath) {
13-
throw new Error('"commandsPath" is required when "validationsPath" is set.');
14-
}
7+
constructor({ ...options }: CommandKitOptions) {
8+
if (!options.client) {
9+
throw new Error('"client" is required when instantiating CommandKit.');
10+
}
1511

16-
this._data = {
17-
...options,
18-
commands: [],
19-
};
12+
if (options.validationsPath && !options.commandsPath) {
13+
throw new Error('"commandsPath" is required when "validationsPath" is set.');
14+
}
2015

21-
this._init();
22-
}
16+
this._data = {
17+
...options,
18+
commands: [],
19+
};
2320

24-
private _init() {
25-
// Event handler
26-
if (this._data.eventsPath) {
27-
new EventHandler({
28-
client: this._data.client,
29-
eventsPath: this._data.eventsPath,
30-
});
21+
this._init();
3122
}
3223

33-
// Validation handler
34-
let validationFunctions: Function[] = [];
24+
private _init() {
25+
// Event handler
26+
if (this._data.eventsPath) {
27+
new EventHandler({
28+
client: this._data.client,
29+
eventsPath: this._data.eventsPath,
30+
});
31+
}
3532

36-
if (this._data.validationsPath) {
37-
const validationHandler = new ValidationHandler({
38-
validationsPath: this._data.validationsPath,
39-
});
33+
// Validation handler
34+
let validationFunctions: Function[] = [];
4035

41-
validationFunctions = validationHandler.getValidations();
42-
}
36+
if (this._data.validationsPath) {
37+
const validationHandler = new ValidationHandler({
38+
validationsPath: this._data.validationsPath,
39+
});
40+
41+
validationHandler.getValidations().forEach((v) => validationFunctions.push(v));
42+
}
4343

44-
// Command handler
45-
if (this._data.commandsPath) {
46-
const commandHandler = new CommandHandler({
47-
client: this._data.client,
48-
commandsPath: this._data.commandsPath,
49-
devGuildIds: this._data.devGuildIds || [],
50-
devUserIds: this._data.devUserIds || [],
51-
validations: validationFunctions,
52-
});
44+
// Command handler
45+
if (this._data.commandsPath) {
46+
const commandHandler = new CommandHandler({
47+
client: this._data.client,
48+
commandsPath: this._data.commandsPath,
49+
devGuildIds: this._data.devGuildIds || [],
50+
devUserIds: this._data.devUserIds || [],
51+
devRoleIds: this._data.devRoleIds || [],
52+
customValidations: validationFunctions,
53+
skipBuiltInValidations: this._data.skipBuiltInValidations || false,
54+
});
5355

54-
this._data.commands = commandHandler.getCommands();
56+
this._data.commands = commandHandler.getCommands();
57+
}
5558
}
56-
}
5759

58-
get commands() {
59-
return this._data.commands.map((cmd) => {
60-
const { run, ...command } = cmd;
61-
return command;
62-
});
63-
}
60+
get commands() {
61+
return this._data.commands.map((cmd) => {
62+
const { run, ...command } = cmd;
63+
return command;
64+
});
65+
}
6466
}

0 commit comments

Comments
 (0)