Created
July 13, 2017 12:06
-
-
Save Nickforall/406e206208f72eb0f0a26a28ad449a77 to your computer and use it in GitHub Desktop.
This is a demo plugin for what squadbot **could** look like
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "squadbot-demo", | |
"commands": { | |
"demo": "replies \"Yoooo\"" | |
}, | |
"protocols": [ | |
"*" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Squadbot demo plugin, this piece of code is non functional and written to | |
* illustrate how squadbot's api's will work. | |
*/ | |
// SquadBot.require is the equilevant of require.js' require function, except we | |
// can also load squadbot specific modules by prefixing it with squadbot/ | |
// | |
// Requiring files from the filesystem only works in the plugin's own folder | |
const logger = SquadBot.require('squadbot/logger'); | |
const capabilities = SquadBot.require('squadbot/capabilities'); | |
// NPM modules are prefixed with npm/ and will be automatically installed on initialization. | |
const request = SquadBot.require('npm/request'); | |
// Node's standard library is written as normal | |
const util = SquadBot.require('util'); | |
// simple event handling happens like this, just like node's event emitter. | |
SquadBot.on('loaded', (protocols, plugins) => { | |
// we have async storage available capable of storing anything json | |
Squadbot.Storage.storeAsync("key", "value"); | |
// as well as syncrhonous reading | |
Squadbot.Storage.read("key"); | |
// we can store public data that can be accessed by other plugins | |
Squadbot.Storage.storeAsync("anotherkey", 1, true); | |
// that we and other plugins can read | |
Squadbot.Storage.readGlobal("squadbot-demo/key"); | |
logger.log("Squadbot demo-plugin has been initialized!"); | |
}); | |
// There also is more complex handling available: | |
// This event will only be called when the protocol that is firing this event | |
// has the capabilities described in the given array | |
SquadBot.on('message', [ capabilities.textMessage, capabilities.imageMessage ], (message) => { | |
// of course you can also test capabilities with an if statement | |
if (message.protocol.isCapable(capabilities.mention)) { | |
logger.log(util.inspect(message.mentions)); | |
} | |
}); | |
// There is a specific handler for commands | |
// Capability checking is available here too | |
SquadBot.registerCommand("demo", (args, message) => { | |
logger.log("yooo"); | |
message.reply("Yoooo"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment