https://github.com/doowb/base-bot
Simple bot that knows how to handle events when told too. Use base bot to build more complex bots with plugins.
https://github.com/doowb/base-bot
Last synced: about 1 year ago
JSON representation
Simple bot that knows how to handle events when told too. Use base bot to build more complex bots with plugins.
- Host: GitHub
- URL: https://github.com/doowb/base-bot
- Owner: doowb
- License: mit
- Created: 2015-12-21T19:57:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-05-15T15:50:42.000Z (about 9 years ago)
- Last Synced: 2025-05-08T04:48:22.274Z (about 1 year ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# base-bot [](https://www.npmjs.com/package/base-bot)
> Simple bot that knows how to handle events when told too. Use base bot to build more complex bots with plugins.
## Install
Install with [npm](https://www.npmjs.com/)
```sh
$ npm i base-bot --save
```
## Usage
```js
var bot = require('base-bot');
```
## API
### [BaseBot](index.js#L24)
Create a new instance of a BaseBot with provided options.
**Params**
* `options` **{Object}**: Options to configure the github bot.
**Example**
```js
var bot = new BaseBot();
```
### [.handle](index.js#L52)
Handle a payload object. The `payload` will be passed to all registered handlers. Handlers may modify the `payload` and return it in their `callback`. The aggregated results will be returned in the `handle` `callback`.
**Params**
* `event` **{String}**: Event type to handle. Only listeners registered for this type will be notified.
* `payload` **{Object}**: Payload object to handle.
* `cb` **{Function}**: Callback to notify call when finished handling payload.
**Example**
```js
bot.handle('issue', payload, function(err, results) {
if (err) return console.error(err);
console.log(results);
});
```
### [.handler](index.js#L79)
Add a specific `on` and `handle` methods for an event.
**Params**
* `method` **{String}**: Name of the methods to add.
* `returns` **{Object}** `this`: for chaining.
**Example**
```js
bot.handler('issue');
bot.onIssue(function(payload, cb) { cb(null, payload); });
bot.handleIssue(payload, function(err, results) {
if (err) return console.error(err);
console.log(results);
});
```
### [.handlers](index.js#L116)
Add a specific `on` and `handle` methods for an array of events.
**Params**
* `methods` **{String|Array}**: Array of method names to add.
* `returns` **{Object}** `this`: for chaining.
**Example**
```js
bot.handlers(['issue', 'commit']);
bot.onIssue(function(payload, cb) { cb(null, payload); });
bot.onCommit(function(payload, cb) { cb(null, payload); });
bot.handleIssue(payload, function(err, results) {
if (err) return console.error(err);
console.log(results);
});
bot.handleCommit(payload, function(err, results) {
if (err) return console.error(err);
console.log(results);
});
```
## Related projects
* [base-methods](https://www.npmjs.com/package/base-methods): base-methods is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://www.npmjs.com/package/base-methods) | [homepage](https://github.com/jonschlinkert/base-methods)
* [use](https://www.npmjs.com/package/use): Easily add plugin support to your node.js application. | [homepage](https://github.com/jonschlinkert/use)
## Running tests
Install dev dependencies:
```sh
$ npm i -d && npm test
```
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/doowb/base-bot/issues/new).
## Author
**Brian Woodward**
+ [github/doowb](https://github.com/doowb)
+ [twitter/doowb](http://twitter.com/doowb)
## License
Copyright © 2015 [Brian Woodward](https://github.com/doowb)
Released under the MIT license.
***
_This file was generated by [verb](https://github.com/verbose/verb) on December 21, 2015._