Documentation
¶
Overview ¶
Package actions contains the actions that the bot can perform. Actions will be passed the current chat details and can return a response. More than one action can generate a response. Errors will result in no response from the action.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseHandler ¶ added in v0.1.2
type BaseHandler struct {
Name string
}
BaseHandler provides the basic support elements for a handler.
func NewBaseHandler ¶ added in v0.1.2
func NewBaseHandler(name string) *BaseHandler
NewBaseHandler returns a new, named BaseHandler.
Example ¶
package main import ( "fmt" "bitbucket.org/idomdavis/gobot/actions" ) func main() { var h *actions.BaseHandler h = actions.NewBaseHandler("Named") fmt.Println(h.ID()) h = &actions.BaseHandler{} fmt.Println(h.ID()) }
Output: Named Action Unnamed Action
func (*BaseHandler) ID ¶ added in v0.1.2
func (b *BaseHandler) ID() string
ID for the action taken from the Name.
func (*BaseHandler) Init ¶ added in v0.1.2
func (*BaseHandler) Init() error
Init the action. Init does nothing.
type Echo ¶ added in v0.1.2
type Echo struct {
*BaseHandler
}
Echo just displays what was sent to it.
type Handler ¶
type Handler interface { // Handle the message, responding if relevant. Errors should be logged // and/or reported to the user via the sender. Handle(inbound message.Inbound, sender message.Sender) // ID returns the name of the action in order to identify it in logs and // errors. ID() string // Init the handler Init() error }
Handler defines a type that can handle incoming chat messages.
type Moar ¶ added in v0.1.1
type Moar struct { BackingStore store.JSONStore Counter int *BaseHandler }
Moar just displays information about the bot.
type Ping ¶
type Ping struct {
*BaseHandler
}
Ping action is a simple "status check" that will response with "Pong" to indicate the bot is up and listening. Ping also understands pong and responds with an appropriate message.
func (*Ping) Handle ¶
Handle the chat message by replying Ping to Pong and Pong to ping.
Example ¶
package main import ( "bitbucket.org/idomdavis/gobot/actions" "bitbucket.org/idomdavis/gobot/listener" "bitbucket.org/idomdavis/gobot/message" ) func main() { a := actions.Ping{} msg := message.Inbound{ Channel: "chan", Content: "ping", Author: message.User{ID: "user"}, } s := listener.Console{} a.Handle(msg, s) }
Output: Pong!
type Shutdown ¶ added in v0.1.15
type Shutdown struct {
*BaseHandler
}
Shutdown the bot with the given version ID.
type Status ¶ added in v0.1.0
type Status struct { Settings config.Settings *BaseHandler // contains filtered or unexported fields }
Status just displays information about the bot.
func (*Status) Handle ¶ added in v0.1.0
Handle the chat message by replying with version information.
Example ¶
package main import ( "bitbucket.org/idomdavis/gobot/actions" "bitbucket.org/idomdavis/gobot/config" "bitbucket.org/idomdavis/gobot/listener" "bitbucket.org/idomdavis/gobot/message" ) func main() { a := actions.Status{Settings: config.Settings{Discord: config.Discord{Name: "bot"}}} _ = a.Init() msg := message.Inbound{ Channel: "chan", Content: "status", Author: message.User{ID: "user"}, } s := listener.Console{} a.Handle(msg, s) }
Output: