Classes: Plugin - 5GameMaker/openjsk GitHub Wiki
abstract class Plugin
/plugins/Plugin.ts
import { Plugin } from 'openjsk';
export class MyCoolPlugin extends Plugin { // if you want to add commands use Module class instead
public myCoolFunction() { /* code */ }
}
Base class for all plugins
Methods
- virtual void onLoad()
Called each time plugin is being loaded
export class MyCoolPlugin extends Plugin {
public onLoad() {
super.onLoad(); // It should be like that
/* load everything you need */
}
}
- virtual void onUnload()
Called each time plugin is being unloaded (please don't mess this up)
export class MyCoolPlugin extends Plugin {
public onUnload() {
super.onUnload(); // It should be like that
/* unload everything you need */
}
}
- protected void addBehavour(behavour : Behavour)
Add a behavour to your plugin (i wonder why you should use them instead of handeling bot events by yourself)
export class MyCoolPlugin extends Plugin {
public constructor(bot : Bot) {
super(bot);
this.addBehavour(new EventBehavour(bot, "guildMemeberAdd", async m => m.send("Hello!").catch(() => {}))); // please never add this feature to your bot
}
}
Fields
- Bot parent
Bot plugin has been created for
const plugin = new MyCoolPlugin(bot); // sets Plugin.parent
console.log(plugin.parent); // tons of stuff
- string name
Plugin's name (Randomized by default)
export class MyCoolPlugin extends Plugin {
public constructor(bot : Bot) {
super(bot);
this.name = "my-cool-plugin";
}
}