Klasa

Discord npm npm Build Status Codacy Badge Greenkeeper badge David

Klasa is a class remix on the Komada Bot Framework, built on top of Discord.js. It offers an extremely easy installation and framework to build your own commands, event handlers, and much more.

What's with the name?

Following suit from Komada (the Croatian word for "pieces"), Klasa is the croation word for "class". Like Komada, Klasa is modular, meaning each "piece" is a standalone part that can be easily replaced, enhanced, reloaded, removed.

Why Klasa?

Klasa offers a different interface than Komada, namly all pieces extend base classes. As such, it isn't as beginner friendly, but it packs the advantages of OOP you wouldn't get otherwise. (The simplicity of <Command>.reload() and <Client>.inhibitors.run() as opposed to <Client>.funcs.reloadCommand(commandName) and <Client>.funcs.runCommandInhibitors() in komada respectively.) Say you want to unload an event, it isn't very easy to do in komada, however you can simply <Event>.unload() in Klasa.

What is different from Komada?

There are a number of differences currently:

  • Client isn't passed to the run of pieces, it is built into the base pieces object and is accessable as this.client
  • Inhibitors are async in klasa, requiring rejection of undefined or a message if you want to inhibit the command.
  • The piece stores (caches) aren't just Discord.Collections like in komada, they are extensions of collections which includes all loading, getting, setting, deleting, ect built right in and abstracted away. <EventStore>.delete(eventName) not only removes the event from the collection, but unregisters the event as a listener. <CommandStore>.get(name) not only gets the command if it's the command name, but if it's a command alias as well. ect.
  • No <Client>.funcs. All functions have been abstracted away into OOP paradigms, or moved to the util class (only functions which have no reason to ever change, such as util.toTitleCase() or util.codeBlock()). If you would like to add functions that are shared among multiple things, you can do so in the standard node.js way via module.exports and require()
  • Events overwrite core pieces, like other pieces do, instead of offering a second event listener. So it is important to use the transfer command to edit certain events, instead of simply replacing them so that certain Klasa framework operations continue to work
  • No installNPM function. Requiring pieces without installing the required packages wont install the missing dependancies like it does in komada. (If and when the download command is sorted with a Klasa-pieces repo, that download command will likely have installNPM added back)
  • All pieces are flat, meaning no help or conf. <Command>.description instead of <Command>.help.description ect. As such, the cooldown map that stores users on cooldown, has been changed to cooldowns and the cached instance of your usage is usageString where as usage is your fully parsed usage.
  • All pieces (except extendables) can now be used as types usage strings, to get klasa pieces for use in commands. The new types are cmd, command, event, inhibitor, finalizer, monitor, provider.

Time to get started!

See the following tutorial on how to get started using Klasa.

See also: