discordgocmds

package module
v0.0.0-...-a2d03eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2019 License: MIT Imports: 7 Imported by: 0

README ¶

~ discordgocmds ~

Simple command parser package for discordgo



go get github.com/zekroTJA/discordgocmds

👉 GODOC


Features

  • Simply create commands with invoke aliases, permission level, description and help text by creating a class for each command exteding the Command abstract class.
  • Use whatever you want as Database source to manage permissions and guild prefixes by creating your own database driver extending the DatabaseInterface class.
  • Permission system using permission levels.
  • You can also implement your own permission system into discordjs-cmds2 by using the PermissionInterface class.
  • Group your commands together
  • Automatically created command list and help message
  • You can also replace the default help command with your own just by overwriting the help invoke.
  • Promise-Based safety: Every command will be executed in seperate threads which also will catch all exceptions thrown in the commands code.
  • Register your own logger classes based on the LoggerInterface if you want to log into a Database or whatever you want to do with it


© 2018 zekro Development
zekro.de | contact[at]zekro.de
MIT Licence

Documentation ¶

Index ¶

Constants ¶

View Source
const (
	GroupGeneral    = "GENERAL"
	GroupChat       = "CHAT"
	GroupAdmin      = "ADMIN"
	GroupModeration = "MODERATION"
	GroupFun        = "FUN"
	GroupEtc        = "ETC"
)

Variables ¶

View Source
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 (c *CmdHelp) GetDescription() string

func (*CmdHelp) GetGroup ¶

func (c *CmdHelp) GetGroup() string

func (*CmdHelp) GetHelp ¶

func (c *CmdHelp) GetHelp() string

func (*CmdHelp) GetInvokes ¶

func (c *CmdHelp) GetInvokes() []string

func (*CmdHelp) GetPermission ¶

func (c *CmdHelp) GetPermission() int

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.

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL