v0.3.6; answerCallbackQuery
This commit is contained in:
@@ -57,6 +57,7 @@ func (b *Bot) handleCallback(update *Update, ctx *MsgContext) {
|
||||
ctx.From = update.CallbackQuery.From
|
||||
ctx.Msg = update.CallbackQuery.Message
|
||||
ctx.CallbackMsgId = update.CallbackQuery.Message.MessageID
|
||||
ctx.CallbackQueryId = update.CallbackQuery.ID
|
||||
ctx.Args = data.Args
|
||||
|
||||
for _, plugin := range b.plugins {
|
||||
|
||||
17
methods.go
17
methods.go
@@ -138,3 +138,20 @@ func (b *Bot) DeleteMessage(params *DeleteMessageP) (bool, error) {
|
||||
}
|
||||
return *ok, err
|
||||
}
|
||||
|
||||
type AnswerCallbackQueryP struct {
|
||||
CallbackQueryID string `json:"callback_query_id"`
|
||||
Text string `json:"text,omitempty"`
|
||||
ShowAlert bool `json:"show_alert,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
CacheTime int `json:"cache_time,omitempty"`
|
||||
}
|
||||
|
||||
func (b *Bot) AnswerCallbackQuery(params *AnswerCallbackQueryP) (bool, error) {
|
||||
req := NewRequest[bool]("answerCallbackQuery", params)
|
||||
ok, err := req.Do(b)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return *ok, err
|
||||
}
|
||||
|
||||
@@ -3,15 +3,16 @@ package laniakea
|
||||
import "fmt"
|
||||
|
||||
type MsgContext struct {
|
||||
Bot *Bot
|
||||
Msg *Message
|
||||
Update *Update
|
||||
From *User
|
||||
CallbackMsgId int
|
||||
FromID int
|
||||
Prefix string
|
||||
Text string
|
||||
Args []string
|
||||
Bot *Bot
|
||||
Msg *Message
|
||||
Update *Update
|
||||
From *User
|
||||
CallbackMsgId int
|
||||
CallbackQueryId string
|
||||
FromID int
|
||||
Prefix string
|
||||
Text string
|
||||
Args []string
|
||||
}
|
||||
|
||||
type AnswerMessage struct {
|
||||
@@ -151,14 +152,41 @@ func (ctx *MsgContext) CallbackDelete() {
|
||||
ctx.delete(ctx.CallbackMsgId)
|
||||
}
|
||||
|
||||
func (ctx *MsgContext) Error(err error) {
|
||||
_, sendErr := ctx.Bot.SendMessage(&SendMessageP{
|
||||
ChatID: ctx.Msg.Chat.ID,
|
||||
Text: fmt.Sprintf(ctx.Bot.errorTemplate, EscapeMarkdown(err.Error())),
|
||||
func (ctx *MsgContext) answerCallbackQuery(url, text string, showAlert bool) {
|
||||
if len(ctx.CallbackQueryId) == 0 {
|
||||
return
|
||||
}
|
||||
_, err := ctx.Bot.AnswerCallbackQuery(&AnswerCallbackQueryP{
|
||||
CallbackQueryID: ctx.CallbackQueryId,
|
||||
Text: text, ShowAlert: showAlert, URL: url,
|
||||
})
|
||||
ctx.Bot.logger.Errorln(err)
|
||||
|
||||
if sendErr != nil {
|
||||
ctx.Bot.logger.Errorln(sendErr)
|
||||
if err != nil {
|
||||
ctx.Bot.logger.Errorln(err)
|
||||
}
|
||||
}
|
||||
func (ctx *MsgContext) AnswerCbQuery() {
|
||||
ctx.answerCallbackQuery("", "", false)
|
||||
}
|
||||
func (ctx *MsgContext) AnswerCbQueryText(text string) {
|
||||
ctx.answerCallbackQuery("", text, false)
|
||||
}
|
||||
func (ctx *MsgContext) AnswerCbQueryAlert(text string) {
|
||||
ctx.answerCallbackQuery("", text, true)
|
||||
}
|
||||
func (ctx *MsgContext) AnswerCbQueryUrl(u string) {
|
||||
ctx.answerCallbackQuery(u, "", false)
|
||||
}
|
||||
|
||||
func (ctx *MsgContext) error(err error) {
|
||||
text := fmt.Sprintf(ctx.Bot.errorTemplate, EscapeMarkdown(err.Error()))
|
||||
|
||||
if ctx.CallbackQueryId != "" {
|
||||
ctx.answerCallbackQuery("", text, false)
|
||||
} else {
|
||||
ctx.answer(text, nil)
|
||||
}
|
||||
ctx.Bot.logger.Errorln(err)
|
||||
}
|
||||
func (ctx *MsgContext) Error(err error) {
|
||||
ctx.error(err)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package laniakea
|
||||
|
||||
const (
|
||||
VersionString = "0.3.2"
|
||||
VersionString = "0.3.6"
|
||||
VersionMajor = 0
|
||||
VersionMinor = 3
|
||||
VersionPatch = 2
|
||||
VersionPatch = 6
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user