commands

package
v0.0.0-...-19ad383 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePagedEmbed

func CreatePagedEmbed(out *CommandOutput, s *discordgo.Session,
	m *discordgo.MessageCreate, expirech chan struct{}, exitch chan struct{})

CreatePagedEmbed is used to create paginated embeds under a goroutine that will eventually expire and return. The operates by paging the provided *CommandOutput linked list, so long as the correct react is added to the initial embed message. To detect which reacts need to be added, the function generateOutputEmbed returns two boolean values.

The first boolean denotes previous, the second denotes next. These variables are doP and doN respectively.

func GenerateOutputEmbed

func GenerateOutputEmbed(out *CommandOutput, page *Page) (*discordgo.MessageEmbed, bool, bool)

GenerateOutputEmbed creates a Discord embed from a CommandOutput, and outputs booleans depicting whether or not the Next or Previous page of output is available

func HasNumArgs

func HasNumArgs(a BotArgs, min, max int) bool

HasNumArgs - Determine if a set of command arguments is between min and max

@a BotArgs    Argument set to process
@min int      Minimum number of positional arguments
@max int      Maximum number of positional arguments

You can use -1 in place of either min or max (or both) to disable the check
for that range.

func InitializeCommandRegistry

func InitializeCommandRegistry(r *CommandRegistrar)

InitializeCommandRegistry Register the commands for commands/everyonecmds

@r *CommandRegistrar    The command resistrar that we are initializing

Types

type BotArgs

type BotArgs []string

BotArgs - Botarguments type (for BotCommand)

type BotCommand

BotCommand - Function signature for a bots primary function

type CommandArgument

type CommandArgument [2]string

CommandArgument - Define an argument for a command

@0    Argument's invokation
@1    A description of it's effect on the command

type CommandOutput

type CommandOutput struct {
	Title       string
	Description string
	Header      string
	Quoted      bool
	Monospace   bool
	Status      int
	Color       int
	// contains filtered or unexported fields
}

CommandOutput is an object describing a commands output

func (*CommandOutput) AddLine

func (o *CommandOutput) AddLine(line string)

AddLine adds a line of output to the CommandOutput

func (*CommandOutput) Construct

func (o *CommandOutput) Construct()

Construct processes the lines in a CommandOutput object and forms a linked list of Pages to paginate through on embeds

func (*CommandOutput) Index

func (o *CommandOutput) Index() (int, int)

Index returns the current index, and the max page index

func (*CommandOutput) Loglevel

func (o *CommandOutput) Loglevel() int

Loglevel - Return the current loglevel for the CommandRegistrant

func (*CommandOutput) NextPage

func (o *CommandOutput) NextPage() *Page

NextPage returns a string of the next page, or an empty string if either the doesn't exist or is empty

func (*CommandOutput) PreviousPage

func (o *CommandOutput) PreviousPage() *Page

PreviousPage returns a string of the previuos page, or an empty string if there is no previous page, or its empty

func (*CommandOutput) RemoveLine

func (o *CommandOutput) RemoveLine()

RemoveLine removes the last line of output from the CommandOutput object

func (*CommandOutput) SetLoglevel

func (o *CommandOutput) SetLoglevel(l int)

SetLoglevel - Set the current loglevel

func (*CommandOutput) ThisPage

func (o *CommandOutput) ThisPage() *Page

ThisPage returns the current page

func (*CommandOutput) UUID

func (o *CommandOutput) UUID() string

UUID - Return a commands name.

type CommandRegistrant

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

CommandRegistrant - Command definition

func (*CommandRegistrant) Help

func (c *CommandRegistrant) Help() *CommandOutput

Help - Return a commands help text with following markdown formatting preapplied

func (*CommandRegistrant) Loglevel

func (c *CommandRegistrant) Loglevel() int

Loglevel - Return the current loglevel for the CommandRegistrant

func (*CommandRegistrant) Name

func (c *CommandRegistrant) Name() string

Name - Return a commands name.

func (*CommandRegistrant) Registrar

func (c *CommandRegistrant) Registrar() *CommandRegistrar

Registrar - Return a commands master CommandRegistrar

func (*CommandRegistrant) SetLoglevel

func (c *CommandRegistrant) SetLoglevel(l int)

SetLoglevel - Set the current loglevel

func (*CommandRegistrant) Subcommands

func (c *CommandRegistrant) Subcommands() (int, []*CommandRegistrant)

Subcommands - Return all the count of the subcommands added to a command, and their slice.

func (*CommandRegistrant) UUID

func (c *CommandRegistrant) UUID() string

UUID - Return a commands name and guild information

type CommandRegistrar

type CommandRegistrar struct {
	GuildID string
	// contains filtered or unexported fields
}

CommandRegistrar - Guild specific container for commands and authorization level settings

func NewRegistrar

func NewRegistrar(gid string, gs ifaces.IGameServer) *CommandRegistrar

NewRegistrar - Create and return a new instance of CommandRegistrar

@gid string    ID string of the guild the CommandRegistrar belongs to

func Registrar

func Registrar(gid string) (r *CommandRegistrar, err error)

Registrar - Return the Registrar that is associated with a specific guild

func (*CommandRegistrar) AllCommands

func (reg *CommandRegistrar) AllCommands() (int, []string)

AllCommands - Return an int and a string slice. The int is how many commands are currently registered, and the slice is list of their names

func (*CommandRegistrar) Command

func (reg *CommandRegistrar) Command(n string) (*CommandRegistrant, error)

Command - Return a pointer to a given registered CommandRegistrant

@n string    Name of a command
TODO: Consider refactoring this to make use of BotConfig.GetAliasesCommand

func (*CommandRegistrar) IsRegistered

func (reg *CommandRegistrar) IsRegistered(n string) bool

IsRegistered - Return true if the command is registered, false if its not

@n string    Name of a command

func (*CommandRegistrar) Loglevel

func (reg *CommandRegistrar) Loglevel() int

Loglevel - Return the current loglevel for the CommandRegistrant

func (*CommandRegistrar) ProcessCommand

func (reg *CommandRegistrar) ProcessCommand(s *discordgo.Session,
	m *discordgo.MessageCreate, c ifaces.IConfigurator,
	exitch chan struct{}) (string, ICommandError)

ProcessCommand - Processes a Discord message that has the configured prefix, and runs the correct command given its contents

@s *discordgo.Session          Discordgo Session
@m *discordgo.MessageCreate    Discordgo message event
@c IConfigurator               Bot configuration pointer

func (*CommandRegistrar) Register

func (reg *CommandRegistrar) Register(n, d, u string, a []CommandArgument,
	f BotCommand, owners ...string) error

Register - Register a command with the given options

@n string               Name
@d string               Description text
@u string               Usage text
@a []CommandArgument    Valid arguments
@f BotCommand           Function to execute

@owner ...string        Registered command to add this subcommand to

func (*CommandRegistrar) SetLoglevel

func (reg *CommandRegistrar) SetLoglevel(l int)

SetLoglevel - Set the current loglevel

func (*CommandRegistrar) UUID

func (reg *CommandRegistrar) UUID() string

UUID - Return a commands name.

type ErrCommandDisabled

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

ErrCommandDisabled describes an attempt to use a command that has been disabled

func (*ErrCommandDisabled) Command

func (e *ErrCommandDisabled) Command() *CommandRegistrant

Command returns the command object that encountered an error

func (*ErrCommandDisabled) Emit

func (e *ErrCommandDisabled) Emit(s *discordgo.Session, channel string)

Emit creates and outputs a CommandOutput with error formatting for the given error object.

func (*ErrCommandDisabled) Error

func (e *ErrCommandDisabled) Error() string

func (*ErrCommandDisabled) Subcommand

func (e *ErrCommandDisabled) Subcommand() *CommandRegistrant

Subcommand returns the subcommand object that encountered an error

type ErrCommandError

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

ErrCommandError describes a generic non-fatal error that occurred during command processing.

func (*ErrCommandError) Command

func (e *ErrCommandError) Command() *CommandRegistrant

Command returns the command object that encountered an error

func (*ErrCommandError) Emit

func (e *ErrCommandError) Emit(s *discordgo.Session, channel string)

Emit creates and outputs a CommandOutput with error formatting for the given error object.

func (*ErrCommandError) Error

func (e *ErrCommandError) Error() string

func (*ErrCommandError) Subcommand

func (e *ErrCommandError) Subcommand() *CommandRegistrant

Subcommand returns the subcommand object that encountered an error

type ErrInvalidAlias

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

ErrInvalidAlias describes an attempt to use an alias that doesn't exist

func (*ErrInvalidAlias) Command

func (e *ErrInvalidAlias) Command() *CommandRegistrant

Command returns the command object that encountered an error

func (*ErrInvalidAlias) Emit

func (e *ErrInvalidAlias) Emit(s *discordgo.Session, channel string)

Emit creates and outputs a CommandOutput with error formatting for the given error object.

func (*ErrInvalidAlias) Error

func (e *ErrInvalidAlias) Error() string

func (*ErrInvalidAlias) Subcommand

func (e *ErrInvalidAlias) Subcommand() *CommandRegistrant

Subcommand returns the subcommand object that encountered an error

type ErrInvalidArgument

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

ErrInvalidArgument describes an invalid attempt to use a command due to incorrect arguments

func (*ErrInvalidArgument) Command

func (e *ErrInvalidArgument) Command() *CommandRegistrant

Command returns the command object that encountered an error

func (*ErrInvalidArgument) Emit

func (e *ErrInvalidArgument) Emit(s *discordgo.Session, channel string)

Emit creates and outputs a CommandOutput with error formatting for the given error object.

func (*ErrInvalidArgument) Error

func (e *ErrInvalidArgument) Error() string

func (*ErrInvalidArgument) Subcommand

func (e *ErrInvalidArgument) Subcommand() *CommandRegistrant

Subcommand returns the subcommand object that encountered an error

type ErrInvalidCommand

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

ErrInvalidCommand describes an attempt to run a command that doesn't exist

func (*ErrInvalidCommand) Command

func (e *ErrInvalidCommand) Command() *CommandRegistrant

Command returns the command object that encountered an error

func (*ErrInvalidCommand) Emit

func (e *ErrInvalidCommand) Emit(s *discordgo.Session, channel string)

Emit creates and outputs a CommandOutput with error formatting for the given error object.

func (*ErrInvalidCommand) Error

func (e *ErrInvalidCommand) Error() string

func (*ErrInvalidCommand) Subcommand

func (e *ErrInvalidCommand) Subcommand() *CommandRegistrant

Subcommand returns the subcommand object that encountered an error

type ErrInvalidSubcommand

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

ErrInvalidSubcommand describes an error in which a provided subcommand does not exist

func (*ErrInvalidSubcommand) Command

Command returns the command object that encountered an error

func (*ErrInvalidSubcommand) Emit

func (e *ErrInvalidSubcommand) Emit(s *discordgo.Session, channel string)

Emit creates and outputs a CommandOutput with error formatting for the given error object.

func (*ErrInvalidSubcommand) Error

func (e *ErrInvalidSubcommand) Error() string

func (*ErrInvalidSubcommand) Subcommand

func (e *ErrInvalidSubcommand) Subcommand() *CommandRegistrant

Subcommand returns the subcommand object that encountered an error

type ErrInvalidTimezone

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

ErrInvalidTimezone describes an attempt to use an invalid timezone that was configured

func (*ErrInvalidTimezone) Command

func (e *ErrInvalidTimezone) Command() *CommandRegistrant

Command returns the command object that encountered an error

func (*ErrInvalidTimezone) Emit

func (e *ErrInvalidTimezone) Emit(s *discordgo.Session, channel string)

Emit creates and outputs a CommandOutput with error formatting for the given error object.

func (*ErrInvalidTimezone) Error

func (e *ErrInvalidTimezone) Error() string

func (*ErrInvalidTimezone) Subcommand

func (e *ErrInvalidTimezone) Subcommand() *CommandRegistrant

Subcommand returns the subcommand object that encountered an error

type ErrUnauthorizedUsage

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

ErrUnauthorizedUsage describes an attempt to run a command by someone unauthorized to do so

func (*ErrUnauthorizedUsage) Command

Command returns the command object that encountered an error

func (*ErrUnauthorizedUsage) Emit

func (e *ErrUnauthorizedUsage) Emit(s *discordgo.Session, channel string)

Emit creates and outputs a CommandOutput with error formatting for the given error object.

func (*ErrUnauthorizedUsage) Error

func (e *ErrUnauthorizedUsage) Error() string

func (*ErrUnauthorizedUsage) Subcommand

func (e *ErrUnauthorizedUsage) Subcommand() *CommandRegistrant

Subcommand returns the subcommand object that encountered an error

type ICommandError

type ICommandError interface {
	Command() *CommandRegistrant
	Subcommand() *CommandRegistrant
	Emit(*discordgo.Session, string)
	error
}

ICommandError describes an error producable by a bot command

type ICommandOutput

type ICommandOutput interface {
	Pages() []string
	Next() string
	Last() string
}

ICommandOutput descibes an interface to a commands output

type Page

type Page struct {
	Content string
	Index   int
}

Page is a single pages worth of content that is less than 1500 characters in size to confirm with the Discord embed character limit (2000)

Jump to

Keyboard shortcuts

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