command

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

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

Parser listens for message events and dispatches commands. As a userbot, the Parser only handles outgoing messages (IsOut == true).

func NewParser

func NewParser(registry *Registry, bus *eventbus.Bus) *Parser

func (*Parser) Start

func (p *Parser) Start()

Start registers the message listener (userbot: outgoing only).

type Registry

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

Registry manages command registration, lookup, and middleware execution. Supports multi-prefix command parsing.

func NewRegistry

func NewRegistry(prefixes []string, emitter interfaces.Emitter, api *tg.Client, resolver interfaces.PeerResolver, ownerID int64, i18nMgr *i18n.Manager) *Registry

func (*Registry) AddPrefix

func (r *Registry) AddPrefix(prefix string)

AddPrefix adds a prefix without removing existing ones.

func (*Registry) AddUserAlias

func (r *Registry) AddUserAlias(name, cmd string)

AddUserAlias registers a runtime alias. The alias value is a full command line (command plus optional fixed arguments) and is expanded exactly once during parsing; aliases do not nest.

func (*Registry) ExecuteCommand

func (r *Registry) ExecuteCommand(ctx context.Context, msg *interfaces.MessageEvent, name string, args []string) error

func (*Registry) Get

func (r *Registry) Get(name string) (*interfaces.Command, bool)

func (*Registry) GetAll

func (r *Registry) GetAll() map[string]*interfaces.Command

func (*Registry) GetByPlugin

func (r *Registry) GetByPlugin(plugin string) map[string]*interfaces.Command

func (*Registry) GetPrefix

func (r *Registry) GetPrefix() string

func (*Registry) GetPrefixes

func (r *Registry) GetPrefixes() []string

func (*Registry) IsCommand

func (r *Registry) IsCommand(text string) bool

IsCommand checks if text starts with any registered prefix.

func (*Registry) ParseCommand

func (r *Registry) ParseCommand(text string) (name string, args []string, ok bool)

ParseCommand parses a command from text, trying all registered prefixes. Returns the first match across all prefixes.

func (*Registry) Register

func (r *Registry) Register(cmd *interfaces.Command) error

func (*Registry) RemovePrefix

func (r *Registry) RemovePrefix(prefix string) bool

RemovePrefix removes a prefix (keeps at least one).

func (*Registry) RemoveUserAlias

func (r *Registry) RemoveUserAlias(name string)

RemoveUserAlias deletes a runtime alias.

func (*Registry) SetMediaSender

func (r *Registry) SetMediaSender(m interfaces.MediaSender)

SetMediaSender wires the media manager so command handlers can send files.

func (*Registry) SetOwnerID

func (r *Registry) SetOwnerID(id int64)

SetOwnerID updates the owner ID after initial resolution.

func (*Registry) SetPrefix

func (r *Registry) SetPrefix(prefix string)

func (*Registry) SetPrefixes

func (r *Registry) SetPrefixes(prefixes []string)

SetPrefixes replaces all prefixes.

func (*Registry) SetSudoChecker

func (r *Registry) SetSudoChecker(f func(int64) bool)

SetSudoChecker wires a permission checker used to let delegated users run OwnerOnly commands.

func (*Registry) Unregister

func (r *Registry) Unregister(name string)

func (*Registry) UnregisterPlugin

func (r *Registry) UnregisterPlugin(plugin string)

func (*Registry) Use

func (r *Registry) Use(mw interfaces.Middleware)

func (*Registry) UserAliases

func (r *Registry) UserAliases() map[string]string

UserAliases returns a copy of the runtime alias map.

Jump to

Keyboard shortcuts

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