bf

package module
v0.0.0-...-e2b9006 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2018 License: MIT Imports: 8 Imported by: 0

README

Bf: a Discord bot framework

Bf is a Discord bot framework.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrVSNotFound  is used when a voice state can't be found
	ErrVSNotFound = errors.New("Could not find user's voice state")
	// ErrDoubleCommand is used when 2 or more commands with the same trigger are added
	ErrDoubleCommand = errors.New("2 or more commands with the same trigger detected, only one of them will never be called")
)

Functions

func Action

func Action(action func(Context)) func(*Com)

Action sets the action of the new command

func Disabled

func Disabled(disabled bool) func(*Com)

Disabled sets if the new command is disabled

func EmptyOptionFunc

func EmptyOptionFunc(b *Bot) error

EmptyOptionFunc is a OptionFunc that does nothing it is used when an error occurs

func Name

func Name(name string) func(*Com)

Name sets the name of the new command

func Trigger

func Trigger(trigger string) func(*Com)

Trigger sets the trigger of the new command

func Use

func Use(use string) func(*Com)

Use sets the use of the new command

Types

type Bot

type Bot struct {
	Mu sync.RWMutex

	Session *discordgo.Session
	Time    time.Time

	ErrWriter io.Writer
	ErrPrefix func() string

	Prefix string
	Token  string

	Commands map[string]Command
}

Bot is a wrapper for a discordgo session

func NewBot

func NewBot(options ...OptionFunc) (*Bot, error)

NewBot creates a new bot

func (*Bot) AddCommand

func (b *Bot) AddCommand(coms ...Command) error

AddCommand adds a command to the bot

func (*Bot) AddHandler

func (b *Bot) AddHandler(handler interface{})

AddHandler adds a handler to the discordgo session

func (*Bot) Close

func (b *Bot) Close() error

Close closes the discord session

func (*Bot) Error

func (b *Bot) Error(err error)

Error writes the error to the ErrWriter

func (*Bot) Open

func (b *Bot) Open() error

Open opens the discord session

func (*Bot) Restart

func (b *Bot) Restart() error

Restart closes and opens the discord session

func (*Bot) UpTime

func (b *Bot) UpTime() time.Duration

UpTime is the time the bot has been active for

func (*Bot) UpdateStatus

func (b *Bot) UpdateStatus(game string) error

UpdateStatus sets the bot's status if game == "" then set status to active and not playing anything

type Com

type Com struct {
	A func(Context)
	T string
	U string
	N string
	D bool
}

Com is a simple implementation of the Command interface

func NewCommand

func NewCommand(options ...func(*Com)) *Com

NewCommand creates a new command with the given options

func (*Com) Action

func (c *Com) Action(ctx Context)

Action calls the command'ss action

func (*Com) Disabled

func (c *Com) Disabled() bool

Disabled returns whether the command is disabled

func (*Com) Name

func (c *Com) Name() string

Name returns the command's name

func (*Com) Trigger

func (c *Com) Trigger() string

Trigger returns the command's trigger

func (*Com) Use

func (c *Com) Use() string

Use returns the command's use

type Command

type Command interface {
	Action(Context)
	Disabled() bool
	Name() string
	Use() string
	Trigger() string
}

Command describes a basic command

type Context

type Context struct {
	Bot           *Bot
	Session       *discordgo.Session
	MessageCreate *discordgo.MessageCreate

	Message string
}

Context is a struct with data for commands

func (*Context) Error

func (ctx *Context) Error(err error)

Error writes a error to the bot

func (*Context) GetVoiceConn

func (ctx *Context) GetVoiceConn(vs *discordgo.VoiceState, mute bool, deaf bool) (*discordgo.VoiceConnection, error)

GetVoiceConn joins the voice channel of the given voice state

func (*Context) GetVoiceState

func (ctx *Context) GetVoiceState() (*discordgo.VoiceState, error)

GetVoiceState tries to get the voice state of the person who triggered the command

func (*Context) JoinVoiceChannel

func (ctx *Context) JoinVoiceChannel(mute bool, deaf bool) (*discordgo.VoiceConnection, error)

JoinVoiceChannel joins the voice channel of the person who triggered the command

func (*Context) SendEmbed

func (ctx *Context) SendEmbed(embed *discordgo.MessageEmbed) error

SendEmbed sends a discordgo embed to the channel that triggerd the command

func (*Context) SendMessage

func (ctx *Context) SendMessage(message string) error

SendMessage sends a message to the channel that triggerd the command

type OptionFunc

type OptionFunc func(*Bot) error

OptionFunc is a option for the bot

func ErrPrefix

func ErrPrefix(prefunc func() string) OptionFunc

ErrPrefix sets the function that will be called and prepended to the error

func ErrWriter

func ErrWriter(w io.Writer) OptionFunc

ErrWriter sets the writer errors are written to

func Prefix

func Prefix(prefix string) OptionFunc

Prefix sets the prefix of the bot

func Token

func Token(token string) OptionFunc

Token sets the token of the bot

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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