Documentation
¶
Overview ¶
Package bot runs the companion Telegram bot. It talks only to the owner, renders plugin settings as button panels and hosts plugin pages.
Index ¶
- func Disabled() bool
- func Login(ctx context.Context, client *telegram.Client, token string) (*tg.User, error)
- func NewClient(opt Options, h telegram.UpdateHandler) *telegram.Client
- func TokenBotID(token string) int64
- type Catalog
- type Options
- type PluginInfo
- type RepoEntry
- type Service
- func (s *Service) Enabled() bool
- func (s *Service) For(name string) plugin.Bot
- func (s *Service) KnowsOwner() bool
- func (s *Service) Ready() bool
- func (s *Service) RemovePlugin(name string)
- func (s *Service) Run(ctx context.Context) error
- func (s *Service) SetCatalog(c Catalog)
- func (s *Service) SetOwner(id int64)
- func (s *Service) Settings(spec *plugin.SettingsSpec) (plugin.Settings, error)
- func (s *Service) Username() string
- func (s *Service) WaitReady(ctx context.Context) bool
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Disabled ¶
func Disabled() bool
Disabled reports whether the env asks to skip the bot (tests, CI).
func Login ¶
Login authorizes client as the bot behind token. A session that belongs to another bot is logged out first.
func NewClient ¶
func NewClient(opt Options, h telegram.UpdateHandler) *telegram.Client
NewClient builds the gotd client for the bot account.
func TokenBotID ¶
TokenBotID is the numeric bot id at the start of a token, 0 if malformed.
Types ¶
type Catalog ¶
type Catalog interface {
Builtins() []PluginInfo
// Externals lists loaded external plugins and files that failed.
Externals() []PluginInfo
Repo(ctx context.Context, fresh bool) ([]RepoEntry, error)
Install(ctx context.Context, name string) error
Remove(ctx context.Context, name string) error
// Reload reloads a loaded plugin or retries a failed one.
Reload(ctx context.Context, name string) error
// Explain turns an action error into a reason (zh, en).
Explain(err error) (string, string)
}
Catalog is what the bot needs to list and manage plugins.
type Options ¶
type Options struct {
APIID int
APIHash string
Token string
SessionFile string
PeersFile string
Device telegram.DeviceConfig
// Version is shown in the menu header.
Version string
}
Options configures the bot.
type PluginInfo ¶
type PluginInfo struct {
Name string
Desc string
DescEN string
Version string
Author string
Commands []string // with prefix, aliases included
// Failed is the load error of an external plugin file that did not
// load; such a plugin has no commands, settings or page.
Failed string
}
PluginInfo describes one plugin for the panels.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the companion bot.
func New ¶
New builds the service. Without a token Run returns at once and the bot stays unavailable, but settings still work for plugins.
func (*Service) KnowsOwner ¶
KnowsOwner reports whether the bot can already message the owner. Bots cannot open a chat; the owner has to message it once.
func (*Service) RemovePlugin ¶
RemovePlugin drops a plugin's page and settings (on unload).
func (*Service) Run ¶
Run connects the bot and blocks until ctx ends. Connection problems are logged, never fatal: the userbot keeps working without its bot.
func (*Service) SetCatalog ¶
SetCatalog wires plugin listing and management.