1.0.0 • Published 7 years ago

discord-hermes v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

Hermes

Hermes is a bot framework for creating bots for Discord.

Features

  • Per-server configuration
  • Plugin system, also configurable per-server
    • Plugins are just simple objects, so no file loading logic involved
    • Plugins can be loaded and unloaded on the fly
  • Advanced command parser, akin to command line arguments (using minimist)
  • Permission system: specify required server permissions, roles, or specific users
    • Includes plugin and command blacklisting on a channel-by-channel basis
  • Built on top of Eris

Installation

npm install --save discord-hermes

Example

const Eris = require('eris')
const Hermes = require('discord-hermes')

// Plugins loaded as node modules
const PluginManager = require('hermes-plugin-manager')
const SettingsManager = require('hermes-settings-manager')

// An example of a custom plugin
const MyPlugin = {
  load (bot, commands) {
    // Commands are only created for the servers where the plugin is enabled
    commands.add('ping', (msg, args) => {
      msg.channel.createMessage('pong!')
    })
  }
}

// Create the Eris client and Hermes instance
const bot = new Eris("your bot token")
const hermes = new Hermes(bot, {
  // Specify available plugins
  'pluginmanager': PluginManager,
  'settingsmanager': SettingsManager,
  'myplugin': MyPlugin
})

hermes.setDefaultAutoloadPlugins(['pluginmanager', 'settingsmanager', 'myplugin'])
hermes.enablePluginAutoloading()

bot.connect()

Plugins

Below is an example of a plugin with all available arguments:

module.exports = {
  load(bot, commands, onEvent, serverId, pluginConfig, serverConfig, hermes, pluginName) {
    
  },
  
  unload(bot, serverId, pluginConfig, serverConfig, hermes, pluginName) {
    // Commands registered with commands.add and events registered with onEvent get unloaded automatically
  }
}

API

new Hermes(bot, availablePlugins[, config])

Creates a new Hermes instance

ParamTypeDescription
botEris.ClientThe Eris client instance to use
availablePluginsObject, MapInitially available plugins, format: {pluginName: pluginObj}
configObject
config.serverConfigDirStringPath to the directory where to save server configuration. Default: servers
config.debugBoolWhether to enable extra logging in console
hermes.enablePluginAutoloading()

Automatically loads server plugins specified in server configuration and setDefaultAutoloadPlugins()

hermes.setDefaultAutoloadPlugins(plugins)
ParamTypeDescription
pluginsString[]Array of available plugin names to load automatically for all servers
hermes.loadServerPlugin(serverId, pluginName) => Promise

Loads ("enables") an available plugin for the specified server

ParamType
serverIdString
pluginNameString
hermes.unloadServerPlugin(serverId, pluginName) => Promise

Unloads ("disables") a loaded plugin from the specified server

ParamType
serverIdString
pluginNameString
hermes.unloadAllServerPlugins(serverId) => Promise

Unloads all plugins for the specified server

ParamType
serverIdString
hermes.getLoadedServerPlugins(serverId) => Map<pluginName, pluginObj>

Returns a map of loaded plugins for the specified server

ParamType
serverIdString
hermes.getAvailablePlugins() => Map<pluginName, pluginObj>

Returns a map of registered available plugins

hermes.addAvailablePlugin(name, pluginObj)

Adds a new available plugin

ParamType
nameString
pluginObjObject
hermes.removeAvailablePlugin(name) => Promise

Removes an available plugin after unloading it from all servers

ParamType
nameString