Inline commands support (needed for pins handling)
This commit is contained in:
parent
fed4a52075
commit
a6811f61fc
@ -56,13 +56,18 @@ func main() {
|
||||
updates, _ := c.Bot.GetUpdatesChan(u)
|
||||
|
||||
for update := range updates {
|
||||
if update.Message == nil || update.Message.From == nil {
|
||||
continue
|
||||
} else if update.Message.Date < (int(time.Now().Unix()) - 1) {
|
||||
// Ignore old messages
|
||||
continue
|
||||
}
|
||||
|
||||
if update.Message != nil {
|
||||
if update.Message.From != nil {
|
||||
if update.Message.Date > (int(time.Now().Unix()) - 5) {
|
||||
c.Router.RouteRequest(&update)
|
||||
}
|
||||
}
|
||||
} else if update.InlineQuery != nil {
|
||||
c.Router.RouteInline(&update)
|
||||
} else if update.ChosenInlineResult != nil {
|
||||
c.Log.Debug(update.ChosenInlineResult.ResultID)
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func CreateLocationsUp(tx *sql.Tx) error {
|
||||
if err4 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err5 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏙:', 'Город', NOW());")
|
||||
_, err5 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏙', 'Город', NOW());")
|
||||
if err5 != nil {
|
||||
return err2
|
||||
}
|
||||
|
48
lib/router/inline.go
Normal file
48
lib/router/inline.go
Normal file
@ -0,0 +1,48 @@
|
||||
// i2_bot – Instinct PokememBro Bot
|
||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// RouteInline routes inline requests to bot
|
||||
func (r *Router) RouteInline(update *tgbotapi.Update) string {
|
||||
availableCommands := make(map[string]string)
|
||||
availableCommands["0"] = "🌲Лес"
|
||||
availableCommands["1"] = "⛰Горы"
|
||||
availableCommands["2"] = "🚣Озеро"
|
||||
availableCommands["3"] = "🏙Город"
|
||||
availableCommands["4"] = "🏛Катакомбы"
|
||||
availableCommands["5"] = "⛪️Кладбище"
|
||||
outputCommands := make(map[string]string)
|
||||
for i, value := range availableCommands {
|
||||
if strings.Contains(value, update.InlineQuery.Query) {
|
||||
outputCommands[i] = value
|
||||
}
|
||||
}
|
||||
|
||||
results := make([]interface{}, 0)
|
||||
for i, value := range outputCommands {
|
||||
article := tgbotapi.NewInlineQueryResultArticle(i, "Команда боту @PokememBroBot:", value)
|
||||
article.Description = value
|
||||
|
||||
results = append(results, article)
|
||||
}
|
||||
|
||||
inlineConf := tgbotapi.InlineConfig{
|
||||
InlineQueryID: update.InlineQuery.ID,
|
||||
IsPersonal: true,
|
||||
CacheTime: 0,
|
||||
Results: results,
|
||||
}
|
||||
|
||||
_, err := c.Bot.AnswerInlineQuery(inlineConf)
|
||||
if err != nil {
|
||||
c.Log.Error(err.Error())
|
||||
}
|
||||
|
||||
return "fail"
|
||||
}
|
@ -10,5 +10,7 @@ import (
|
||||
// RouterInterface implements Router for importing via appcontext.
|
||||
type RouterInterface interface {
|
||||
Init()
|
||||
|
||||
RouteInline(update *tgbotapi.Update) string
|
||||
RouteRequest(update *tgbotapi.Update) string
|
||||
}
|
||||
|
Reference in New Issue
Block a user