Documentation ¶
Index ¶
- Constants
- Variables
- func EscapeMarkdownV2CodeBlock(s string) string
- func EscapeMarkdownV2Plaintext(s string) string
- func HandleStart(c tele.Context) error
- type Command
- type CommandOutputResponseBuilder
- type Config
- type Handler
- func (h *Handler) HandleCancel(c tele.Context) error
- func (h *Handler) HandleExec(c tele.Context) error
- func (h *Handler) HandleList(c tele.Context) error
- func (h *Handler) ReplaceUserCommandsByID(m map[int64][]Command)
- func (h *Handler) SetCommand(next tele.HandlerFunc) tele.HandlerFunc
- func (h *Handler) SetContext(ctx context.Context)
- func (h *Handler) SetUserCommands(next tele.HandlerFunc) tele.HandlerFunc
- func (h *Handler) Wait()
- type Runner
- type User
Constants ¶
const ( // DefaultExecTimeout is the default command execution timeout. DefaultExecTimeout = 15 * time.Second // DefaultExitTimeout is the default command exit timeout. DefaultExitTimeout = 5 * time.Second )
Variables ¶
var Commands = []tele.Command{
{
Text: "start",
Description: "Get started with the bot",
},
{
Text: "list",
Description: "List commands authorized for you to request execution",
},
{
Text: "exec",
Description: "Execute an authorized command at the specified index",
},
{
Text: "cancel",
Description: "Cancel a running command at the specified index",
},
}
Functions ¶
func EscapeMarkdownV2CodeBlock ¶
EscapeMarkdownV2CodeBlock escapes the given string for use in a MarkdownV2 code block.
func EscapeMarkdownV2Plaintext ¶
EscapeMarkdownV2Plaintext escapes the given string for use in a MarkdownV2 plaintext.
Types ¶
type Command ¶ added in v1.1.0
type Command struct { // Name is the command name. Name string `json:"name"` // Args is the list of command arguments. Args []string `json:"args"` // ExecTimeoutSec is the command execution timeout in seconds. // When command execution exceeds this timeout, an interrupt signal is sent to the process. // If the process does not exit within [ExitTimeoutSec], it is terminated. // // If zero, [DefaultExecTimeout] is used. ExecTimeoutSec int `json:"execTimeoutSec"` // ExitTimeoutSec is the command exit timeout in seconds. // When command execution exceeds [ExecTimeoutSec], an interrupt signal is sent to the process. // If the process does not exit within this timeout, it is terminated. // // If zero, [DefaultExitTimeout] is used. ExitTimeoutSec int `json:"exitTimeoutSec"` // contains filtered or unexported fields }
Command is an authorized command.
type CommandOutputResponseBuilder ¶
type CommandOutputResponseBuilder struct {
// contains filtered or unexported fields
}
CommandOutputResponseBuilder is a reusable builder for command output responses.
type Config ¶
type Config struct { // Token is the bot token. Token string `json:"token"` // URL is the custom bot API URL. // Leave empty to use the official bot API. URL string `json:"url"` // Users is the list of authorized users. Users []User `json:"users"` }
Config is the configuration for the bot.
func (Config) UserCommandsByID ¶
UserCommandsByID returns a map of user ID to list of commands.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles bot commands.
func (*Handler) HandleCancel ¶ added in v1.1.0
HandleCancel handles the `/cancel` command.
func (*Handler) HandleExec ¶
HandleExec handles the `/exec` command.
func (*Handler) HandleList ¶
HandleList handles the `/list` command.
func (*Handler) ReplaceUserCommandsByID ¶
ReplaceUserCommandsByID replaces the user commands map.
func (*Handler) SetCommand ¶ added in v1.1.0
func (h *Handler) SetCommand(next tele.HandlerFunc) tele.HandlerFunc
SetCommand is a middleware that parses the specified command index and adds the command and its index to the context. It short-circuits the command handler if the index is invalid.
func (*Handler) SetContext ¶ added in v1.1.0
SetContext sets the context.
func (*Handler) SetUserCommands ¶ added in v1.1.0
func (h *Handler) SetUserCommands(next tele.HandlerFunc) tele.HandlerFunc
SetUserCommands is a middleware that adds the user's list of authorized commands to the context. It short-circuits the command handler if the user is not authorized to execute any commands.