bear

package module
v0.4.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 5 Imported by: 0

README

bear

A simple bot framework.

Documentation

Index

Constants

View Source
const (
	SuccessColor int = 5025616
	ErrorColor   int = 16007990
	InfoColor    int = 2201331
)

This is a collection of the standard colors used for messages.

Variables

View Source
var (
	ErrModuleAlreadyExists  = errors.New("module does not have a unique name")
	ErrCommandAlreadyExists = errors.New("command does not have a unique caller")
)

The errors returned from Bear commands.

View Source
var Version = "0.4.0-alpha"

Version is the current version of Bear.

Functions

This section is empty.

Types

type Bear

type Bear struct {
	Commands map[string]Command
	Modules  map[string]Module
	Session  *discordgo.Session
	Config   *Config
	Version  string
	// contains filtered or unexported fields
}

Bear is the core bot.

func New

func New(config *Config) *Bear

New returns a new Bear.

func (*Bear) AddHandler

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

AddHandler will add a handler to the Discord session

func (*Bear) Close

func (b *Bear) Close() error

Close will close all the sessions properly.

func (*Bear) RegisterCommand

func (b *Bear) RegisterCommand(cmd Command) error

RegisterCommand will check if a command exists, and add it to the bot.

func (*Bear) RegisterCommands

func (b *Bear) RegisterCommands(cmds []Command) error

RegisterCommands will register an array of commands to the bot.

func (*Bear) RegisterModule

func (b *Bear) RegisterModule(module Module) error

RegisterModule with register a module to the bot.

func (*Bear) RegisterModules

func (b *Bear) RegisterModules(modules ...Module) error

RegisterModules will register all of the modules passed to this function.

func (*Bear) Start

func (b *Bear) Start() error

Start will open the Discord session, and initialize the bot.

func (*Bear) UpdateConfig

func (b *Bear) UpdateConfig(config *Config) *Bear

UpdateConfig will update the configuration of the bot.

type Command

type Command interface {
	Callers() []string
	Handler(*Context)
}

Command is the interface for a given command.

type Config

type Config struct {
	DiscordToken string   `json:"discord_token"`
	AutoDelete   bool     `json:"auto_delete"`
	AdminRoles   []string `json:"admin_roles"`
	AdminUsers   []string `json:"admin_users"`
}

Config holds the configuration options for the bot.

type Context

type Context struct {
	ChannelID string
	Session   *discordgo.Session
	Message   *discordgo.MessageCreate
}

Context holds useful functions for a handler.

func (Context) SendEmbed

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

SendEmbed sends a custom embed message.

func (Context) SendErrorMessage

func (ctx Context) SendErrorMessage(format string, a ...interface{}) (*discordgo.Message, error)

SendErrorMessage is a quick way to send an error.

func (Context) SendInfoMessage

func (ctx Context) SendInfoMessage(format string, a ...interface{}) (*discordgo.Message, error)

SendInfoMessage is a shortcut for sending a message with the info colors.

func (Context) SendMessage

func (ctx Context) SendMessage(color int, title, format string, a ...interface{}) (*discordgo.Message, error)

SendMessage sends an embed message with a message and color.

func (Context) SendSuccessMessage

func (ctx Context) SendSuccessMessage(format string, a ...interface{}) (*discordgo.Message, error)

SendSuccessMessage is a shortcut for sending a message with the success colors.

type Module

type Module interface {
	Name() string
	Desc() string
	Commands() []Command
	Version() string
	Init(*Bear) error
	Close(*Bear) error
}

Module interface defines signature for a module.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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