listener

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package listener defines chat listeners for the bot.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrConnectionFailure = errors.New("failed to connect to server")

ErrConnectionFailure is returned if there was an error connecting to the server for any reason.

View Source
var ErrInvalidClientConfig = errors.New("invalid client config")

ErrInvalidClientConfig is returned if the bot is started with a client config name it doesn't recognise.

View Source
var ErrNoDiscordToken = errors.New("no discord token set")

ErrNoDiscordToken is returned if there is no Discord token set in the config.

Functions

func ConsoleClient added in v0.1.13

func ConsoleClient(dispatcher Dispatcher, _ config.Settings) message.Sender

ConsoleClient starts a new client listening on the console.

func DiscordClient added in v0.1.13

func DiscordClient(dispatcher Dispatcher, settings config.Settings) (message.Sender, error)

DiscordClient creates a new connection to Discord using the given Dispatcher and Settings. If the connection fails an error is returned. If there is no Discord Token set then the program will exit.

func Start added in v0.1.13

func Start(dispatcher Dispatcher, settings config.Settings) (message.Sender, error)

Start the client using the Dispatcher to handle incoming messages.

Types

type Console added in v0.1.13

type Console struct {
	Dispatcher
}

Console client.

func (Console) Send added in v0.1.13

func (c Console) Send(message message.Outbound) error

Send will output the message component of the Outbound to STDOUT.

func (Console) SendString added in v0.1.13

func (c Console) SendString(channel, msg string) error

SendString will build an Outbound and Send that.

type Discord

type Discord struct {
	Dispatcher
}

Discord listener. The set of Actions are used to handle the messages.

func (*Discord) Connect

func (d *Discord) Connect(token string) (*discordgo.Session, error)

Connect to the Discord server using the given token. The Actions set on the Discord type will be used to handle the message.

type DiscordSender added in v0.1.2

type DiscordSender struct {
	// contains filtered or unexported fields
}

DiscordSender sends messages to Discord.

func (DiscordSender) Send added in v0.1.2

func (d DiscordSender) Send(msg message.Outbound) error

Send a message to Discord.

func (DiscordSender) SendString added in v0.1.13

func (d DiscordSender) SendString(channel, msg string) error

SendString builds an Outbound message and sends it.

type Dispatcher added in v0.1.13

type Dispatcher struct {
	config.Settings

	Actions []actions.Handler
}

A Dispatcher dispatches incoming messages to each of the Actions which can handle them and reply via the Author if needed.

func (Dispatcher) Dispatch added in v0.1.13

func (d Dispatcher) Dispatch(m message.Inbound, s message.Sender)

Dispatch an incoming Message to the registered Actions allowing them to respond if relevant on the Sender.

Example
d := listener.Dispatcher{
	Actions:  []actions.Handler{&actions.Echo{}},
	Settings: config.Settings{Discord: config.Discord{Prefix: "!"}},
}

c := &MockClient{
	Dispatcher: d,
}

c.Receive(message.Inbound{
	Channel: "chan",
	Content: d.Settings.Discord.Prefix + "Some amusing message",
	Author: message.User{
		ID:  "sender",
		Bot: false,
	},
})

if len(c.Messages) == 1 {
	fmt.Println(c.Messages[0].Message)
}
Output:

[chan] sender: Some amusing message

Jump to

Keyboard shortcuts

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