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.From = update.CallbackQuery.From
|
||||||
ctx.Msg = update.CallbackQuery.Message
|
ctx.Msg = update.CallbackQuery.Message
|
||||||
ctx.CallbackMsgId = update.CallbackQuery.Message.MessageID
|
ctx.CallbackMsgId = update.CallbackQuery.Message.MessageID
|
||||||
|
ctx.CallbackQueryId = update.CallbackQuery.ID
|
||||||
ctx.Args = data.Args
|
ctx.Args = data.Args
|
||||||
|
|
||||||
for _, plugin := range b.plugins {
|
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
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ type MsgContext struct {
|
|||||||
Update *Update
|
Update *Update
|
||||||
From *User
|
From *User
|
||||||
CallbackMsgId int
|
CallbackMsgId int
|
||||||
|
CallbackQueryId string
|
||||||
FromID int
|
FromID int
|
||||||
Prefix string
|
Prefix string
|
||||||
Text string
|
Text string
|
||||||
@@ -151,14 +152,41 @@ func (ctx *MsgContext) CallbackDelete() {
|
|||||||
ctx.delete(ctx.CallbackMsgId)
|
ctx.delete(ctx.CallbackMsgId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *MsgContext) Error(err error) {
|
func (ctx *MsgContext) answerCallbackQuery(url, text string, showAlert bool) {
|
||||||
_, sendErr := ctx.Bot.SendMessage(&SendMessageP{
|
if len(ctx.CallbackQueryId) == 0 {
|
||||||
ChatID: ctx.Msg.Chat.ID,
|
return
|
||||||
Text: fmt.Sprintf(ctx.Bot.errorTemplate, EscapeMarkdown(err.Error())),
|
}
|
||||||
|
_, err := ctx.Bot.AnswerCallbackQuery(&AnswerCallbackQueryP{
|
||||||
|
CallbackQueryID: ctx.CallbackQueryId,
|
||||||
|
Text: text, ShowAlert: showAlert, URL: url,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
ctx.Bot.logger.Errorln(err)
|
ctx.Bot.logger.Errorln(err)
|
||||||
|
|
||||||
if sendErr != nil {
|
|
||||||
ctx.Bot.logger.Errorln(sendErr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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
|
package laniakea
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VersionString = "0.3.2"
|
VersionString = "0.3.6"
|
||||||
VersionMajor = 0
|
VersionMajor = 0
|
||||||
VersionMinor = 3
|
VersionMinor = 3
|
||||||
VersionPatch = 2
|
VersionPatch = 6
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user