-
Notifications
You must be signed in to change notification settings - Fork 0
Modular Commands
Arthur Neuman edited this page May 17, 2020
·
3 revisions
It's standard practice to keep your systems as modular as possible, granting agility in new feature development.
Standard practice is to keep your commands as files in a data folder that is required.
If your command files are put in a folder, you can require the parent folder by placing an index.js
in it. The purpose of this file is to require all the command files and compile them into an array the agent can take.
const commands = []
const files = readdirSync(__dirname)
for (const file of files) if (file !== 'index.js') commands.push(require(join(__dirname, file)))
module.exports = commands
const {
Command
} = require('cyclone-engine')
const data = {
name: 'ping',
desc: 'Check if the bot is responding to commands'
action: () => 'pong'
}
module.exports = new Command(data)
Now you can require the folder containing the commands and receive an array containing the commands