Documentation ¶
Overview ¶
Package listener defines chat listeners for the bot.
Index ¶
- Variables
- func ConsoleClient(dispatcher Dispatcher, _ config.Settings) message.Sender
- func DiscordClient(dispatcher Dispatcher, settings config.Settings) (message.Sender, error)
- func Start(dispatcher Dispatcher, settings config.Settings) (message.Sender, error)
- type Console
- type Discord
- type DiscordSender
- type Dispatcher
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrConnectionFailure = errors.New("failed to connect to server")
ErrConnectionFailure is returned if there was an error connecting to the server for any reason.
var ErrInvalidClientConfig = errors.New("invalid client config")
ErrInvalidClientConfig is returned if the bot is started with a client config name it doesn't recognise.
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
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.
Types ¶
type Console ¶ added in v0.1.13
type Console struct {
Dispatcher
}
Console client.
func (Console) Send ¶ added in v0.1.13
Send will output the message component of the Outbound to STDOUT.
func (Console) SendString ¶ added in v0.1.13
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.
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
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