Documentation ¶
Index ¶
- Constants
- Variables
- func MemberPermissions(guild *discordgo.Guild, channel *discordgo.Channel, member *discordgo.Member) (apermissions int)
- func StartBot(token string, cmd interface{}, opts func(*Context) error) (stop func() error, err error)
- type CommandContext
- type Context
- func (ctx *Context) Call(event interface{}) error
- func (ctx *Context) Channel(channelID string) (*discordgo.Channel, error)
- func (ctx *Context) Help() string
- func (ctx *Context) Member(guildID, memberID string) (*discordgo.Member, error)
- func (ctx *Context) RegisterSubcommand(cmd interface{}) (*Subcommand, error)
- func (ctx *Context) Reply(m *discordgo.Message, reply string) error
- func (ctx *Context) Role(guildID, roleID string) (*discordgo.Role, error)
- func (ctx *Context) Send(channelID string, content interface{}) (err error)
- func (ctx *Context) Start() func()
- func (ctx *Context) UserPermissions(channelID, userID string) (apermissions int, err error)
- type Descriptor
- type ErrInvalidUsage
- type ErrUnknownCommand
- type ManualParseable
- type NameFlag
- type Namer
- type Parseable
- type RawArguments
- type Subcommand
- type Usager
Constants ¶
const FlagSeparator = 'ー'
Variables ¶
Functions ¶
Types ¶
type CommandContext ¶
type CommandContext struct { Description string Flag NameFlag // contains filtered or unexported fields }
CommandContext is an internal struct containing fields to make this library work. As such, they're all unexported. Description, however, is exported for editing, and may be used to generate more informative help messages.
func (*CommandContext) Name ¶
func (cctx *CommandContext) Name() string
func (*CommandContext) Usage ¶
func (cctx *CommandContext) Usage() []string
type Context ¶
type Context struct { *Subcommand *discordgo.Session // Descriptive (but optional) bot name Name string // Descriptive help body Description string // The prefix for commands Prefix string // FormatError formats any errors returned by anything, including the method // commands or the reflect functions. This also includes invalid usage // errors or unknown command errors. Returning an empty string means // ignoring the error. FormatError func(error) string // ErrorLogger logs any error that anything makes and the library can't // reply to the client. This includes any event callback errors that aren't // Message Create. ErrorLogger func(error) // ReplyError when true replies to the user the error. ReplyError bool // Subcommands contains all the registered subcommands. Subcommands []*Subcommand }
func New ¶
New makes a new context with a "~" as the prefix. cmds must be a pointer to a struct with a *Context field. Example:
type Commands struct { Ctx *Context } cmds := &Commands{} c, err := rfrouter.New(session, cmds)
Commands' exported methods will all be used as commands. Messages are parsed with its first argument (the command) mapped accordingly to c.MapName, which capitalizes the first letter automatically to reflect the exported method name.
The default prefix is "~", which means commands must start with "~" followed by the command name in the first argument, else it will be ignored.
c.Start() should be called afterwards to actually handle incoming events.
func (*Context) Help ¶
Help generates one. This function is used more for reference than an actual help message. As such, it only uses exported fields or methods.
func (*Context) RegisterSubcommand ¶
func (ctx *Context) RegisterSubcommand(cmd interface{}) (*Subcommand, error)
func (*Context) Send ¶
Send sends a string, an embed pointer or a MessageSend pointer. Any other type given will panic.
type Descriptor ¶
type Descriptor interface {
Description() string
}
Descriptor is optionally used to set the Description of a command context.
type ErrInvalidUsage ¶
type ErrInvalidUsage struct { Args []string Prefix string Index int Err string // contains filtered or unexported fields }
func (*ErrInvalidUsage) Error ¶
func (err *ErrInvalidUsage) Error() string
type ErrUnknownCommand ¶
type ErrUnknownCommand struct { Command string Parent string Prefix string // contains filtered or unexported fields }
func (*ErrUnknownCommand) Error ¶
func (err *ErrUnknownCommand) Error() string
type ManualParseable ¶
ManaulParseable implements a ParseContent(string) method. If the library sees this for an argument, it will send all of the arguments (including the command) into the method. If used, this should be the only argument followed after the Message Create event. Any more and the router will ignore.
type Namer ¶
type Namer interface {
Name() string
}
Namer is optionally used to override the command context's name.
type Parseable ¶
Parseable implements a Parse(string) method for data structures that can be used as arguments.
type RawArguments ¶
type RawArguments struct {
Arguments []string
}
func (*RawArguments) ParseContent ¶
func (r *RawArguments) ParseContent(args []string) error
type Subcommand ¶
type Subcommand struct { Description string // Commands contains all the registered command contexts. Commands []*CommandContext // struct flags Flag NameFlag // contains filtered or unexported fields }
func NewSubcommand ¶
func NewSubcommand(cmd interface{}) (*Subcommand, error)
func (*Subcommand) InitCommands ¶
func (sub *Subcommand) InitCommands(ctx *Context) error
InitCommands fills a Subcommand with a context. This shouldn't be called at all, rather you should use the RegisterSubcommand method of a Context.
func (*Subcommand) Name ¶
func (sub *Subcommand) Name() string
Name returns the command name in lower case. This only returns non-zero for subcommands.
func (*Subcommand) NeedsName ¶
func (sub *Subcommand) NeedsName()
NeedsName sets the name for this subcommand. Like InitCommands, this shouldn't be called at all, rather you should use RegisterSubcommand.