cmds

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

The Commands package both contains the Manager framework and the bot commands. Everything is pretty modular and can be adapted to your own use cases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// The name of the command (What it will be triggered by).
	Name string

	// Command aliases
	Aliases []string

	// The command's description.
	Description string

	// If the command is only able to be ran by an owner.
	OwnerOnly bool

	// If the command is hidden from help.
	Hidden bool

	// The permissions the user is required to have to execute the command.
	UserPermissions permissions.Permission

	// The permissions the bot is required to have to execute the command.
	BotPermissions permissions.Permission

	// The CommandType designates where the command can be ran.
	Type CommandType

	// The function that will be executed whenever a message fits the criteria to execute the command.
	Run CommandFunc

	// The function that will be ran to process arguments
	ProcessArgs CommandArgFunc
}

A Command represents any given command contained in a bot.

func DefaultHelp

func DefaultHelp(ec int) *Command

func RemoveCommandFromSlice added in v0.3.0

func RemoveCommandFromSlice(s []*Command, i int) []*Command

type CommandArgFunc added in v0.3.0

type CommandArgFunc func([]string) interface{}

type CommandFunc

type CommandFunc func(Context, []string) error

A CommandFunc is ran whenever a CommandManager gets a message supposed to run the given command.

type CommandType

type CommandType int

A CommandType represents the locations commands can be used.

const (
	// A Command that is only supposed to run in a personal message
	CommandTypePM CommandType = iota

	// A command that is only supposed to run in a Guild
	CommandTypeGuild

	// A Command that is able to run anywhere
	CommandTypeEverywhere
)

type Context

type Context struct {
	// The connection to Discord.
	Session *discordgo.Session

	// The event that fired the CommandHandler.
	Event *discordgo.MessageCreate

	// The CommandManager that handled this command.
	Manager *Manager

	// The custom args struct for this command
	Args interface{}

	// The Message that fired this event.
	Message *discordgo.Message

	// The User that fired this event.
	User *discordgo.User

	// The Channel the event was fired in.
	Channel *discordgo.Channel

	// The guild the Channel belongs to.
	Guild *discordgo.Guild

	// The User's guild member.
	Member *discordgo.Member
}

A Context is passed to a CommandRunFunc. It contains the information needed for a command to execute.

func (*Context) PurgeMessages added in v0.3.0

func (ctx *Context) PurgeMessages(num int) error

PurgeMessages purges 'x' number of messages from the Channel a Context was initiated for.

func (*Context) Reply

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

Reply sends a message to the channel a Context was initiated for.

func (*Context) ReplyEmbed

func (ctx *Context) ReplyEmbed(embed *discordgo.MessageEmbed) (*discordgo.Message, error)

ReplyEmbed sends an embed to the channel a Context was initiated for.

func (*Context) ReplyFile

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

ReplyFile sends a file to the channel a Context was initiated for.

type Manager

type Manager struct {
	// The array of prefixes a Manager will respond to.
	Prefixes []string

	// The array of IDs that will be considered a bot owner.
	Owners []string

	// The bot instance Logger.
	Logger *logrus.Logger

	// The map of Commands in the Manager.
	Commands *[]*Command

	// If the Manager ignores bots or not.
	IgnoreBots bool

	// The function that will be ran when the Manager encounters an error.
	OnErrorFunc ManagerOnErrorFunc
}

A Manager represents a set of prefixes, owners and commands, with some extra utility to create a command handler.

func NewManager

func NewManager(l *logrus.Logger, ignoreBots bool, errorFunc ManagerOnErrorFunc) Manager

NewManager instantiates a new Manager. It returns a Manager.

func (*Manager) AddCommand added in v0.3.0

func (cmdm *Manager) AddCommand(cmd *Command)

AddCommand adds an existent command to the Manager's command list. It returns nothing.

func (*Manager) AddNewCommand added in v0.3.0

func (cmdm *Manager) AddNewCommand(name string, aliases []string, desc string, owneronly, hidden bool, userperms, botperms permissions.Permission,
	cmdType CommandType, run CommandFunc)

AddNewCommand adds a new command to the Manager's command list. It returns nothing.

func (*Manager) AddPrefix

func (cmdm *Manager) AddPrefix(prefix string)

AddPrefix adds a new prefix to the Manager's prefix list. It returns nothing.

func (*Manager) CommandHandler added in v0.3.0

func (cmdm *Manager) CommandHandler(s *discordgo.Session, m *discordgo.MessageCreate)

CommandHandler works as the Manager's message listener. It returns nothing.

func (*Manager) GetCommand

func (cmdm *Manager) GetCommand(name string) (cmd *Command, exists bool, index int)

func (*Manager) GetPrefixes

func (cmdm *Manager) GetPrefixes() []string

GetPrefixes gets the Manager's prefix list. It returns a string array.

func (*Manager) IsOwner

func (cmdm *Manager) IsOwner(id string) bool

IsOwner checks if a user ID is is in the owner list. It returns a bool.

func (*Manager) RemoveCommand added in v0.3.0

func (cmdm *Manager) RemoveCommand(name string)

RemoveCommand removes a command from the Manager's command list. It returns nothing.

func (*Manager) RemovePrefix

func (cmdm *Manager) RemovePrefix(prefix string)

RemovePrefix removes a prefix from the Manager's prefix list. It returns nothing.

func (*Manager) SetPrefixes

func (cmdm *Manager) SetPrefixes(prefixes []string)

SetPrefixes sets the Manager's prefix list. It returns nothing.

type ManagerOnErrorFunc added in v0.3.0

type ManagerOnErrorFunc func(cmdm *Manager, ctx Context, err error)

A ManagerOnErrorFunc is a function that will run whenever the Manager encounters an error.

Jump to

Keyboard shortcuts

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