command

package
v0.0.0-...-a10a6d9 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageTypeCommand = message.MessageTypeCustom + 100
)

Message type for commands

Variables

View Source
var (
	ErrQueueFull       = errors.New("command queue is full")
	ErrInvalidCommand  = errors.New("invalid command format")
	ErrCommandNotFound = errors.New("command not found")
)

Functions

func CreateCommandMessage

func CreateCommandMessage(cmd *Command) (*message.Message, error)

CreateCommandMessage creates a message containing a command

Types

type Command

type Command struct {
	ID        string    `cbor:"id"`
	Name      string    `cbor:"name"`
	Argument  string    `cbor:"argument"`
	PlayerID  string    `cbor:"player_id"`
	Timestamp time.Time `cbor:"timestamp"`
	Raw       string    `cbor:"raw"`
}

Command represents a parsed command

func ParseCommandMessage

func ParseCommandMessage(msg *message.Message) (*Command, error)

ParseCommandMessage parses a command from a message

type CommandConfig

type CommandConfig struct {
	QueueSize int  // Maximum number of commands in queue per player
	Enabled   bool // Whether command processing is enabled
}

CommandConfig contains configuration for the command system

func DefaultCommandConfig

func DefaultCommandConfig() *CommandConfig

DefaultCommandConfig returns default configuration

type CommandHandler

type CommandHandler func(cmd *Command) error

CommandHandler is a function that handles a command

type CommandManager

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

CommandManager handles command parsing, queueing, and processing

func NewCommandManager

func NewCommandManager(config *CommandConfig, eventManager events.EventManager) *CommandManager

NewCommandManager creates a new command manager

func (*CommandManager) ClearQueue

func (cm *CommandManager) ClearQueue(playerID string)

ClearQueue clears all commands from a player's queue

func (*CommandManager) ExecuteCommand

func (cm *CommandManager) ExecuteCommand(cmd *Command) error

ExecuteCommand executes a command by calling its handler

func (*CommandManager) GetQueue

func (cm *CommandManager) GetQueue(playerID string) *CommandQueue

GetQueue returns the command queue for a player

func (*CommandManager) GetQueueSize

func (cm *CommandManager) GetQueueSize(playerID string) int

GetQueueSize returns the current size of a player's command queue

func (*CommandManager) GetRegisteredCommands

func (cm *CommandManager) GetRegisteredCommands() []string

GetRegisteredCommands returns a list of all registered command names

func (*CommandManager) IsEnabled

func (cm *CommandManager) IsEnabled() bool

IsEnabled returns true if command processing is enabled

func (*CommandManager) IsQueueFull

func (cm *CommandManager) IsQueueFull(playerID string) bool

IsQueueFull returns true if a player's command queue is full

func (*CommandManager) ParseCommand

func (cm *CommandManager) ParseCommand(input string, playerID string) (*Command, error)

ParseCommand parses a command string into a Command struct

func (*CommandManager) ProcessCommand

func (cm *CommandManager) ProcessCommand(input string, playerID string) error

ProcessCommand processes a command string for a player

func (*CommandManager) ProcessQueue

func (cm *CommandManager) ProcessQueue(playerID string) error

ProcessQueue processes the next command in a player's queue

func (*CommandManager) QueueCommand

func (cm *CommandManager) QueueCommand(cmd *Command) error

QueueCommand adds a command to the player's queue

func (*CommandManager) RegisterHandler

func (cm *CommandManager) RegisterHandler(commandName string, handler CommandHandler)

RegisterHandler registers a command handler

func (*CommandManager) RemovePlayer

func (cm *CommandManager) RemovePlayer(playerID string)

RemovePlayer removes a player's command queue

func (*CommandManager) SetEnabled

func (cm *CommandManager) SetEnabled(enabled bool)

SetEnabled enables or disables command processing

func (*CommandManager) UnregisterHandler

func (cm *CommandManager) UnregisterHandler(commandName string)

UnregisterHandler removes a command handler

type CommandQueue

type CommandQueue struct {
	PlayerID string
	Commands []*Command
	MaxSize  int
	// contains filtered or unexported fields
}

CommandQueue manages commands for a single player

func NewCommandQueue

func NewCommandQueue(playerID string, maxSize int) *CommandQueue

NewCommandQueue creates a new command queue for a player

func (*CommandQueue) Clear

func (q *CommandQueue) Clear()

Clear removes all commands from the queue

func (*CommandQueue) Dequeue

func (q *CommandQueue) Dequeue() *Command

Dequeue removes and returns the next command from the queue

func (*CommandQueue) Enqueue

func (q *CommandQueue) Enqueue(cmd *Command) error

Enqueue adds a command to the queue

func (*CommandQueue) IsFull

func (q *CommandQueue) IsFull() bool

IsFull returns true if the queue is at capacity

func (*CommandQueue) Size

func (q *CommandQueue) Size() int

Size returns the current number of commands in the queue

Jump to

Keyboard shortcuts

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