bot

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

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

Bot contains the connection information and commands used to communicate with Discord.

func New

func New(cfg *config.Config, s DiscordSession) (*Bot, error)

New returns a new instance of a Bot and establishes the connection to discord.

func (*Bot) AddCommand

func (b *Bot) AddCommand(command SlateCommand)

AddCommand allows a new command to be registered with the bot

func (*Bot) Commands

func (b *Bot) Commands() []SlateCommand

Commands returns the list of commands

func (*Bot) Stop

func (b *Bot) Stop() error

Stop cleanly closes the connection to Discord

type DiscordFactory

type DiscordFactory func(cfg *config.Config) (DiscordSession, error)

DiscordFactory describes a factory function used to create a discord session.

cfg: The slate configuration object.

type DiscordSession

type DiscordSession interface {
	// AddHandler adds a function handler to Discord.
	AddHandler(interface{}) func()

	// ChannelMessageSend allows a message to be sent to a channel on Discord
	// todo: Remove the hard reference to discordgo
	ChannelMessageSend(string, string) (*discordgo.Message, error)

	// Open establishes the websocket connection to Discord.
	Open() error

	// Close closes the websocket connection to Discord.
	Close() error
}

DiscordSession describes the functions required to work with discord

func MockDiscordFactory

func MockDiscordFactory(cfg *config.Config) (DiscordSession, error)

MockDiscordFactory is a DiscordFactory mock function for the MockDiscordSession

type MockCommand

type MockCommand struct {
	mock.Mock
}

MockCommand is a mock command handler

func (*MockCommand) Execute

func (c *MockCommand) Execute(ctx context.Context, f *flag.FlagSet) string

Execute runs the command

func (*MockCommand) Name

func (*MockCommand) Name() string

Name returns the name of the command

func (*MockCommand) SetFlags

func (c *MockCommand) SetFlags(f *flag.FlagSet)

SetFlags sets the flags for the commands

func (*MockCommand) Synopsis

func (*MockCommand) Synopsis() string

Synopsis returns the synospis of the command

func (*MockCommand) Usage

func (*MockCommand) Usage() string

Usage returns the usage of the command

type MockDiscordSession

type MockDiscordSession struct {
	mock.Mock
}

MockDiscordSession mocks a discord session object

func (*MockDiscordSession) AddHandler

func (m *MockDiscordSession) AddHandler(h interface{}) func()

AddHandler is a stub

func (*MockDiscordSession) ChannelMessageSend

func (m *MockDiscordSession) ChannelMessageSend(ch string, message string) (*discordgo.Message, error)

ChannelMessageSend is a stub

func (*MockDiscordSession) Close

func (m *MockDiscordSession) Close() error

Close is a stub

func (*MockDiscordSession) Open

func (m *MockDiscordSession) Open() error

Open is a stub

type SlateCommand

type SlateCommand interface {
	// Name describes the string used to route input to this command
	Name() string

	// Synopsis describes what the command will do
	Synopsis() string

	// Usage describes the helpfile and usage for this command
	Usage() string

	// SetFlags sets up any flags the command requires
	SetFlags(set *flag.FlagSet)

	// Execute is the handler which will be run when this command is called
	Execute(context.Context, *flag.FlagSet) string
}

SlateCommand describes a command to be registered with slate.

Jump to

Keyboard shortcuts

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