Documentation ¶
Index ¶
- Variables
- func BooleanTransformer(_ *Context, Arg string) (interface{}, error)
- func ChannelTransformer(ctx *Context, Arg string) (channel interface{}, err error)
- func EmbedsPaginator(ctx *Context, Pages []*disgord.Embed) error
- func IntTransformer(_ *Context, Arg string) (interface{}, error)
- func MemberTransformer(ctx *Context, Arg string) (member interface{}, err error)
- func MentionPrefix(ctx *Context, r *StringIterator) bool
- func MessageURLTransformer(ctx *Context, Arg string) (message interface{}, err error)
- func MultiplePrefixCheckers(Handlers ...PrefixCheck) func(ctx *Context, r *StringIterator) bool
- func RoleTransformer(ctx *Context, Arg string) (role interface{}, err error)
- func StaticPrefix(Prefix string) func(_ *Context, r *StringIterator) bool
- func StringTransformer(_ *Context, Arg string) (interface{}, error)
- func UIntTransformer(_ *Context, Arg string) (interface{}, error)
- func UserTransformer(ctx *Context, Arg string) (user interface{}, err error)
- type ArgTransformer
- type Category
- type CategoryInterface
- type Command
- type CommandBlank
- type CommandNotFound
- type Context
- func (c *Context) BotMember() (*disgord.Member, error)
- func (c *Context) Channel() (*disgord.Channel, error)
- func (c *Context) DisplayEmbedMenu(m *EmbedMenu) error
- func (c *Context) Replay() error
- func (c *Context) Reply(data ...interface{}) (*disgord.Message, error)
- func (c *Context) WaitForMessage(CheckFunc func(s disgord.Session, msg *disgord.Message) bool) *disgord.Message
- type CustomCommandsHandler
- type DeletedMessageHandler
- type EmbedMenu
- type ErrorHandler
- type InMemoryMessageCacheStorageAdapter
- func (c *InMemoryMessageCacheStorageAdapter) AddChannelID(GuildID, ChannelID string)
- func (c *InMemoryMessageCacheStorageAdapter) Delete(ChannelID, MessageID string)
- func (c *InMemoryMessageCacheStorageAdapter) DeleteChannelsMessages(ChannelID string)
- func (c *InMemoryMessageCacheStorageAdapter) GetAllChannelIDs(GuildID string) []string
- func (c *InMemoryMessageCacheStorageAdapter) GetAndDelete(ChannelID, MessageID string) *disgord.Message
- func (c *InMemoryMessageCacheStorageAdapter) Init()
- func (c *InMemoryMessageCacheStorageAdapter) RemoveChannelID(GuildID, ChannelID string)
- func (c *InMemoryMessageCacheStorageAdapter) RemoveGuild(GuildID string)
- func (c *InMemoryMessageCacheStorageAdapter) Set(ChannelID, MessageID string, Message *disgord.Message, Limit uint)
- type IncorrectPermissions
- type InvalidArgCount
- type InvalidTransformation
- type MenuButton
- type MenuInfo
- type MenuReaction
- type MenuReactions
- type MessageCacheStorageAdapter
- type Middleware
- type PermissionValidator
- type PrefixCheck
- type Router
- func (r *Router) AddErrorHandler(Handler ErrorHandler)
- func (r *Router) GetAllCommands() []*Command
- func (r *Router) GetCommand(Name string) *Command
- func (r *Router) GetCommandsOrderedByCategory() map[CategoryInterface][]*Command
- func (r *Router) Hook(s disgord.Session)
- func (r *Router) RemoveCommand(c *Command)
- func (r *Router) SetCommand(c *Command)
- type RouterConfig
- type StringIterator
Constants ¶
This section is empty.
Variables ¶
var ADD_REACTIONS = permissionsWrapper("Add Reactions", 0x00000040)
ADD_REACTIONS is a wrapper for the Discord permission.
var ADMINISTRATOR = permissionsWrapper("Administrator", 0x00000008)
ADMINISTRATOR is a wrapper for the Discord permission.
var ATTACH_FILES = permissionsWrapper("Attach Files", 0x00008000)
ATTACH_FILES is a wrapper for the Discord permission.
var BAN_MEMBERS = permissionsWrapper("Ban Members", 0x00000004)
BAN_MEMBERS is a wrapper for the Discord permission.
var CHANGE_NICKNAME = permissionsWrapper("Change Nickname", 0x04000000)
CHANGE_NICKNAME is a wrapper for the Discord permission.
var CONNECT = permissionsWrapper("Connect", 0x00100000)
CONNECT is a wrapper for the Discord permission.
var CREATE_INSTANT_INVITE = permissionsWrapper("Create Instant Invite", 0x00000001)
CREATE_INSTANT_INVITE is a wrapper for the Discord permission.
var DEAFEN_MEMBERS = permissionsWrapper("Deafen Members", 0x00800000)
DEAFEN_MEMBERS is a wrapper for the Discord permission.
var EMBED_LINKS = permissionsWrapper("Embed Links", 0x00004000)
EMBED_LINKS is a wrapper for the Discord permission.
var KICK_MEMBERS = permissionsWrapper("Kick Members", 0x00000002)
KICK_MEMBERS is a wrapper for the Discord permission.
var MANAGE_CHANNELS = permissionsWrapper("Manage Channels", 0x00000010)
MANAGE_CHANNELS is a wrapper for the Discord permission.
var MANAGE_EMOJIS = permissionsWrapper("Manage Emojis", 0x40000000)
MANAGE_EMOJIS is a wrapper for the Discord permission.
var MANAGE_GUILD = permissionsWrapper("Manage Guild", 0x00000020)
MANAGE_GUILD is a wrapper for the Discord permission.
var MANAGE_MESSAGES = permissionsWrapper("Manage Messages", 0x00002000)
MANAGE_MESSAGES is a wrapper for the Discord permission.
var MANAGE_NICKNAMES = permissionsWrapper("Manage Nicknames", 0x08000000)
MANAGE_NICKNAMES is a wrapper for the Discord permission.
var MANAGE_ROLES = permissionsWrapper("Manage Roles", 0x10000000)
MANAGE_ROLES is a wrapper for the Discord permission.
var MANAGE_WEBHOOKS = permissionsWrapper("Manage Webhooks", 0x20000000)
MANAGE_WEBHOOKS is a wrapper for the Discord permission.
var MENTION_EVERYONE = permissionsWrapper("Mention Everyone", 0x00020000)
MENTION_EVERYONE is a wrapper for the Discord permission.
var MOVE_MEMBERS = permissionsWrapper("Move Members", 0x01000000)
MOVE_MEMBERS is a wrapper for the Discord permission.
var MUTE_MEMBERS = permissionsWrapper("Mute Members", 0x00400000)
MUTE_MEMBERS is a wrapper for the Discord permission.
var PRIORITY_SPEAKER = permissionsWrapper("Priority Speaker", 0x00000100)
PRIORITY_SPEAKER is a wrapper for the Discord permission.
var READ_MESSAGE_HISTORY = permissionsWrapper("Read Message History", 0x00010000)
READ_MESSAGE_HISTORY is a wrapper for the Discord permission.
var SEND_MESSAGES = permissionsWrapper("Send Messages", 0x00000800)
SEND_MESSAGES is a wrapper for the Discord permission.
var SEND_TTS_MESSAGES = permissionsWrapper("Send Tts Messages", 0x00001000)
SEND_TTS_MESSAGES is a wrapper for the Discord permission.
var SPEAK = permissionsWrapper("Speak", 0x00200000)
SPEAK is a wrapper for the Discord permission.
var STREAM = permissionsWrapper("Stream", 0x00000200)
STREAM is a wrapper for the Discord permission.
var USE_EXTERNAL_EMOJIS = permissionsWrapper("Use External Emojis", 0x00040000)
USE_EXTERNAL_EMOJIS is a wrapper for the Discord permission.
var USE_VAD = permissionsWrapper("Use Vad", 0x02000000)
USE_VAD is a wrapper for the Discord permission.
var VIEW_AUDIT_LOG = permissionsWrapper("View Audit Log", 0x00000080)
VIEW_AUDIT_LOG is a wrapper for the Discord permission.
var VIEW_CHANNEL = permissionsWrapper("View Channel", 0x00000400)
VIEW_CHANNEL is a wrapper for the Discord permission.
Functions ¶
func BooleanTransformer ¶
BooleanTransformer is used to transform an argument into a boolean if possible.
func ChannelTransformer ¶
ChannelTransformer is used to transform a channel if possible.
func EmbedsPaginator ¶
EmbedsPaginator is used to paginate together several embeds.
func IntTransformer ¶
IntTransformer is used to transform an arg to a integer if possible.
func MemberTransformer ¶
MemberTransformer is used to transform a member if possible.
func MentionPrefix ¶
func MentionPrefix(ctx *Context, r *StringIterator) bool
MentionPrefix is used to handle a mention which is being used as a prefix.
func MessageURLTransformer ¶
MessageURLTransformer is used to transform a message URL to a message if possible.
func MultiplePrefixCheckers ¶
func MultiplePrefixCheckers(Handlers ...PrefixCheck) func(ctx *Context, r *StringIterator) bool
MultiplePrefixCheckers is used to handle multiple prefix checkers.
func RoleTransformer ¶
RoleTransformer is used to transform a role if possible.
func StaticPrefix ¶
func StaticPrefix(Prefix string) func(_ *Context, r *StringIterator) bool
StaticPrefix is used for simple static prefixes.
func StringTransformer ¶
StringTransformer just takes the argument and returns it.
func UIntTransformer ¶
UIntTransformer is used to transform an arg to a unsigned integer if possible.
func UserTransformer ¶
UserTransformer is used to transform a user if possible.
Types ¶
type ArgTransformer ¶
type ArgTransformer struct { // Greedy defines if the parser should keep going until an argument fails. Greedy bool // Optional defines if the argument is optional. This can be mixed with greedy or remainder. // This has to be at the end of the argument list. Optional bool // Remainder defines if it should just parse the rest of the arguments. // Remainders need to be at the end of a command. Remainder bool // Function is used to transform the argument. The function should error if this is not possible. Function func(ctx *Context, Arg string) (interface{}, error) }
ArgTransformer defines a transformer which is to be used on arguments.
type Category ¶
type Category struct { Name string `json:"name"` Description string `json:"description"` PermissionValidators []PermissionValidator `json:"-"` Middleware []Middleware `json:"-"` }
Category is the generic category struct which uses the category interface.
func (*Category) GetDescription ¶
GetDescription is used to get the description of the category.
func (*Category) GetMiddleware ¶
func (c *Category) GetMiddleware() []Middleware
GetMiddleware is used to get the middleware of the category.
func (*Category) GetPermissionValidators ¶
func (c *Category) GetPermissionValidators() []PermissionValidator
GetPermissionValidators is used to get the permission validators of the category.
type CategoryInterface ¶
type CategoryInterface interface { GetName() string GetDescription() string GetPermissionValidators() []func(ctx *Context) (string, bool) // If I change this to the PermissionValidator type, it triggers #25838 in Go. GetMiddleware() []Middleware }
CategoryInterface is the interface which is used for categories. This can be used to write your own category handler if you wish.
type Command ¶
type Command struct { Name string `json:"name"` Aliases []string `json:"aliases"` Description string `json:"description"` Usage string `json:"usage"` Category CategoryInterface `json:"category"` PermissionValidators []PermissionValidator `json:"-"` ArgTransformers []ArgTransformer `json:"-"` Middleware []Middleware `json:"-"` Function func(ctx *Context) error `json:"-"` }
Command defines a command which can be used within the Router.
func (*Command) HasPermission ¶
HasPermission is used to run through the permission validators and check if the user has permission. The error will be of the IncorrectPermissions type if they do not have permission.
type CommandBlank ¶
type CommandBlank struct {
// contains filtered or unexported fields
}
CommandBlank is the error which is thrown when the command is blank.
func (*CommandBlank) Error ¶
func (c *CommandBlank) Error() string
Error is used to give the error description.
type CommandNotFound ¶
type CommandNotFound struct {
// contains filtered or unexported fields
}
CommandNotFound is the error which is thrown when a command is not found.
func (*CommandNotFound) Error ¶
func (c *CommandNotFound) Error() string
Error is used to give the error description.
type Context ¶
type Context struct { Prefix string `json:"prefix"` Message *disgord.Message `json:"message"` BotUser *disgord.User `json:"botUser"` Router *Router `json:"-"` Session disgord.Session `json:"session"` Command *Command `json:"command"` RawArgs string `json:"rawArgs"` Args []interface{} `json:"args"` MiddlewareParams map[string]interface{} `json:"middlewareParams"` }
Context defines the information which might be required to run the command.
func (*Context) BotMember ¶
BotMember is used to get the bot as a member of the server this was within.
func (*Context) DisplayEmbedMenu ¶
DisplayEmbedMenu is used to allow you to easily display a embed menu.
type CustomCommandsHandler ¶
type CustomCommandsHandler = func(ctx *Context, cmdname string, r *StringIterator) (bool, error)
CustomCommandsHandler is the handler which is used for custom commands. An error being returned by the custom commands handler will return in that being passed through to the error handler instead. true here represents this being a custom command. This means the Router will not go through the errors handler unless an error is set.
type DeletedMessageHandler ¶
type DeletedMessageHandler struct { MessageCacheStorageAdapter MessageCacheStorageAdapter `json:"-"` Callback func(s disgord.Session, msg *disgord.Message) `json:"-"` // Limit defines the amount of messages. // -1 = unlimited (not suggested if it's in-memory since it'll lead to memory leaks), 0 = default, >0 = user set maximum Limit int `json:"limit"` }
DeletedMessageHandler is used to handle dispatching events for deleted messages. It does this by using the storage adapter to log messages, then the message is deleted from the database at the message limit or when the deleted message handler is called.
type EmbedMenu ¶
type EmbedMenu struct { Reactions *MenuReactions Embed *disgord.Embed MenuInfo *MenuInfo // contains filtered or unexported fields }
EmbedMenu is the base menu.
func NewEmbedMenu ¶
NewEmbedMenu is used to create a new menu handler.
func (*EmbedMenu) AddBackButton ¶
func (e *EmbedMenu) AddBackButton()
AddBackButton is used to add a back Button to the page.
func (*EmbedMenu) AddParentMenu ¶
AddParent is used to add a new parent menu.
func (*EmbedMenu) Display ¶
Display is used to show a menu. This is un-protected so that people can write their own things on top of embed menus, but you probably want to use ctx.DisplayEmbedMenu(menu).
func (*EmbedMenu) NewChildMenu ¶
func (e *EmbedMenu) NewChildMenu(embed *disgord.Embed, item MenuButton) *EmbedMenu
NewChildMenu is used to create a new child menu.
type ErrorHandler ¶
ErrorHandler is a function which is used to handle errors. true here means that the error was handled by this handler. If this is false, the processor will go to the next handler.
type InMemoryMessageCacheStorageAdapter ¶
type InMemoryMessageCacheStorageAdapter struct {
// contains filtered or unexported fields
}
InMemoryMessageCacheStorageAdapter is used to hold cached messages in RAM. This is extremely fast, but will lead to increased RAM usage.
func (*InMemoryMessageCacheStorageAdapter) AddChannelID ¶
func (c *InMemoryMessageCacheStorageAdapter) AddChannelID(GuildID, ChannelID string)
AddChannelID is used to add a channel ID to the guild.
func (*InMemoryMessageCacheStorageAdapter) Delete ¶
func (c *InMemoryMessageCacheStorageAdapter) Delete(ChannelID, MessageID string)
Delete is used to delete a specific message from the cache.
func (*InMemoryMessageCacheStorageAdapter) DeleteChannelsMessages ¶
func (c *InMemoryMessageCacheStorageAdapter) DeleteChannelsMessages(ChannelID string)
DeleteChannelsMessages is used to delete a channels messages from a cache.
func (*InMemoryMessageCacheStorageAdapter) GetAllChannelIDs ¶
func (c *InMemoryMessageCacheStorageAdapter) GetAllChannelIDs(GuildID string) []string
GetAllChannelIDs is used to get all of the channel ID's.
func (*InMemoryMessageCacheStorageAdapter) GetAndDelete ¶
func (c *InMemoryMessageCacheStorageAdapter) GetAndDelete(ChannelID, MessageID string) *disgord.Message
GetAndDelete is used to get and delete from the cache where this is possible.
func (*InMemoryMessageCacheStorageAdapter) Init ¶
func (c *InMemoryMessageCacheStorageAdapter) Init()
Init is used to initialise the in-memory message cache.
func (*InMemoryMessageCacheStorageAdapter) RemoveChannelID ¶
func (c *InMemoryMessageCacheStorageAdapter) RemoveChannelID(GuildID, ChannelID string)
RemoveChannelID is used to remove a channel ID to the guild.
func (*InMemoryMessageCacheStorageAdapter) RemoveGuild ¶
func (c *InMemoryMessageCacheStorageAdapter) RemoveGuild(GuildID string)
RemoveGuild is used to remove a guild from the cache.
type IncorrectPermissions ¶
type IncorrectPermissions struct {
// contains filtered or unexported fields
}
IncorrectPermissions is the error which is thrown when the user does not have enough permissions.
func (*IncorrectPermissions) Error ¶
func (c *IncorrectPermissions) Error() string
Error is used to give the error description.
type InvalidArgCount ¶
type InvalidArgCount struct {
// contains filtered or unexported fields
}
InvalidArgCount is the error when the arg count is not correct.
func (*InvalidArgCount) Error ¶
func (c *InvalidArgCount) Error() string
Error is used to give the error description.
type InvalidTransformation ¶
type InvalidTransformation struct {
Description string
}
InvalidTransformation is the error argument parsers should use when they can't transform.
func (*InvalidTransformation) Error ¶
func (c *InvalidTransformation) Error() string
Error is used to give the error description.
type MenuButton ¶
MenuButton is the datatype containing information about the button.
type MenuReaction ¶
type MenuReaction struct { Button MenuButton Function func(ChannelID, MessageID snowflake.Snowflake, _ *EmbedMenu, client disgord.Session) }
MenuReaction represents the button and the function which it triggers.
type MenuReactions ¶
type MenuReactions struct {
ReactionSlice []MenuReaction
}
MenuReactions are all of the reactions which the menu has.
func (*MenuReactions) Add ¶
func (mr *MenuReactions) Add(reaction MenuReaction)
Add is used to add a menu reaction.
type MessageCacheStorageAdapter ¶
type MessageCacheStorageAdapter interface { // Called when the router is created. Init() // Related to message caching. GetAndDelete(ChannelID, MessageID string) *disgord.Message Delete(ChannelID, MessageID string) DeleteChannelsMessages(ChannelID string) Set(ChannelID, MessageID string, Message *disgord.Message, Limit uint) // Related to channel and guild ID relationship caching. // Channel ID's are NOT confirmed to be unique and will be repeated on bot reboot as per the Discord API. // You should manage this in your adapter. GetAllChannelIDs(GuildID string) []string AddChannelID(GuildID, ChannelID string) RemoveChannelID(GuildID, ChannelID string) RemoveGuild(GuildID string) }
MessageCacheStorageAdapter is the interface which is used for message cache storage adapters.
type Middleware ¶
Middleware is used to handle setting data within the context before the command is ran. This is useful if there is stuff you want to do, but you don't want to type on every command. If this errors, it will just get passed through to the error handler.
type PermissionValidator ¶
PermissionValidator is a function which is used to validate someones permissions who is running a command. If the boolean is set to true, it means the user has permissions. If it is false, the user does not, and the string will be used as the error with the IncorrectPermissions type.
type PrefixCheck ¶
type PrefixCheck = func(ctx *Context, r *StringIterator) bool
PrefixCheck is the type for a function to check the prefix. true here means the prefix is there and was read. Note that prefix functions cannot see the member object in the message since that is patched in AFTER this is ran.
type Router ¶
type Router struct { BotUser *disgord.User `json:"-"` PrefixCheck PrefixCheck `json:"-"` CustomCommandsHandler CustomCommandsHandler `json:"-"` DeletedMessageHandler *DeletedMessageHandler // contains filtered or unexported fields }
Router defines the command router which is being used. Please call NewRouter to initialise this rather than creating a new struct.
func NewRouter ¶
func NewRouter(Config *RouterConfig) *Router
NewRouter creates a new command Router.
func (*Router) AddErrorHandler ¶
func (r *Router) AddErrorHandler(Handler ErrorHandler)
AddErrorHandler is used to add a error handler to the Router. An error handler takes the structure of the ErrorHandler type above. Error handlers are executed in the order in which they are added to the Router.
func (*Router) GetAllCommands ¶
GetAllCommands is used to get all of the commands.
func (*Router) GetCommand ¶
GetCommand is used to get a command from the Router if it exists. If the command doesn't exist, this will be a nil pointer.
func (*Router) GetCommandsOrderedByCategory ¶
func (r *Router) GetCommandsOrderedByCategory() map[CategoryInterface][]*Command
GetCommandsOrderedByCategory is used to order commands by the categories.
func (*Router) RemoveCommand ¶
RemoveCommand is used to remove a command from the Router.
func (*Router) SetCommand ¶
SetCommand is used to set a command.
type RouterConfig ¶
type RouterConfig struct { DeletedMessageHandler *DeletedMessageHandler PrefixCheck PrefixCheck ErrorHandlers []ErrorHandler PermissionValidators []PermissionValidator Middleware []Middleware }
RouterConfig defines the config which will be used for the Router.
type StringIterator ¶
type StringIterator struct { Text string `json:"text"` Pos uint `json:"pos"` // contains filtered or unexported fields }
StringIterator is used to iterate through a string but keep track of the position. This also allows for the ability to rewind a string. This is NOT designed to be thread safe.
func (*StringIterator) GetChar ¶
func (s *StringIterator) GetChar() (char uint8, err error)
GetChar is used to get a character from the string.
func (*StringIterator) GetRemainder ¶
func (s *StringIterator) GetRemainder(FillIterator bool) (remainder string, err error)
GetRemainder is used to get the remainder of a string. FillIterator defines if the iterators count should be affected by this.
func (*StringIterator) Rewind ¶
func (s *StringIterator) Rewind(N uint)
Rewind is used to rewind a string iterator N number of chars.
Source Files ¶
- category.go
- command.go
- context.go
- default_help_command.go
- default_prefix_checkers.go
- deleted_message_handler.go
- discord_permissions.go
- disgord_command_events.go
- embed_menus.go
- embeds_paginator.go
- errors.go
- get_mention.go
- in_memory_message_cache_storage_adapter.go
- router.go
- string_iterator.go
- test_helpers.go
- transformers.go