command

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotHost added in v0.1.1

type BotHost interface {
	Settings(spec *plugin.SettingsSpec) (plugin.Settings, error)
	For(plugin string) plugin.Bot
	RemovePlugin(plugin string)
}

BotHost is what the registry needs from the companion bot service.

type Parser

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

Parser listens for message events and dispatches commands. It handles the owner's outgoing messages plus, when sudo is enabled, messages from delegated users. Other people's traffic is ignored.

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) CanUseCommands added in v0.1.1

func (r *Registry) CanUseCommands(userID int64) bool

CanUseCommands reports whether a user may trigger commands at all: the owner (outgoing messages) or a sudo-enabled delegated user.

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) Host added in v0.1.1

func (r *Registry) Host() plugin.Host

Host returns the plugin.Host view of the registry: the same services a CommandContext carries, usable outside command handlers.

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) SetBot added in v0.1.1

func (r *Registry) SetBot(b BotHost)

SetBot wires the companion bot so plugins get settings and bot access.

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) SetSelfID added in v0.1.1

func (r *Registry) SetSelfID(id int64)

SetSelfID records the logged-in account id exposed as ctx.SelfID.

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