route

package module
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2021 License: MIT Imports: 15 Imported by: 4

README

route

Command router for Snart.

Documentation

Overview

Package route contains a command Route for Snart.

Index

Constants

View Source
const GlobalGuildID = discord.NullGuildID

GlobalGuildID is the GuildID used for global configurations.

View Source
const KeyPrefix = "prefix"

KeyPrefix is the Confy key used to load/store prefixes.

Variables

View Source
var (
	// ErrCmdNotFound occurs when an unknown command is called.
	ErrCmdNotFound = errors.New("command not found")

	// ErrNoCmd occurs when there is no command after the prefix.
	ErrNoCmd = errors.New("no command")
)
View Source
var ErrNoLinePrefix = errors.New("no prefix in line")

ErrNoLinePrefix occurs when a line doesn't start with a valid prefix.

Functions

This section is empty.

Types

type Cmd added in v0.8.1

type Cmd struct {
	Name  string
	Desc  string
	Cat   string
	Func  Func
	Hide  bool
	Flags interface{}
}

Cmd is a command.

type CmdStore added in v0.9.1

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

CmdStore is a concurrent-safe store of Cmds.

func NewCmdStore added in v0.12.0

func NewCmdStore() *CmdStore

NewCmdStore creates a usable CmdStore.

func (*CmdStore) Add added in v0.12.0

func (c *CmdStore) Add(cmd Cmd)

Add stores a Cmd, using its defined name.

func (*CmdStore) ByCat added in v0.12.0

func (c *CmdStore) ByCat(hidden bool) (map[string][]Cmd, []string)

ByCat creates a map of sorted Cmd categories, and a sorted list of category names.

If hidden is true, Cmds with the Hide flag will be included.

func (*CmdStore) Del added in v0.12.0

func (c *CmdStore) Del(name string)

Del removes a Cmd with the given name.

func (*CmdStore) Get added in v0.12.0

func (c *CmdStore) Get(name string) (Cmd, bool)

Get fetches a Cmd with the given name.

type Func added in v0.6.0

type Func = func(*Trigger) error

Func is a handler for a Trigger.

type Prefix added in v0.3.0

type Prefix struct {
	Value string
	Clean string
}

Prefix is a command prefix.

type PrefixStore added in v0.9.1

type PrefixStore struct {
	Confy confy.Confy
	// contains filtered or unexported fields
}

PrefixStore describes a concurrent-safe store of Guild-specific command prefixes.

func OpenPrefixStore added in v0.12.0

func OpenPrefixStore(c confy.Confy) (*PrefixStore, error)

OpenPrefixStore creates a usable PrefixStore and calls Load.

func (*PrefixStore) Del added in v0.12.0

func (p *PrefixStore) Del(g discord.GuildID)

Del removes the prefix for the given GuildID from the PrefixStore.

func (*PrefixStore) ForLine added in v0.13.0

func (p *PrefixStore) ForLine(
	g discord.GuildID,
	me discord.User,
	mme *discord.Member,
	line string,
) (Prefix, bool)

ForLine finds the first suitable prefix that matches the given line.

func (*PrefixStore) Get added in v0.12.0

func (p *PrefixStore) Get(g discord.GuildID) (string, bool)

Get allows looking up a Prefix by GuildID.

func (*PrefixStore) Load added in v0.12.0

func (p *PrefixStore) Load() error

Load updates the PrefixStore with data from the Confy.

func (*PrefixStore) Set added in v0.12.0

func (p *PrefixStore) Set(g discord.GuildID, pfxv string)

Set allows storing a prefix for a given GuildID.

func (*PrefixStore) Store added in v0.12.0

func (p *PrefixStore) Store() error

Store updates the Confy with data from the PrefixStore.

type Reply

type Reply struct {
	api.SendMessageData

	Trigger *Trigger
}

Reply wraps a message to be sent to a given ChannelID using a given Session.

func (*Reply) Send

func (r *Reply) Send() error

Send is a shortcut for SendMsg that elides the resulting message.

func (*Reply) SendMsg

func (r *Reply) SendMsg() (*discord.Message, error)

SendMsg sends the Reply.

type Route

type Route struct {
	State *state.State
	Confy confy.Confy

	Prefix *PrefixStore
	Cmd    *CmdStore
}

Route handles storing and looking up Cmds.

func New added in v0.3.0

func New(s *state.State, c confy.Confy) (*Route, error)

New makes an empty Route with the given State.

func (*Route) Handle added in v0.3.0

func (r *Route) Handle(m *gateway.MessageCreateEvent)

Handle is a MessageCreate handler function for the Route.

func (*Route) Trigger added in v0.3.0

func (r *Route) Trigger(pfx Prefix, m discord.Message, line string) (*Trigger, error)

Trigger gets a Trigger by finding an appropriate Command for a given prefix, message, and line.

type Trigger added in v0.3.0

type Trigger struct {
	Route   *Route
	Message discord.Message
	Prefix  Prefix
	Command Cmd
	FlagSet *flag.FlagSet
	Args    []string
	Flags   interface{}
	Output  *strings.Builder
}

Trigger holds the context that triggered a Command.

func (*Trigger) Reply added in v0.3.0

func (t *Trigger) Reply() *Reply

Reply gets a Reply for the Trigger.

func (*Trigger) Usage added in v0.3.0

func (t *Trigger) Usage()

Usage is the help flag handler for the Trigger.

Jump to

Keyboard shortcuts

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