1.0.0 • Published 8 years ago
discord-hermes v1.0.0
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
Param | Type | Description |
---|---|---|
bot | Eris.Client | The Eris client instance to use |
availablePlugins | Object, Map | Initially available plugins, format: {pluginName: pluginObj} |
config | Object | |
config.serverConfigDir | String | Path to the directory where to save server configuration. Default: servers |
config.debug | Bool | Whether to enable extra logging in console |
hermes.enablePluginAutoloading()
Automatically loads server plugins specified in server configuration and setDefaultAutoloadPlugins()
hermes.setDefaultAutoloadPlugins(plugins)
Param | Type | Description |
---|---|---|
plugins | String[] | 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
Param | Type |
---|---|
serverId | String |
pluginName | String |
hermes.unloadServerPlugin(serverId, pluginName) => Promise
Unloads ("disables") a loaded plugin from the specified server
Param | Type |
---|---|
serverId | String |
pluginName | String |
hermes.unloadAllServerPlugins(serverId) => Promise
Unloads all plugins for the specified server
Param | Type |
---|---|
serverId | String |
hermes.getLoadedServerPlugins(serverId) => Map<pluginName, pluginObj>
Returns a map of loaded plugins for the specified server
Param | Type |
---|---|
serverId | String |
hermes.getAvailablePlugins() => Map<pluginName, pluginObj>
Returns a map of registered available plugins
hermes.addAvailablePlugin(name, pluginObj)
Adds a new available plugin
Param | Type |
---|---|
name | String |
pluginObj | Object |
hermes.removeAvailablePlugin(name) => Promise
Removes an available plugin after unloading it from all servers
Param | Type |
---|---|
name | String |