bear

package module
v0.2.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

bear

A bot for Rexsdev.

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 Version = "0.2.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
	Log      *logrus.Logger
	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{}) *Bear

AddHandler will add a handler to the Discord session

func (*Bear) Close

func (b *Bear) Close() *Bear

CLose will close all the sessions properly.

func (*Bear) RegisterCommand

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

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

func (*Bear) RegisterCommands

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

RegisterCommands will register an array of commands to the bot.

func (*Bear) RegisterModule

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

RegisterModule with register a module to the bot.

func (*Bear) RegisterModules

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

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

func (*Bear) Start

func (b *Bear) Start() *Bear

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 {
	GetCallers() []string
	GetHandler() func(*Context)
}

Command is the interface for a given command.

type Config

type Config struct {
	DiscordToken  string     `json:"discord_token"`
	CommandPrefix string     `json:"command_prefix"`
	AutoDelete    bool       `json:"auto_delete"`
	AdminRoles    []string   `json:"admin_roles"`
	AdminUsers    []string   `json:"admin_users"`
	Log           *LogConfig `json:"log"`
}

Config holds the configuration options for the bot.

type Context

type Context struct {
	Log       *logrus.Logger
	Session   *discordgo.Session
	ChannelID string
	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 LogConfig

type LogConfig struct {
	Debug bool   `json:"debug"`
	File  string `json:"file"`
}

LogConfig holds the configuration options for the logger.

type Module

type Module interface {
	GetName() string
	GetDesc() string
	GetCommands() []Command
	GetVersion() string
	Init(*Bear)
	Close(*Bear)
}

Module interface defines signature for a module.

Directories

Path Synopsis
cmd
bear command

Jump to

Keyboard shortcuts

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