actions

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: MIT Imports: 10 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 ErrBoom = errors.New("boom")

ErrBoom is loud.

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

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

Functions

func Avatar added in v0.1.9

func Avatar(settings config.Settings) error

Avatar will attempt to set the bot avatar.

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.

func (*Echo) Handle added in v0.1.2

func (e *Echo) Handle(channel, user, message string) (string, error)

Handle the chat message by responding with the channel user and message.

type Error added in v0.1.2

type Error struct {
	*BaseHandler
}

Error just goes boom.

func (*Error) Handle added in v0.1.2

func (e *Error) Handle(_, _, _ string) (string, error)

Handle the chat message by responding with the channel user and message.

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 {
	BackingStore store.JSONStore
	Counter      int

	*BaseHandler
}

Moar just displays information about the bot.

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) Init added in v0.1.1

func (m *Moar) Init() error

Init the action.

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

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!

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

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"}}
	_ = a.Init()

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

}
Output:

bot: UNSET (Built: UNSET) - Uptime:

func (*Status) Init added in v0.1.1

func (s *Status) Init() error

Init the action.

type Test added in v0.1.10

type Test struct {
	*BaseHandler
	config.Settings
	// contains filtered or unexported fields
}

Test bed.

func (*Test) Handle added in v0.1.10

func (t *Test) Handle(_, _, message string) (string, error)

Handle the chat message by running the test.

func (*Test) Handler added in v0.1.11

func (t *Test) Handler(_ *discordgo.Session, m *discordgo.UserUpdate)

Handler is just grabbing user updates for us to see what we can see.

Jump to

Keyboard shortcuts

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