listener

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package listener defines chat listeners for the bot.

Index

Examples

Constants

View Source
const Prefix = "!"

Prefix is used by the bot to denote a command.

Variables

This section is empty.

Functions

This section is empty.

Types

type Discord

type Discord struct {
	Actions []actions.Handler
}

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

func (*Discord) Connect

func (d *Discord) Connect(token string) error

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

func (*Discord) Handle added in v0.1.2

func (d *Discord) Handle(m Message, s Sender)

Handle an incoming Message responding via the Sender.

Example
d := listener.Discord{Actions: []actions.Handler{actions.Echo{}}}
s := &MockSender{}

m := listener.Message{
	Channel: "chan",
	Content: listener.Prefix + "Some amusing message",
	Sender: listener.User{
		ID:  "sender",
		Bot: false,
	},
}

d.Handle(m, s)

fmt.Println(s.Message)
Output:

[chan] sender: Some amusing 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(channel string, message string) error

Send a message to Discord.

type Message added in v0.1.2

type Message struct {
	Channel string
	Content string
	Sender  User
}

Message received from the chat platform.

type Sender added in v0.1.2

type Sender interface {
	// Send the message to the channel. If the message fails to send return an
	// error.
	Send(channel string, message string) error
}

A Sender is able to send a message to a chat platform.

type User added in v0.1.2

type User struct {
	ID  string
	Bot bool
}

User on the chat platform.

Jump to

Keyboard shortcuts

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