Skip to content
This repository has been archived by the owner on Jul 13, 2019. It is now read-only.

Modules

zekro edited this page Jan 31, 2018 · 1 revision

You can create modules for the bot which will be places in the sc/modules direcotory. They will be loaded and executed automatically after ready event fired.

Create a module

Just create a *.js or a *.coffee file in the src/modules directory with a name what you want to name your module.

At the top of the module should be a description which should look like following:

/*

MODULE INFO:
- name:         MyModule
- version:      1.0
- creator:      zekro (github.com/zekrotja)
- last edited:  2018/01/31

MODULE DESCRIPTION:
This is my module which implements super cool and new stuff :O

*/

If this is not existent or in wrong formatting, the Pull Request will not be accepted!

Implementations

You can use all other classes which have export functions available. There is a list of all classes avaiable. If you need information about available functions, just take a look in the code and look for exports.* functions ;)

const Main       = require('../main')
const ACHandler  = require('../core/autochanhandler')
const Settings   = require('../core/settings')
const Embeds     = require('../util/embeds')
const Logger     = require('../util/logger')

// These should be implemented via the main class,
// because they are instances which should be used
// to work with the bot.
const MySql      = Main.mysql
const CmdHandler = Main.cmd

Register a command

The command registration and parsing is handled by my Node.js Commands Package.
Here you can find a full documentation about the module.

You can register a command in your module like following:

const Main = require('../main')
const CmdHandler = Main.cmd

// Grab the default prefix from the config
var prefix = Main.config.prefix

// The parser will pass the message instance and the
// arguments as array.
function myCommand(msg, args) {
    msg.channel.send(`Hey, ${msg.member.displayName}! :wave:`)
}

CmdHandler.register(
    myCommand,              // Function which will be executed
    'hey',                  // Main Invoke
    ['ho', 'sayhey'],       // Aliases
    'I say hey to you :*',  // Description
    `\`${prefix}hey\n`,     // Help description
    CmdHandler.type.MISC,   // Type
    0                       // Permission level
)

Register events

You can register events normally by attaching them on the clients event listener grabbed from the main class.

const Main = require('../main')

// Client instance is exported by main class
const client = Main.client

// Just attach your event you want to register to the clients instance
client.on('message', (msg) => {
    console.log(
        `${msg.author.username} send a message with content:\n` +
        msg.content
    )
})
Clone this wiki locally