handler

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBotBlocked = errors.New("bots are ignored") // If bots are ignored return to error

	ErrCommandAlreadyRegistered = errors.New("another command was already registered by this name") // If another command is already registered by this name return to error

	ErrCommandNotFound = errors.New("command not found") // If command is not found return to error

	ErrDataUnavailable = errors.New("necessary data couldn't be fetched") // ErrDataUnavailable : If bot cannot fetch data return to error

	ErrDMOnly = errors.New("dm-only command on guild") // ErrDMOnly : If DM only command is used on guild return to error

	ErrGuildOnly = errors.New("guild-only command on dm") // ErrGuildOnly : If Guild only command is used on DM return to error

	ErrOwnerOnly = errors.New("owner-only command") // ErrOwnerOnly : If someone is trying to run owner only command return to error

	ErrSelfInsufficientPermissions = errors.New("missing permission(s) for bot") // ErrSelfInsufficientPermissions : If bot doesn't have enough permission return to error

	ErrUserInsufficientPermissions = errors.New("missing permission(s) for user") // ErrUserInsufficientPermissions : If user doesn't have enough permission return to error
)

Functions

This section is empty.

Types

type Command

type Command struct {
	Aliases     []string
	Description string
	Name        string

	Hidden    bool
	OwnerOnly bool

	SelfPermissions int
	UserPermissions int

	Run CommandFunc

	Type CommandType
}

Command structure

type CommandFunc

type CommandFunc func(Context, []string) error

CommandFunc is function to run all commands

type CommandHandler

type CommandHandler struct {
	// contains filtered or unexported fields
}

CommandHandler structure

func New

func New(prefixes []string, owners []string, useState, ignoreBots, checkPermssions bool) CommandHandler

New returns a new CommandHandler

func (*CommandHandler) AddCommand

func (c *CommandHandler) AddCommand(name, desc string, aliases []string, owneronly, hidden bool, selfperms, userperms int, cmdtype CommandType, run CommandFunc) error

func (*CommandHandler) AddOwner

func (c *CommandHandler) AddOwner(id string)

func (*CommandHandler) AddPrefix

func (c *CommandHandler) AddPrefix(prefix string)

func (*CommandHandler) ClearDebugFunc

func (c *CommandHandler) ClearDebugFunc()

func (*CommandHandler) ClearHelpCommand

func (c *CommandHandler) ClearHelpCommand()

func (*CommandHandler) ClearOnErrorFunc

func (c *CommandHandler) ClearOnErrorFunc()

func (*CommandHandler) ClearPrerunFunc

func (c *CommandHandler) ClearPrerunFunc()

func (*CommandHandler) GetAllPrefixes

func (c *CommandHandler) GetAllPrefixes() []string

func (*CommandHandler) GetCheckPermissions

func (c *CommandHandler) GetCheckPermissions(enable bool) bool

func (*CommandHandler) GetDebugFunc

func (c *CommandHandler) GetDebugFunc() DebugFunc

func (*CommandHandler) GetEnable

func (c *CommandHandler) GetEnable() bool

func (*CommandHandler) GetHelpCommand

func (c *CommandHandler) GetHelpCommand() *HelpCommand

func (*CommandHandler) GetIgnoreBots

func (c *CommandHandler) GetIgnoreBots() bool

func (*CommandHandler) GetOnErrorFunc

func (c *CommandHandler) GetOnErrorFunc() OnErrorFunc

func (*CommandHandler) GetOwners

func (c *CommandHandler) GetOwners() []string

func (*CommandHandler) GetPrerunFunc

func (c *CommandHandler) GetPrerunFunc() PrerunFunc

func (*CommandHandler) GetUseState

func (c *CommandHandler) GetUseState() bool

func (*CommandHandler) IsOwner

func (c *CommandHandler) IsOwner(id string) bool

func (*CommandHandler) MessageHandler

func (c *CommandHandler) MessageHandler(s *discordgo.Session, event *discordgo.MessageCreate)

Message handler function for Command Handler.

func (*CommandHandler) RemoveCommand

func (c *CommandHandler) RemoveCommand(name string) error

func (*CommandHandler) RemoveOwner

func (c *CommandHandler) RemoveOwner(id string)

func (*CommandHandler) RemovePrefix

func (c *CommandHandler) RemovePrefix(prefix string)

func (*CommandHandler) SetAllPrefixes

func (c *CommandHandler) SetAllPrefixes(prefixes []string)

func (*CommandHandler) SetCheckPermissions

func (c *CommandHandler) SetCheckPermissions(enable bool)

func (*CommandHandler) SetDebugFunc

func (c *CommandHandler) SetDebugFunc(df DebugFunc)

func (*CommandHandler) SetEnable

func (c *CommandHandler) SetEnable(enable bool)

func (*CommandHandler) SetHelpCommand

func (c *CommandHandler) SetHelpCommand(name string, aliases []string, selfperms, userperms int, function HelpCommandFunc) error

func (*CommandHandler) SetIgnoreBots

func (c *CommandHandler) SetIgnoreBots(enable bool)

func (*CommandHandler) SetOnErrorFunc

func (c *CommandHandler) SetOnErrorFunc(oef OnErrorFunc)

func (*CommandHandler) SetOwners

func (c *CommandHandler) SetOwners(ids []string)

func (*CommandHandler) SetPrerunFunc

func (c *CommandHandler) SetPrerunFunc(prf PrerunFunc)

func (*CommandHandler) SetUseState

func (c *CommandHandler) SetUseState(enable bool)

type CommandType

type CommandType int

CommandType int

const (
	CommandTypeEverywhere CommandType = iota // CommandTypeEverywhere : command can be used on everywhere (DMs + Guilds)

	CommandTypeGuild // CommandTypeGuild : command can be only used on guilds (not DMs)

	CommandTypePrivate // CommandTypePrivate : private command type
)

type Context

type Context struct {
	Handler *CommandHandler

	Channel *discordgo.Channel

	Guild *discordgo.Guild

	Member *discordgo.Member

	Message *discordgo.Message

	Session *discordgo.Session

	User *discordgo.User
}

Context structure

func (*Context) Reply

func (c *Context) Reply(message string) (*discordgo.Message, error)

Reply sends a reply to message channel, returns *discordgo.Message and error

func (*Context) ReplyComplex

func (c *Context) ReplyComplex(message string, tts bool, embed *discordgo.MessageEmbed, files []*discordgo.File) (*discordgo.Message, error)

ReplyComplex sends complex reply to message channel, returns *discordgo.Message and error

func (*Context) ReplyDiscordgoEmbed added in v1.7.0

func (c *Context) ReplyDiscordgoEmbed(embed *discordgo.MessageEmbed) (*discordgo.Message, error)

ReplyDiscordgoEmbed replys to message channel with discordgo's embed

func (*Context) ReplyEmbed

func (c *Context) ReplyEmbed(embed embedutil.Embed) (*discordgo.Message, error)

ReplyEmbed replys to message channel with embedutil's embed

func (*Context) ReplyFile

func (c *Context) ReplyFile(filename string, file io.Reader) (*discordgo.Message, error)

ReplyFile replys to message channel with file

type DebugFunc

type DebugFunc func(string)

DebugFunc debug function

type HelpCommand

type HelpCommand struct {
	Aliases         []string
	Name            string
	SelfPermissions int
	UserPermissions int
	Run             HelpCommandFunc
}

HelpCommand struct

type HelpCommandFunc

type HelpCommandFunc func(Context, []string, []*Command, []string) error

HelpCommandFunc is help command function

type OnErrorFunc

type OnErrorFunc func(Context, *Command, []string, error)

OnErrorFunc is a function if error occurres on commands

type PrerunFunc

type PrerunFunc func(Context, *Command, []string) bool

PrerunFunc is a function when command is used

Jump to

Keyboard shortcuts

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