Documentation ¶
Overview ¶
a Telegram Bot Service framework based on yanzay/tbot
Index ¶
- type Argument
- type CallbackHandler
- type Command
- type Field
- type KVDatabase
- type MemoryDB
- type Parameter
- type Server
- func (r *Server) EditCallbackBtn(cq *tbot.CallbackQuery, btnMatrix [][]tbot.InlineKeyboardButton) (*tbot.Message, error)
- func (r *Server) EditCallbackMsg(cq *tbot.CallbackQuery, format string, v ...interface{}) (*tbot.Message, error)
- func (r *Server) EditCallbackMsgWithBtn(cq *tbot.CallbackQuery, btnMatrix [][]tbot.InlineKeyboardButton, format string, ...) (*tbot.Message, error)
- func (r *Server) HandleCallback(cq *tbot.CallbackQuery)
- func (r *Server) HandleMessage(m *tbot.Message)
- func (r *Server) Register(starter string, description string, ...)
- func (r *Server) RegisterInlineButton(data string, handler CallbackHandler)
- func (r *Server) Sendf(chatid string, format string, v ...interface{}) (*tbot.Message, error)
- func (r *Server) SendfWithBtn(chatid string, btnMatrix [][]tbot.InlineKeyboardButton, format string, ...) (*tbot.Message, error)
- func (r *Server) Start() error
- func (r *Server) StartCommand(starter string, from *tbot.User, chat tbot.Chat) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallbackHandler ¶
type CallbackHandler = func(*tbot.CallbackQuery) error
type Command ¶
type Command struct { // 继承 BotCommand tbot.BotCommand // Init 函数用于触发 starter 后的初始化和鉴权 Init func(from *tbot.User, chat tbot.Chat) bool // 命令参数 Param []Parameter Callback func(argv []Argument, from *tbot.User, chatid string) Handler func(*tbot.Message) }
描述了一个命令
type KVDatabase ¶
type KVDatabase interface { // get value based on key Get(key string) interface{} Set(key string, value interface{}) error // return a subdatabase with prefix. e. g. subdb.get(key) is equal to // db.get(prefix + key), ant note that subdb & db share the same storage Sub(prefix string) KVDatabase // traverse all data ForEach(handler func(key string, value interface{})) }
simple abstraction for key-value database
type MemoryDB ¶
MemoryDB implememts KVDatabase, which is a simple storage based on runtime memory
func NewMemoryDB ¶
func NewMemoryDB() MemoryDB
func (*MemoryDB) Sub ¶
func (r *MemoryDB) Sub(prefix string) KVDatabase
type Server ¶
type Server struct { Bot *tbot.Server Client *tbot.Client // contains filtered or unexported fields }
tg bot server
func NewServerFromTbot ¶
func NewServerFromTbot(bot *tbot.Server) Server
func (*Server) EditCallbackBtn ¶
func (*Server) EditCallbackMsg ¶
func (*Server) EditCallbackMsgWithBtn ¶
func (*Server) HandleCallback ¶
func (r *Server) HandleCallback(cq *tbot.CallbackQuery)
func (*Server) HandleMessage ¶
func (r *Server) HandleMessage(m *tbot.Message)
func (*Server) Register ¶
func (r *Server) Register(starter string, description string, init func(from *tbot.User, chat tbot.Chat) bool, params []Parameter, f func(argv []Argument, from *tbot.User, chatid string))
starter 为命令的触发字符串。若开头为 / 则会作为显示命令,否则为隐式命令。 description 可选,用于描述命令。开头为 / 的命令会以 start - description 的形式打印到日志中,方便在 Bot Father 那 setcommand。init 指在触发 start 后,获取参数前的检查(例如权限),返回值为 true 则继续获取参数,否则终止。params 描述了参数列表,包含每个参数的描述,校验器,f 即回调函数
func (*Server) RegisterInlineButton ¶
func (r *Server) RegisterInlineButton(data string, handler CallbackHandler)
data: 按扭的 CallbackData
func (*Server) SendfWithBtn ¶
func (r *Server) SendfWithBtn(chatid string, btnMatrix [][]tbot.InlineKeyboardButton, format string, v ...interface{}) (*tbot.Message, error)
Send message with inline button
func (*Server) StartCommand ¶
Click to show internal directories.
Click to hide internal directories.