actions

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2021 License: MIT Imports: 5 Imported by: 0

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

View Source
var ErrNotHandled = errors.New("message not handled")

ErrNotHandled is returned if a handler can't handle the message.

Functions

This section is empty.

Types

type Handler

type Handler interface {

	// Handle the message.
	Handle(channel, user, message string) (string, error)

	// ID returns the name of the action in order to identify it in logs and
	// errors.
	ID() string

	// Initialise the handler
	Init() error
}

Handler defines a type that can handle incoming chat messages.

type Moar added in v0.1.1

type Moar struct {
	Counter int `json:"counter"`
	// contains filtered or unexported fields
}

Moar just displays information about the bot.

func NewMoar added in v0.1.1

func NewMoar(store store.Driver) *Moar

NewMoar returns a new Moar action.

func (*Moar) Handle added in v0.1.1

func (m *Moar) Handle(_, _, message string) (string, error)

Handle the chat message by incrementing a counter.

func (*Moar) ID added in v0.1.1

func (m *Moar) ID() string

ID for the action.

func (*Moar) Init added in v0.1.1

func (m *Moar) Init() error

Init the action.

type Ping

type Ping struct{}

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

func (p Ping) Handle(_, _, message string) (string, error)

Handle the chat message by replying Ping to Pong and Pong to ping.

Example
package main

import (
	"fmt"

	"bitbucket.org/idomdavis/gobot/actions"
)

func main() {
	a := actions.Ping{}

	if m, err := a.Handle("chan", "user", "ping"); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(m)
	}

}
Output:

Pong!

func (Ping) ID

func (p Ping) ID() string

ID for the action.

Example
package main

import (
	"fmt"

	"bitbucket.org/idomdavis/gobot/actions"
)

func main() {
	fmt.Println(actions.Ping{}.ID())

}
Output:

Ping Action

func (Ping) Init added in v0.1.1

func (p Ping) Init() error

Init the action.

type Status added in v0.1.0

type Status struct {
	config.Settings
}

Status just displays information about the bot.

func (Status) Handle added in v0.1.0

func (s Status) Handle(_, _, message string) (string, error)

Handle the chat message by replying with version information.

Example
package main

import (
	"fmt"

	"bitbucket.org/idomdavis/gobot/actions"
	"bitbucket.org/idomdavis/gobot/config"
)

func main() {
	a := actions.Status{Settings: config.Settings{Name: "bot"}}

	if m, err := a.Handle("chan", "user", "status"); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(m)
	}

	if m, err := a.Handle("chan", "user", "version"); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(m)
	}

}
Output:

bot: UNSET (Built: UNSET)
bot: UNSET (Built: UNSET)

func (Status) ID added in v0.1.0

func (s Status) ID() string

ID for the action.

Example
package main

import (
	"fmt"

	"bitbucket.org/idomdavis/gobot/actions"
)

func main() {
	fmt.Println(actions.Status{}.ID())

}
Output:

Status Action

func (Status) Init added in v0.1.1

func (s Status) Init() error

Init the action.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL