commands

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Multi-platform Commands

Этот пример использует модульный набор команд из commands/*.

  • Каждый модуль — отдельный файл и отдельная структура, реализующая commands.Module.
  • Набор активных модулей выбирается в examples/multi-platform/main.go.
  • Включен FSM-модуль регистрации (register_fsm.go).

Встроенные модули

  • start_command.go — команда /start.
  • botcmd_module.go — botcmd-style middleware (app.Use) с декларативными командами и алиасами:
    • /help или /h
    • /menu 3 или /m 3
  • menu_callback.go — обработчик callback menu.*.
  • echo_message.go — echo для сообщений.
    • также показывает mentions и attachments из текста.
  • register_fsm.go — диалог регистрации:
    • /register → шаг email
    • шаг code
    • /cancel на любом шаге
  • feedback_fsm.go — диалог отзыва:
    • /feedback → шаг текста
    • шаг подтверждения (да/нет)
    • /cancel на любом шаге

Как добавить свою команду

  1. Создай файл в examples/multi-platform/commands/, например help_command.go.
  2. Реализуй Name() string и Register(app *app.App).
  3. Добавь модуль в commands.DefaultModules(...) или в commandSet в main.go.

Быстрое отключение команды

Просто убери модуль из commandSet — код файла можно оставить.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(app *astraengine.App, modules ...Module)

Types

type AttachTestCommand added in v1.0.2

type AttachTestCommand struct{}

func NewAttachTestCommand added in v1.0.2

func NewAttachTestCommand() *AttachTestCommand

func (*AttachTestCommand) Name added in v1.0.2

func (c *AttachTestCommand) Name() string

func (*AttachTestCommand) Register added in v1.0.2

func (c *AttachTestCommand) Register(app *astraengine.App)

type BotcmdModule

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

func NewBotcmdModule

func NewBotcmdModule() *BotcmdModule

func (*BotcmdModule) Name

func (m *BotcmdModule) Name() string

func (*BotcmdModule) Register

func (m *BotcmdModule) Register(app *astraengine.App)

type CallbackModule

type CallbackModule interface {
	Pattern() string
	HandleCallback(ctx CommandContext) error
}

CallbackModule is a convenience interface for callback routes.

type CommandContext

type CommandContext interface {
	SendText(text string) error
}

type CommandModule

type CommandModule interface {
	Command() string
	HandleCommand(ctx CommandContext) error
}

CommandModule is a convenience interface for slash-like commands.

type EchoMessage

type EchoMessage struct{}

func NewEchoMessage

func NewEchoMessage() *EchoMessage

func (*EchoMessage) Name

func (c *EchoMessage) Name() string

func (*EchoMessage) Register

func (c *EchoMessage) Register(app *astraengine.App)

type FeedbackFSM

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

func NewFeedbackFSM

func NewFeedbackFSM(fsm *state.FSM) *FeedbackFSM

func (*FeedbackFSM) Name

func (m *FeedbackFSM) Name() string

func (*FeedbackFSM) Register

func (m *FeedbackFSM) Register(app *astraengine.App)
type MenuCallback struct{}

func NewMenuCallback

func NewMenuCallback() *MenuCallback
func (c *MenuCallback) Name() string
func (c *MenuCallback) Register(app *astraengine.App)

type MessageModule

type MessageModule interface {
	HandleMessage(ctx CommandContext) error
}

MessageModule is a convenience interface for message handlers.

type Module

type Module interface {
	Name() string
	Register(app *astraengine.App)
}

Module is a pluggable route unit. Users can implement it in separate files and include/exclude modules in main.go depending on project needs.

func DefaultModules

func DefaultModules(fsm *state.FSM) []Module

DefaultModules returns a user-editable default set.

type RegisterFSM

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

func NewRegisterFSM

func NewRegisterFSM(fsm *state.FSM) *RegisterFSM

func (*RegisterFSM) Name

func (m *RegisterFSM) Name() string

func (*RegisterFSM) Register

func (m *RegisterFSM) Register(app *astraengine.App)

type StartCommand

type StartCommand struct{}

func NewStartCommand

func NewStartCommand() *StartCommand

func (*StartCommand) Name

func (c *StartCommand) Name() string

func (*StartCommand) Register

func (c *StartCommand) Register(app *astraengine.App)

Jump to

Keyboard shortcuts

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