Commands

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2020 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

The Commands package both contains the CommandManager 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

func AboutCommand

func AboutCommand(ctx CommandContext, args []string) error

AboutCommand is a CommandRunFunc. It supplies the user who runs it information about the bot. It returns an error if any occurred.

func HelpCommand

func HelpCommand(ctx CommandContext, args []string) error

HelpCommand is a CommandRunFunc. It supplies the user a list of commands in the CommandManager it is assigned to. It returns an error if any occurred.

func InviteCommand added in v0.8.0

func InviteCommand(ctx CommandContext, args []string) error

InviteCommand is a CommandRunFunc. It supplies the user an invite to the bot. It returns an error if any occurred.

func LoadTags

func LoadTags(f string, log *logrus.Logger)

LoadTags loads the tags from a given file. It returns nothing.

func OwnerCommand

func OwnerCommand(ctx CommandContext, args []string) error

OwnerCommand is a CommandRunFunc. It currently has no use. It returns an error if any occurred.

func PingCommand

func PingCommand(ctx CommandContext, args []string) error

PingCommand is a CommandRunFunc. It supplies the user a message if the bot is alive. It returns an error if any occurred.

func SuggestCommand added in v0.10.0

func SuggestCommand(ctx CommandContext, args []string) error

func TagCommand

func TagCommand(ctx CommandContext, args []string) error

TagCommand is a CommandRunFunc. It supplies the user with the tag description if the tag supplied exists. It returns an error if any occurred.

func UserInfoCommand added in v0.10.0

func UserInfoCommand(ctx CommandContext, args []string) error

UserInfoCommand is a CommandRunFunc. It supplies the user information about another user. It returns an error if any occurred.

Types

type Command

type Command struct {
	// The name of the command (What it will be triggered by).
	Name 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 Shared.Permission

	// The permissions the bot is required to have to execute the command.
	BotPermissions Shared.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
}

A Command represents any given command contained in a bot.

func NewAboutCommand

func NewAboutCommand() *Command

NewAboutCommand returns a new AboutCommand for use in a CommandManager. It returns a Command struct.

func NewHelpCommand

func NewHelpCommand() *Command

NewHelpCommand returns a new HelpCommand for use in a CommandManager. It returns a Command struct.

func NewInviteCommand added in v0.8.0

func NewInviteCommand() *Command

NewInviteCommand returns a new InviteCommand for use in a CommandManager. It returns a Command struct.

func NewOwnerCommand

func NewOwnerCommand() *Command

NewOwnerCommand returns a new OwnerCommand for use in a CommandManager. It returns a Command struct.

func NewPingCommand

func NewPingCommand() *Command

NewPingCommand returns a new PingCommand for use in a CommandManager. It returns a Command struct.

func NewSuggestCommand added in v0.10.0

func NewSuggestCommand() *Command

func NewTagCommand

func NewTagCommand() *Command

NewTagCommand returns a new TagCommand for use in a CommandManager. It returns a Command struct.

func NewUserInfoCommand added in v0.10.0

func NewUserInfoCommand() *Command

NewUserInfoCommand returns a new UserInfoCommand for use in a CommandManager. It returns a Command struct.

type CommandContext

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

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

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

	// The bot's StatusManager.
	StatusManager *Status.StatusManager

	// 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 CommandContext is passed to a CommandRunFunc. It contains the information needed for a command to execute.

func (*CommandContext) Reply

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

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

func (*CommandContext) ReplyEmbed

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

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

func (*CommandContext) ReplyFile

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

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

type CommandFunc

type CommandFunc func(CommandContext, []string) error

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

type CommandManager

type CommandManager struct {
	// The bot configuration
	Config Configuration.Configuration

	// The array of prefixes a CommandManager will respond to.
	Prefixes []string

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

	// The bot's StatusManager.
	StatusManager *Status.StatusManager

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

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

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

	// The function that will be ran when the CommandManager encounters an error.
	OnErrorFunc CommandManagerOnErrorFunc
}

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

func NewCommandManager

func NewCommandManager(c Configuration.Configuration, sm *Status.StatusManager, l *logrus.Logger, ignoreBots bool, errorFunc CommandManagerOnErrorFunc) CommandManager

NewCommandManager instantiates a new CommandManager. It returns a CommandManager.

func (*CommandManager) AddCommand

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

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

func (*CommandManager) AddNewCommand

func (cmdm *CommandManager) AddNewCommand(name, desc string, owneronly, hidden bool, userperms, botperms Shared.Permission,
	cmdType CommandType, run CommandFunc)

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

func (*CommandManager) AddPrefix

func (cmdm *CommandManager) AddPrefix(prefix string)

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

func (*CommandManager) CommandHandler

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

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

func (*CommandManager) GetPrefixes

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

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

func (*CommandManager) IsOwner

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

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

func (*CommandManager) RemoveCommand

func (cmdm *CommandManager) RemoveCommand(name string)

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

func (*CommandManager) RemovePrefix

func (cmdm *CommandManager) RemovePrefix(prefix string)

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

func (*CommandManager) SetPrefixes

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

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

type CommandManagerOnErrorFunc

type CommandManagerOnErrorFunc func(cmdm *CommandManager, err error)

A CommandManagerOnErrorFunc is a function that will run whenever the CommandManager encounters an error.

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
)

Jump to

Keyboard shortcuts

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