Documentation ¶
Index ¶
- Constants
- func PrettyDurationString(duration time.Duration) (out string)
- type AutoResponse
- type Command
- type Ctx
- func (ctx *Ctx) AddReactionHandler(messageID, reaction string, f func(ctx *Ctx)) func()
- func (ctx *Ctx) AddReactionHandlerOnce(messageID, reaction string, f func(ctx *Ctx)) func()
- func (ctx *Ctx) AddYesNoHandler(messageID string, yesFunc, noFunc func(ctx *Ctx)) func()
- func (ctx *Ctx) Check(owners []string) (err error)
- func (ctx *Ctx) CheckArgRange(min, max int) (err error)
- func (ctx *Ctx) CheckMinArgs(c int) (err error)
- func (ctx *Ctx) CheckRequiredArgs(c int) (err error)
- func (ctx *Ctx) CmdEmbed(cmd *Command) *discordgo.MessageEmbed
- func (ctx *Ctx) CommandError(err error) (error, error)
- func (ctx *Ctx) Edit(message *discordgo.Message, arg interface{}) (msg *discordgo.Message, err error)
- func (ctx *Ctx) EditEmbedf(message *discordgo.Message, title, format string, args ...interface{}) (msg *discordgo.Message, err error)
- func (ctx *Ctx) Editf(message *discordgo.Message, format string, args ...interface{}) (msg *discordgo.Message, err error)
- func (ctx *Ctx) Embed(title, description string, color int) (msg *discordgo.Message, err error)
- func (ctx *Ctx) EmbedNoXHandler(title, description string, color int) (msg *discordgo.Message, err error)
- func (ctx *Ctx) Embedf(title, format string, args ...interface{}) (msg *discordgo.Message, err error)
- func (ctx *Ctx) EmbedfNoXHandler(title, format string, args ...interface{}) (msg *discordgo.Message, err error)
- func (ctx *Ctx) GroupCmdEmbed(g *Group, cmd *Command) *discordgo.MessageEmbed
- func (ctx *Ctx) GroupEmbed(g *Group) *discordgo.MessageEmbed
- func (ctx *Ctx) Invite() string
- func (ctx *Ctx) Match(cmds ...string) bool
- func (ctx *Ctx) MatchPrefix() bool
- func (ctx *Ctx) MatchRegexp(re *regexp.Regexp) bool
- func (ctx *Ctx) PagedEmbed(embeds []*discordgo.MessageEmbed) (msg *discordgo.Message, err error)
- func (ctx *Ctx) ParseChannel(channel string) (*discordgo.Channel, error)
- func (ctx *Ctx) ParseMember(member string) (*discordgo.Member, error)
- func (ctx *Ctx) ParseRole(role string) (*discordgo.Role, error)
- func (ctx *Ctx) React(emoji string) (err error)
- func (ctx *Ctx) Send(arg interface{}) (message *discordgo.Message, err error)
- func (ctx *Ctx) SendNoAddXHandler(arg interface{}) (message *discordgo.Message, err error)
- func (ctx *Ctx) Sendf(format string, args ...interface{}) (msg *discordgo.Message, err error)
- func (ctx *Ctx) SendfNoAddXHandler(format string, args ...interface{}) (msg *discordgo.Message, err error)
- func (ctx *Ctx) TriggerTyping() (err error)
- type ErrorMissingRequiredArgs
- type ErrorNoDMs
- type ErrorNoPermissions
- type ErrorNotACommand
- type ErrorNotEnoughArgs
- type ErrorTooManyArguments
- type Group
- type PermLevel
- type Router
- func (r *Router) AddCommand(cmd *Command)
- func (r *Router) AddGroup(group *Group) *Group
- func (r *Router) AddResponse(response *AutoResponse)
- func (r *Router) Execute(ctx *Ctx, guildSettings *structs.GuildSettings) (err error)
- func (r *Router) GetCommand(name string) (c *Command)
- func (r *Router) GetGroup(name string) (group *Group)
- func (r *Router) Help(ctx *Ctx, guildSettings *structs.GuildSettings) (err error)
- func (r *Router) MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate)
- func (r *Router) Respond(s *discordgo.Session, m *discordgo.MessageCreate) (err error)
Constants ¶
const ( // SuccessEmoji is the emoji used to designate a successful action SuccessEmoji = "✅" // ErrorEmoji is the emoji used for errors ErrorEmoji = "❌" // WarnEmoji is the emoji used to warn that a command failed WarnEmoji = "⚠️" )
Variables ¶
This section is empty.
Functions ¶
func PrettyDurationString ¶
PrettyDurationString ...
Types ¶
type AutoResponse ¶
type AutoResponse struct { Triggers []string Regex *regexp.Regexp Response func(s *discordgo.Session, m *discordgo.MessageCreate) error }
AutoResponse is a single autoresponse, intended for very simple responses to exact messages that don't match commands
type Command ¶
type Command struct { Name string Aliases []string Regex *regexp.Regexp Description string LongDescription string Usage string Command func(*Ctx) error Permissions PermLevel GuildOnly bool Cooldown time.Duration Router *Router }
Command is a single command
type Ctx ¶
type Ctx struct { GuildPrefix string Command string Args []string RawArgs string Session *discordgo.Session Bot *bot.Bot BotUser *discordgo.User Database *cbdb.Db BoltDb *cbdb.BoltDb Message *discordgo.MessageCreate Channel *discordgo.Channel Author *discordgo.User Handlers *ttlcache.Cache AdditionalParams map[string]interface{} GuildSettings *structs.GuildSettings Cmd *Command }
Ctx is the context for a command
func Context ¶
func Context(prefix, messageContent string, m *discordgo.MessageCreate, b *bot.Bot) (ctx *Ctx, err error)
Context creates a new Ctx
func (*Ctx) AddReactionHandler ¶
AddReactionHandler adds a reaction handler function
func (*Ctx) AddReactionHandlerOnce ¶
AddReactionHandlerOnce adds a reaction handler function that is only called once
func (*Ctx) AddYesNoHandler ¶
AddYesNoHandler reacts with ✅ and ❌, and runs one of two functions depending on which one is used
func (*Ctx) CheckArgRange ¶
CheckArgRange checks if the number of arguments is within the given range
func (*Ctx) CheckMinArgs ¶
CheckMinArgs checks if the argument count is less than the given count
func (*Ctx) CheckRequiredArgs ¶
CheckRequiredArgs checks if the arg count is exactly the given count
func (*Ctx) CommandError ¶
CommandError sends an error message and optionally returns an error for logging purposes
func (*Ctx) Edit ¶
func (ctx *Ctx) Edit(message *discordgo.Message, arg interface{}) (msg *discordgo.Message, err error)
Edit a message
func (*Ctx) EditEmbedf ¶
func (ctx *Ctx) EditEmbedf(message *discordgo.Message, title, format string, args ...interface{}) (msg *discordgo.Message, err error)
EditEmbedf edits an embed with Embedf syntax
func (*Ctx) Editf ¶
func (ctx *Ctx) Editf(message *discordgo.Message, format string, args ...interface{}) (msg *discordgo.Message, err error)
Editf edits a message with Sendf-like syntax
func (*Ctx) EmbedNoXHandler ¶
func (ctx *Ctx) EmbedNoXHandler(title, description string, color int) (msg *discordgo.Message, err error)
EmbedNoXHandler ...
func (*Ctx) Embedf ¶
func (ctx *Ctx) Embedf(title, format string, args ...interface{}) (msg *discordgo.Message, err error)
Embedf sends a fmt.Sprintf-like input string, in an embed
func (*Ctx) EmbedfNoXHandler ¶
func (ctx *Ctx) EmbedfNoXHandler(title, format string, args ...interface{}) (msg *discordgo.Message, err error)
EmbedfNoXHandler ...
func (*Ctx) GroupCmdEmbed ¶
func (ctx *Ctx) GroupCmdEmbed(g *Group, cmd *Command) *discordgo.MessageEmbed
GroupCmdEmbed ...
func (*Ctx) GroupEmbed ¶
func (ctx *Ctx) GroupEmbed(g *Group) *discordgo.MessageEmbed
GroupEmbed ...
func (*Ctx) MatchPrefix ¶
MatchPrefix checks if the message matched any prefix
func (*Ctx) MatchRegexp ¶
MatchRegexp checks if the command matches the given regex
func (*Ctx) PagedEmbed ¶
PagedEmbed ...
func (*Ctx) ParseChannel ¶
ParseChannel takes a string and attempts to find a channel that matches that string
func (*Ctx) ParseMember ¶
ParseMember takes a string and attempts to find a member that matches that string
func (*Ctx) ParseRole ¶
ParseRole takes a string and attempts to find a role that matches that string
func (*Ctx) SendNoAddXHandler ¶
SendNoAddXHandler sends a message without adding a handler for :x:
func (*Ctx) SendfNoAddXHandler ¶
func (ctx *Ctx) SendfNoAddXHandler(format string, args ...interface{}) (msg *discordgo.Message, err error)
SendfNoAddXHandler ...
func (*Ctx) TriggerTyping ¶
TriggerTyping triggers typing in the channel the command was invoked in.
type ErrorMissingRequiredArgs ¶
ErrorMissingRequiredArgs is called when one or more required arguments is missing
func (*ErrorMissingRequiredArgs) Error ¶
func (e *ErrorMissingRequiredArgs) Error() string
type ErrorNoDMs ¶
type ErrorNoDMs struct{}
ErrorNoDMs is called when the command cannot be used in a DM
func (*ErrorNoDMs) Error ¶
func (e *ErrorNoDMs) Error() string
type ErrorNoPermissions ¶
type ErrorNoPermissions struct {
MissingPerms string
}
ErrorNoPermissions is called when the user doesn't have permission to execute the command
func (*ErrorNoPermissions) Error ¶
func (e *ErrorNoPermissions) Error() string
type ErrorNotACommand ¶
type ErrorNotACommand struct{}
ErrorNotACommand is called when the given string isn't a command.
func (*ErrorNotACommand) Error ¶
func (e *ErrorNotACommand) Error() string
type ErrorNotEnoughArgs ¶
ErrorNotEnoughArgs is called when not enough arguments were supplied
func (*ErrorNotEnoughArgs) Error ¶
func (e *ErrorNotEnoughArgs) Error() string
type ErrorTooManyArguments ¶
ErrorTooManyArguments is called when there are too many arguments
func (*ErrorTooManyArguments) Error ¶
func (e *ErrorTooManyArguments) Error() string
type Group ¶
type Group struct { Name string Aliases []string Regex *regexp.Regexp Description string Command *Command Subcommands []*Command Router *Router Cooldowns *ttlcache.Cache }
Group is a group of subcommands
func (*Group) AddCommand ¶
AddCommand adds a command to a group
func (*Group) Execute ¶
func (g *Group) Execute(ctx *Ctx, guildSettings *structs.GuildSettings) (err error)
Execute executes any command given
func (*Group) GetCommand ¶
GetCommand gets a command by name
type PermLevel ¶
type PermLevel int
PermLevel is the permission level of the command
const ( // PermLevelNone can be used by all users PermLevelNone PermLevel = iota // PermLevelHelper requires a helper role PermLevelHelper // PermLevelMod requires a moderator role PermLevelMod // PermLevelAdmin requires admin perms PermLevelAdmin // PermLevelOwner requires the person to be the bot owner PermLevelOwner )
type Router ¶
type Router struct { Commands []*Command Groups []*Group AutoResponses []*AutoResponse BotOwners []string Cooldowns *ttlcache.Cache Bot *bot.Bot }
Router is the command router
func (*Router) AddCommand ¶
AddCommand adds a command to the router
func (*Router) AddResponse ¶
func (r *Router) AddResponse(response *AutoResponse)
AddResponse adds an autoresponse to the router
func (*Router) Execute ¶
func (r *Router) Execute(ctx *Ctx, guildSettings *structs.GuildSettings) (err error)
Execute actually executes the router
func (*Router) GetCommand ¶
GetCommand gets a command by name
func (*Router) Help ¶
func (r *Router) Help(ctx *Ctx, guildSettings *structs.GuildSettings) (err error)
Help is the help command
func (*Router) MessageCreate ¶
func (r *Router) MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate)
MessageCreate handles message create events