______ __ ____ __
/ ____/___ _/ /_/ __ )____ / /_
/ /_ / __ `/ __/ __ / __ \/ __/
/ __/ / /_/ / /_/ /_/ / /_/ / /_
/_/ \__,_/\__/_____/\____/\__/
FatBot is an easy to use and extensible ES6 IRC bot framework.
Note: You are reading the documentation of the ES6 version (v1.x). If you are looking for the v0.3 documentation (
coffeescript
) please refer to the 0.3 branch.
> npm install fatbot
import { Bot } from 'fatbot'
let bot = new Bot({
server: 'freenode',
nick: 'fatbot',
channels: ['#fatbot', '#skinnybot'],
botDebug: false
})
// Listen to Bot events
bot.on('user:join', (r) => {
r.reply(`Welcome to ${r.channel}, ${r.nick} !`)
})
// Listening discussion
bot.hear(/hello/, (r) => {
r.reply(`Hello ${r.nick} !`)
})
// Connect the bot
bot.connect()
> fatbot bot.js
In this example, you are :
- Connecting
mybot
to a built-in server shortcut calledfreenode
and join a channel called#fatbot
- Perform action on events with
Fatbot::on
- Launching the bot with
Fatbot::connnect
method
Note: Since your bot will be launched with babel-node you can write your bot in ES6
For large bot projects, you may want to split your functionalities into different files.
You can use Bot::on
with an object literal
bot.on({
event: 'user:talk',
trigger: (r) => {
console.log(`${r.nick} is talking...`)
}
})
// ./lib/hello.js
function callback (r) {
r.reply(`Hello ${r.nick}!`)
}
export const ontalk = {
event: 'user:talk',
trigger: callback
}
export const onprivate = {
event: 'user:private',
trigger: callback
}
// ./bot.js
import * as hello from './lib/hello'
//...
bot.on(hello)
bot.connect()
You can extend the prototype of the Bot
class. For example, the method Bot::hear
is a built-in extension:
Bot.prototype.hear = function (regex,callback) {
this.on('user:talk', (r) => {
if (r.text.match(regex)) {
callback(r)
}
})
}
You can easily add behaviors to the bot by listening to events :
bot.on('user:join', (r) => {
r.reply(`Welcome to ${r.channel}, ${r.nick}!`)
})
r
is the Response object.
These are the events thrown by the bot.
Event name | Description | Response |
---|---|---|
client:error |
Error sent by the client | err (isnt Response object) |
self:connected |
Bot is connected to server | server |
self:talk |
Bot is talking | nick, text, client, reply(txt) |
self:join |
Bot is joining a channel | channel, nick, text, client |
user:talk |
User is talking in channel | nick, channel, text, client, reply(txt) |
user:private |
User send pm to the bot | nick, text, client |
user:join |
User join a channel | channel, nick, text, client, reply(txt) |
- 🦄 Rewrite the project into ES6. Nothing has changed in the API
- Fix CB when using coffee-script v.1.6.x compiler
- You can now add event listeners with objects literal
- You can now add event listeners bundled in arrays
- README.md upadated with new examples
- Bot completely rewritten (again)
- Temporary removing sugars in favor of prototype extensions
- Refinery lost in translation ;)
- Simpler code to do such simple things
- Bot completely rewritten in coffeescript on top of node and node-irc
- Fatbot is now a standalone framework
- Plugins are now called sugars
- Added sugars factories called refinery helpers
- Merge of node branch into master
- Fist beta working version of the coffeescript version