Documentation
¶
Index ¶
Constants ¶
const ( GroupGeneral = "GENERAL" GroupChat = "CHAT" GroupAdmin = "ADMIN" GroupModeration = "MODERATION" GroupFun = "FUN" GroupEtc = "ETC" )
Variables ¶
var ( EmbedColor = 0xFFEB3B ErrorColor = 0xf44336 )
Functions ¶
This section is empty.
Types ¶
type CmdHandler ¶
type CmdHandler struct {
// contains filtered or unexported fields
}
CmdHandler is the main controller of the command handler and contains the bot session, the registered commands and registers the message handler checking messages for commands.
func New ¶
func New(session *discordgo.Session, dbMiddleware DatabaseMiddleware, options *CmdHandlerOptions) *CmdHandler
New creates a new instance of CmdHandler by passing the discordgo session, the database middleware instance and the command handler options as argument.
func (*CmdHandler) RegisterCommand ¶
func (c *CmdHandler) RegisterCommand(cmd Command)
RegisterCommand registers a Command class in the command handler and will be available for execution.
type CmdHandlerOptions ¶
type CmdHandlerOptions struct { Prefix string BotOwnerID string OwnerPermissionLevel int DefaultColor int InvokeToLower bool ParseMsgEdit bool ReactToBots bool DeleteCmdMessages bool }
CmdHandlerOptions is used to pass general options to the CmdHandler.
func NewCmdHandlerOptions ¶
func NewCmdHandlerOptions() *CmdHandlerOptions
NewCmdHandlerOptions creates a new instance of CmdHandlerOptions with the default configuration settings.
type CmdHelp ¶
type CmdHelp struct{}
func (*CmdHelp) Exec ¶
func (c *CmdHelp) Exec(args *CommandArgs) error
func (*CmdHelp) GetDescription ¶
func (*CmdHelp) GetInvokes ¶
func (*CmdHelp) GetPermission ¶
type Command ¶
type Command interface { GetInvokes() []string GetDescription() string GetHelp() string GetGroup() string GetPermission() int Exec(args *CommandArgs) error }
Command is the interface containing Functions a command should have
type CommandArgs ¶
type CommandArgs struct { Channel *discordgo.Channel User *discordgo.User Guild *discordgo.Guild Message *discordgo.Message Args []string Session *discordgo.Session CmdHandler *CmdHandler }
CommandArgs will be passed to the command Exec function and contains the Channel, User, Guild, Message, Session and Command Handler Object pointers and the list of command arguments
type DatabaseMiddleware ¶
type DatabaseMiddleware interface { // GetUserPermissionLevel returns the requested users // permission level number from the database or // and error, if the request failed for some reason. GetUserPermissionLevel(userID string, roles []string) (int, error) // GetGuildPrefix returns the requested guilds custom // prefix, if set. If the prefix was not set on the // guild, the function must return an empty string (""). // If the reuest failed for some reason, the function // returns an error. GetGuildPrefix(guildID string) (string, error) }
DatabaseMiddleware is an interface defining how to build a struct used by the command handler to communicate with your database, for example a MySql database.
type DefaultPermissionHandler ¶
type DefaultPermissionHandler struct {
// contains filtered or unexported fields
}
DefaultPermissionHandler is the default handler for level based permission handling
func NewDefaultPermissionHandler ¶
func NewDefaultPermissionHandler(db DatabaseMiddleware) *DefaultPermissionHandler
NewDefaultPermissionHandler creates an instance of DefaultPermissionHandler getting passed the instance of the database middileware
func (*DefaultPermissionHandler) CheckUserPermission ¶
func (p *DefaultPermissionHandler) CheckUserPermission(cmdArgs *CommandArgs, s *discordgo.Session, cmdInstance Command) (bool, error)
CheckUserPermission compares the command executing users permission level to the required permission level of the command and returns if the user matches the required permission.
type PermissionHandler ¶
type PermissionHandler interface { // CheckUserPermission is getting passed the command arguments and the // instance of the command struct and returns a bool if the user is // permitted to use this command or an error, if the permission check // has failed for any reason, which will automatically count as // 'no permission'. CheckUserPermission(cmdArgs *CommandArgs, s *discordgo.Session, cmdInstance Command) (bool, error) }
PermissionHandler describes a struct handling permission of users using specific commands. By implementing this interface, you can create your own permission handler.