Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 'publish'

on:
push:
branches: [main]

jobs:
release:
name: 🚀 publish
runs-on: ubuntu-latest
steps:
- name: 📚 checkout
uses: actions/checkout@v3
- name: 🟢 node
uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://registry.npmjs.org
- name: 🍳 prepare
run: |
npm install
npm run build
- name: 🚚 publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
21 changes: 16 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,46 @@ All notable changes to this project will be documented in this file.

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

## [0.0.9] - 2023-08-09

### Added

- Support for developer role IDs
- Ability to skip built-in validations by setting `skipBuiltInValidations` to true inside the `CommandKit` constructor

### Changed

- Change validations to run custom user validations first, then CommandKit's built-in validations.

## [0.0.8] - 2023-07-03

### Added

- Support for nested files inside of each event folder.
- Support for nested files inside of each event folder.

## [0.0.7] - 2023-07-02

### Changed

- 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.
- 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.

## [0.0.6] - 2023-07-02

### Fixed

- Fixed a bug where wrong event names were being registered on Windows.
- Fixed a bug where wrong event names were being registered on Windows.

## [0.0.5] - 2023-07-02

### Added

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

## [0.0.4] - 2023-07-01

### Updated

- Update package.json with new URLs, scripts, and version
- Update package.json with new URLs, scripts, and version

## [0.0.3] - 2023-07-01

Expand Down
58 changes: 33 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# CommandKit

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

_Tested with Discord.js version `v14.11.0`_
**Supports Discord.js version 14**

# Features

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

# Documentation

Expand All @@ -37,38 +37,46 @@ yarn add commandkit

# Usage

This is a simple overview of how to set up this library with all the options.

**It's highly recommended you check out the [documentation](https://commandkit.underctrl.io) to fully understand how to work with this library.**
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)

```js
// index.js
const { Client, IntentsBitField } = require('discord.js');
const { Client, GatewayIntentBits } = require('discord.js');
const { CommandKit } = require('commandkit');
const path = require('path');

const client = new Client({
intents: [IntentsBitField.Flags.Guilds],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});

new CommandKit({
// Your discord.js client object
client,
// Your discord.js client object
client,

// Path to the commands folder
commandsPath: path.join(__dirname, 'commands'),

// Path to the events folder
eventsPath: path.join(__dirname, 'events'),

// Path to the commands folder
commandsPath: path.join(__dirname, 'commands'),
// Path to the validations folder (only valid if "commandsPath" was provided)
validationsPath: path.join(__dirname, 'validations'),

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

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

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

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

client.login('YOUR_TOKEN_HERE');
Expand Down
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "commandkit",
"version": "0.0.8",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
"build": "tsc"
},
"repository": {
"type": "git",
"url": "https://github.com/notunderctrl/commandkit"
},
"homepage": "https://commandkit.underctrl.io",
"keywords": [
"discord.js",
"command handler",
"event handler",
"command validations"
],
"dependencies": {},
"devDependencies": {
"discord.js": "^14.11.0",
"tsc": "^2.0.4"
}
"name": "commandkit",
"version": "0.0.9",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
"build": "tsc"
},
"repository": {
"type": "git",
"url": "https://github.com/notunderctrl/commandkit"
},
"homepage": "https://commandkit.underctrl.io",
"keywords": [
"discord.js",
"command handler",
"event handler",
"command validations"
],
"dependencies": {},
"devDependencies": {
"discord.js": "^14.12.1",
"typescript": "^5.1.6"
}
}
96 changes: 49 additions & 47 deletions src/CommandKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,65 @@ import { CommandHandler, EventHandler, ValidationHandler } from './handlers';
import { CommandKitData, CommandKitOptions } from '../typings';

export class CommandKit {
private _data: CommandKitData;
private _data: CommandKitData;

constructor({ ...options }: CommandKitOptions) {
if (!options.client) {
throw new Error('"client" is required when instantiating CommandKit.');
}

if (options.validationsPath && !options.commandsPath) {
throw new Error('"commandsPath" is required when "validationsPath" is set.');
}
constructor({ ...options }: CommandKitOptions) {
if (!options.client) {
throw new Error('"client" is required when instantiating CommandKit.');
}

this._data = {
...options,
commands: [],
};
if (options.validationsPath && !options.commandsPath) {
throw new Error('"commandsPath" is required when "validationsPath" is set.');
}

this._init();
}
this._data = {
...options,
commands: [],
};

private _init() {
// Event handler
if (this._data.eventsPath) {
new EventHandler({
client: this._data.client,
eventsPath: this._data.eventsPath,
});
this._init();
}

// Validation handler
let validationFunctions: Function[] = [];
private _init() {
// Event handler
if (this._data.eventsPath) {
new EventHandler({
client: this._data.client,
eventsPath: this._data.eventsPath,
});
}

if (this._data.validationsPath) {
const validationHandler = new ValidationHandler({
validationsPath: this._data.validationsPath,
});
// Validation handler
let validationFunctions: Function[] = [];

validationFunctions = validationHandler.getValidations();
}
if (this._data.validationsPath) {
const validationHandler = new ValidationHandler({
validationsPath: this._data.validationsPath,
});

validationHandler.getValidations().forEach((v) => validationFunctions.push(v));
}

// Command handler
if (this._data.commandsPath) {
const commandHandler = new CommandHandler({
client: this._data.client,
commandsPath: this._data.commandsPath,
devGuildIds: this._data.devGuildIds || [],
devUserIds: this._data.devUserIds || [],
validations: validationFunctions,
});
// Command handler
if (this._data.commandsPath) {
const commandHandler = new CommandHandler({
client: this._data.client,
commandsPath: this._data.commandsPath,
devGuildIds: this._data.devGuildIds || [],
devUserIds: this._data.devUserIds || [],
devRoleIds: this._data.devRoleIds || [],
customValidations: validationFunctions,
skipBuiltInValidations: this._data.skipBuiltInValidations || false,
});

this._data.commands = commandHandler.getCommands();
this._data.commands = commandHandler.getCommands();
}
}
}

get commands() {
return this._data.commands.map((cmd) => {
const { run, ...command } = cmd;
return command;
});
}
get commands() {
return this._data.commands.map((cmd) => {
const { run, ...command } = cmd;
return command;
});
}
}
Loading