Documentation ¶
Index ¶
- Constants
- Variables
- type Command
- type CommandOption
- type Config
- type Context
- type Discordant
- func (d *Discordant) ADMIN(name string, handler HandlerFunc, options ...CommandOption)
- func (d *Discordant) ALL(name string, handler HandlerFunc, options ...CommandOption)
- func (d *Discordant) Add(name string, handler HandlerFunc, options ...CommandOption)
- func (d *Discordant) AddHandler(handler interface{}) func()
- func (d *Discordant) CheckAccess(id string, channels ...string) bool
- func (d *Discordant) Close() error
- func (d *Discordant) Commands() map[string]Command
- func (d *Discordant) GENERAL(name string, handler HandlerFunc, options ...CommandOption)
- func (d *Discordant) GetCommand(message string) (*Command, error)
- func (d *Discordant) ID() string
- func (d *Discordant) NewContext(message *discordgo.MessageCreate, command *Command) Context
- func (d *Discordant) Run()
- func (d *Discordant) Session() *discordgo.Session
- type HandlerFunc
- type Logger
- type Option
Constants ¶
const ( ChannelAdmin = "admin" ChannelGeneral = "general" )
Channel types.
const ( DefaultCommandPrefix = "!" DefaultCommandDelimiter = " " )
Defaults.
const ( ResponseMessageFail = "```fail```" ResponseMessageFormatJSON = "```json\n%s\n```" )
Response massage layouts.
const DiscordMaxMessageLen = 2000
DiscordMaxMessageLen max discord message length.
Variables ¶
var ( // ErrEmptyToken is returned when discord bot token is empty with enabled hook. ErrEmptyToken = errors.New("discord bot token is empty") // ErrEmptyPrefix is returned when discord bot prefix is empty. ErrEmptyPrefix = errors.New("discord bot prefix is empty") // ErrEmptyChannelID is returned when discord channel id is empty with enabled hook. ErrEmptyChannelID = errors.New("discord channel id is empty") // ErrMessageTooLong is returned when message that has been sent to discord longer // than 2000 characters. ErrMessageTooLong = errors.New("discord message too long") // ErrCommandNotFound is returned if an unknown command was received. ErrCommandNotFound = errors.New("command not found") )
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct { Name string `json:"name"` Arg string `json:"arg"` Description string `json:"description"` Help string `json:"help"` Access []string `json:"access"` // contains filtered or unexported fields }
Command is the Discord command.
type CommandOption ¶
type CommandOption func(*Command)
CommandOption describes command option func.
func MiddlewareAccess ¶
func MiddlewareAccess(access ...string) CommandOption
MiddlewareAccess adds access levels.
func MiddlewareDescription ¶
func MiddlewareDescription(description string) CommandOption
MiddlewareDescription adds description to command..
type Config ¶
type Config struct { Token string `json:"token" yaml:"token"` Prefix string `json:"prefix" yaml:"prefix"` Safemode bool `json:"safemode" yaml:"safemode"` Channels map[string]string `json:"channels" yaml:"channels"` AccessOrder []string `json:"access_order" yaml:"access_order"` }
Config contains credentials for Discord server.
type Context ¶
type Context interface { Command() *Command Discordant() *Discordant Request() *discordgo.MessageCreate ChannelID() string Send(msg string, params ...string) error }
Context is an interface represents the context of the current Discord command.
type Discordant ¶
type Discordant struct {
// contains filtered or unexported fields
}
Discordant represents a connection to the Discord API.
func New ¶
func New(cfg *Config, options ...Option) (*Discordant, error)
New creates a new Discord session and will automate some startup tasks if given enough information to do so. Currently, you can pass zero arguments, and it will return an empty Discord session.
func (*Discordant) ADMIN ¶
func (d *Discordant) ADMIN(name string, handler HandlerFunc, options ...CommandOption)
ADMIN adds route handler to admin channel.
func (*Discordant) ALL ¶
func (d *Discordant) ALL(name string, handler HandlerFunc, options ...CommandOption)
ALL adds route handler to any channel.
func (*Discordant) Add ¶
func (d *Discordant) Add(name string, handler HandlerFunc, options ...CommandOption)
Add adds route handler.
func (*Discordant) AddHandler ¶
func (d *Discordant) AddHandler(handler interface{}) func()
AddHandler allows you to add an event handler that will be fired anytime the Discord WSAPI event that matches the function fires.
func (*Discordant) CheckAccess ¶
func (d *Discordant) CheckAccess(id string, channels ...string) bool
CheckAccess returns true if access is allowed.
func (*Discordant) Commands ¶
func (d *Discordant) Commands() map[string]Command
Commands returns commands list.
func (*Discordant) GENERAL ¶ added in v0.1.3
func (d *Discordant) GENERAL(name string, handler HandlerFunc, options ...CommandOption)
GENERAL adds route handler to general channel.
func (*Discordant) GetCommand ¶
func (d *Discordant) GetCommand(message string) (*Command, error)
GetCommand returns command by received message.
func (*Discordant) NewContext ¶
func (d *Discordant) NewContext(message *discordgo.MessageCreate, command *Command) Context
NewContext creates new Context.
func (*Discordant) Session ¶
func (d *Discordant) Session() *discordgo.Session
Session returns discord Session.
type HandlerFunc ¶
HandlerFunc defines a function to serve HTTP requests.
type Logger ¶
type Logger interface { Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Warningf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Debug(args ...interface{}) Info(args ...interface{}) Warning(args ...interface{}) Error(args ...interface{}) Debugln(args ...interface{}) Infoln(args ...interface{}) Warningln(args ...interface{}) Errorln(args ...interface{}) }
Logger is implemented by any logging system that is used for standard logs.
func NewDefaultLog ¶
func NewDefaultLog() Logger
NewDefaultLog creates and returns default logger to stderr.
type Option ¶
type Option func(d *Discordant)
Option can be used to a create a customized connections.
func SetSession ¶
SetSession sets discordgo session to Discordant.