Documentation ¶
Overview ¶
Package command holds all of the tools for GGGB's command handling.
Index ¶
- type Admin
- type Callback
- type Command
- type Data
- func (d *Data) CheckPerms(requiredLevel int) bool
- func (d *Data) ReturnMessage(msg string)
- func (d *Data) ReturnNotice(msg string)
- func (d *Data) SendMessage(target, msg string)
- func (d *Data) SendNotice(target, msg string)
- func (d *Data) SendSourceMessage(msg string)
- func (d *Data) SendSourceNotice(msg string)
- func (d *Data) SendTargetMessage(msg string)
- func (d *Data) SendTargetNotice(msg string)
- func (d *Data) String() string
- type DataUtil
- type Manager
- func (m *Manager) AddCommand(name string, requiresAdmin int, callback Callback, help string) error
- func (m *Manager) AddPrefix(name string)
- func (m *Manager) AddSubCommand(rootName, name string, requiresAdmin int, callback Callback, help string) error
- func (m *Manager) ParseLine(line string, fromTerminal bool, source, target string, util DataUtil)
- func (m *Manager) RemoveCommand(name string) error
- func (m *Manager) RemovePrefix(name string)
- func (m *Manager) RemoveSubCommand(rootName, name string) error
- func (m *Manager) SetPrefixes(prefixes []string)
- func (m *Manager) String() string
- type SingleCommand
- type SubCommandList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Admin ¶
Admin represents a mask with a level of admin access
func (*Admin) MatchesMask ¶
MatchesMask returns whether or not the given mask matches the mask on the Admin object
type Callback ¶
type Callback func(data *Data)
Callback is a function that can be attached to a command
type Command ¶
type Command interface { AdminRequired() int Fire(data *Data) Help() string Name() string fmt.Stringer }
Command represents a fireable command
type Data ¶
type Data struct { FromTerminal bool Args []string OriginalArgs string Source string Target string Manager *Manager // contains filtered or unexported fields }
Data represents all the data available for a command call
func (*Data) CheckPerms ¶
CheckPerms verifies that the admin level of the source user is at or above the requiredLevel
func (*Data) ReturnMessage ¶
ReturnMessage either sends a notice to the caller of a command
func (*Data) ReturnNotice ¶
ReturnNotice either sends a notice to the caller of a command
func (*Data) SendMessage ¶
SendMessage sends an IRC privmsg to the given target
func (*Data) SendNotice ¶
SendNotice sends an IRC notice to the given target with the given message
func (*Data) SendSourceMessage ¶
SendSourceMessage is a shortcut to SendMessage that sets the target for the privmsg to the nick of the source on the data object
func (*Data) SendSourceNotice ¶
SendSourceNotice is a shortcut to SendNotice that sets the target of the notice to the nick of the source of the data object
func (*Data) SendTargetMessage ¶
SendTargetMessage is a shortcut to SendMessage that sets the target for the privmsg to the target of the Data object
func (*Data) SendTargetNotice ¶
SendTargetNotice is a shortcut to SendNotice that sets the target of the notice to the target of the Data object
type DataUtil ¶
type DataUtil interface { interfaces.AdminLeveller interfaces.Messager }
DataUtil provides methods for Data to use when returning messages or checking admin levels
type Manager ¶
Manager is a frontend that manages commands and the firing thereof. It is intended to be a completely self contained system for managing commands on arbitrary lines
func NewManager ¶
NewManager creates a Manager with the provided logger and messager. The prefixes vararg sets the prefixes for the commands. Note that the prefix is matched EXACTLY. Meaning that a trailing space is required for any "normal" prefix
func (*Manager) AddCommand ¶
AddCommand adds the callback as a simple (SingleCommand) to the Manager. It is safe for concurrent use. It returns various errors
func (*Manager) AddPrefix ¶
AddPrefix adds a prefix to the command manager. It is not safe for concurrent use
func (*Manager) AddSubCommand ¶
func (m *Manager) AddSubCommand(rootName, name string, requiresAdmin int, callback Callback, help string) error
AddSubCommand adds the given callback as a subcommand to the given root name. If the root name does not exist on the Manager, it is automatically added. Otherwise, if it DOES exist but is of the wrong type, AddSubCommand returns an error
func (*Manager) ParseLine ¶
ParseLine checks the given string for a valid command. If it finds one, it fires that command.
func (*Manager) RemoveCommand ¶
RemoveCommand removes the command referenced by the given string. If the command does not exist, RemoveCommand returns an error.
func (*Manager) RemovePrefix ¶
RemovePrefix removes a prefix from the Manager, it is not safe for concurrent use. If the prefix does not exist, the method is a noop
func (*Manager) RemoveSubCommand ¶
RemoveSubCommand removes the command referenced by name on rootName, if rootName is not a command with sub commands, or name does not exist on rootName, RemoveSubCommand errors
func (*Manager) SetPrefixes ¶
SetPrefixes sets the prefixes the Manager will respond to to the given slice, all other prefixes are removed
type SingleCommand ¶
type SingleCommand struct {
// contains filtered or unexported fields
}
SingleCommand represents a Command with no special subcommand magic. It implements the Command interface
func (*SingleCommand) AdminRequired ¶
func (c *SingleCommand) AdminRequired() int
AdminRequired is a getter for the admin required on the command
func (*SingleCommand) Fire ¶
func (c *SingleCommand) Fire(data *Data)
Fire executes the callback on the command if the caller has the permissions required
func (*SingleCommand) Help ¶
func (c *SingleCommand) Help() string
Help is a getter for the help string for the command
func (*SingleCommand) Name ¶
func (c *SingleCommand) Name() string
Name is a getter for the name of the command
func (*SingleCommand) String ¶
func (c *SingleCommand) String() string
type SubCommandList ¶
type SubCommandList struct { SingleCommand sync.RWMutex // contains filtered or unexported fields }
SubCommandList is an implementation of Command that holds a list of subCommands that it can fire
func (*SubCommandList) Fire ¶
func (s *SubCommandList) Fire(data *Data)
Fire executes the callback on the command if the caller has the permissions required
func (*SubCommandList) Help ¶
func (s *SubCommandList) Help() string
Help returns the help message for the command. For SubCommandLists, this returns the available subcommands
func (*SubCommandList) String ¶
func (s *SubCommandList) String() string