gobot is a Simple XMPP bot written in golang
Initail work based on https://github.com/mattn/go-xmpp/blob/master/example/example.go
gobot is under active development, the api may change w/out warning.
By itself, gobot just sits and listens for incoming XMPP messages. When a message is received, gobot passes the message on to any number of plugins. The plugins provide all the features of the chatbot.
Currently, the following plugins exist:
-
dm - gobot recognizes his nick and replies that his ears are burning when he is mentioned.
-
quote - gobot understands the quote command. Currently 3 types of quotes are supported: code quote - quotes about programming integration quote - quotes about front end integration admin quote - quotes about systems administration
-
chatlog - gobot logs all messages to a text file. Currently '/tmp/chatlog'
-
stathat - gobot counts each message, and logs it as a single 'hit' at stathat.
-
keyword - gobot scans a message for work counts
-
echo - gobot echoes a message back to the room
-
beer - ask gobot for a beer?
First, you'll need to have golang installed: http://golang.org/doc/install
Then, once that is working, all you need to do is:
$ go get github.com/gabeguz/gobot
Currently, the command I use is:
$ $GOPATH/bin/gobot -host="jabber.my.domain:5222" -user="gabe@jabber.my.domain" -pass="hunter2" -room="#gobottest@conference.jabber.my.domain" -name="gobot"
Creating a plugin is pretty easy, you just need to import the xmppbot library:
import (
"github.com/gabeguz/xmppbot"
)
And then implement 2 exported methods so that you conform to the gobotplugin interface:
type MyPlugin struct {}
func (p MyPlugin) Name() string {
return "MyPlugin v1.0"
}
func (p MyPlugin) Execute(msg xmppbot.Message, bot xmppbot.Bot) error {
if msg.From() != bot.FullName() {
bot.Send("Why, hello!")
}
return nil
}
One last step, edit gobot/gobot.go and add a call to your new plugin (importing if necessary) to the []gobotplugin.Plugin slice:
[]gobotplugin.Plugin{
gobotplugin.MyPlugin{},
}
That's it!