Skip to content

Plugins

oq edited this page Sep 27, 2023 · 7 revisions

Making plugins for Dynamite

Making plugins is very simple and you have 2 options:

Using scripting languages (JavaScript, Lua) - for simpler plugins

JavaScript

The javascript plugin api supports most of ES6

Global Variables

server.close (function<code?: number>) - closes the server

server.logger.info (function<format: string, ...any>) - print something to the console with this format [<DATE> INFO]:

server.logger.debug (function<format: string, ...any>) - print something to the console with this format [<DATE> DEBUG]:. If the server isn't running with the -debug argument, the text will not be shown

server.logger.error (function<format: string, ...any>) - print something to the console with this format [<DATE> ERROR]:

server.logger.warn (function<format: string, ...any>) - print something to the console with this format [<DATE> WARN]:

server.logger.print (function<format: string, ...any>) - print something to the console

server.commands.register (function<cmd: Command>) - register (override) a command

server.commands.delete (function<name: string>) - delete a command

server.commands.get (function<name: string>:Command) - get a command with the specified name

server.commands.getAll (function:Command[]) - get all commands

Plugin (function) - register the plugin

Plugin Example:

Plugin({
  identifier: "com.oq.myplugin",
  onLoad: () => {
    server.logger.info("MYPLUGIN!!!!!!!!!!!!!!!!!!!!!!!!!!");
    server.logger.warn("This plugin might be too cool for your server");
    server.logger.error("Failed to find who asked");
    server.logger.debug("Loading commands!!!!");
    server.logger.print("Regular print.");
    server.commands.register({
      name: "command",
      execute: (ctx) => {
        ctx.Reply("hi");
      },
    });
  },
});

Multi file plugins You can also make a plugin with multiple files, and here's how:

  1. Make a plugin.json file that contains the following text:
{
   "rootFile": "index.js", // The root file of the plugin
   "type": "javascript"
}
  1. In your plugin files, you can use the require function. For example, const commands = require("commands.js")

  2. To export stuff, you can use the exports variable. For example, exports = { commands: [] }