command

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package command holds all of the tools for GGGB's command handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Admin

type Admin struct {
	Level int
	Mask  string
}

Admin represents a mask with a level of admin access

func (*Admin) MatchesMask

func (a *Admin) MatchesMask(mask string) bool

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

func (d *Data) CheckPerms(requiredLevel int) bool

CheckPerms verifies that the admin level of the source user is at or above the requiredLevel

func (*Data) ReturnMessage

func (d *Data) ReturnMessage(msg string)

ReturnMessage either sends a notice to the caller of a command

func (*Data) ReturnNotice

func (d *Data) ReturnNotice(msg string)

ReturnNotice either sends a notice to the caller of a command

func (*Data) SendMessage

func (d *Data) SendMessage(target, msg string)

SendMessage sends an IRC privmsg to the given target

func (*Data) SendNotice

func (d *Data) SendNotice(target, msg string)

SendNotice sends an IRC notice to the given target with the given message

func (*Data) SendSourceMessage

func (d *Data) SendSourceMessage(msg string)

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

func (d *Data) SendSourceNotice(msg string)

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

func (d *Data) SendTargetMessage(msg string)

SendTargetMessage is a shortcut to SendMessage that sets the target for the privmsg to the target of the Data object

func (*Data) SendTargetNotice

func (d *Data) SendTargetNotice(msg string)

SendTargetNotice is a shortcut to SendNotice that sets the target of the notice to the target of the Data object

func (*Data) String

func (d *Data) String() string

String implements the stringer interface

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

type Manager struct {
	Logger *log.Logger
	// contains filtered or unexported fields
}

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

func NewManager(logger *log.Logger, pFunc prefixFunc, prefixes ...string) *Manager

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

func (m *Manager) AddCommand(name string, requiresAdmin int, callback Callback, help string) error

AddCommand adds the callback as a simple (SingleCommand) to the Manager. It is safe for concurrent use. It returns various errors

func (*Manager) AddPrefix

func (m *Manager) AddPrefix(name string)

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

func (m *Manager) ParseLine(line string, fromTerminal bool, source, target string, util DataUtil)

ParseLine checks the given string for a valid command. If it finds one, it fires that command.

func (*Manager) RemoveCommand

func (m *Manager) RemoveCommand(name string) error

RemoveCommand removes the command referenced by the given string. If the command does not exist, RemoveCommand returns an error.

func (*Manager) RemovePrefix

func (m *Manager) RemovePrefix(name string)

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

func (m *Manager) RemoveSubCommand(rootName, name string) error

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

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

SetPrefixes sets the prefixes the Manager will respond to to the given slice, all other prefixes are removed

func (*Manager) String

func (m *Manager) String() string

String implements the stringer interface

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

Jump to

Keyboard shortcuts

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