2017-11-26 07:55:13 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package router
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
2017-11-26 15:28:55 +04:00
|
|
|
|
"strconv"
|
2017-11-26 07:55:13 +04:00
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RouteInline routes inline requests to bot
|
|
|
|
|
func (r *Router) RouteInline(update *tgbotapi.Update) string {
|
2018-01-29 23:50:25 +04:00
|
|
|
|
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.InlineQuery.From.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
2017-11-26 15:28:55 +04:00
|
|
|
|
return "fail"
|
2017-11-26 07:55:13 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
results := make([]interface{}, 0)
|
2017-11-26 15:28:55 +04:00
|
|
|
|
|
|
|
|
|
if playerRaw.LeagueID != 1 {
|
|
|
|
|
article := tgbotapi.NewInlineQueryResultArticle("0", "Команда боту @PokememBroBot:", "👤Герой")
|
|
|
|
|
article.Description = "👤Герой"
|
2017-11-26 07:55:13 +04:00
|
|
|
|
|
|
|
|
|
results = append(results, article)
|
2017-11-26 15:28:55 +04:00
|
|
|
|
} else {
|
|
|
|
|
orderNumber, _ := strconv.Atoi(update.InlineQuery.Query)
|
|
|
|
|
if orderNumber != 0 {
|
|
|
|
|
order, ok := c.Orders.GetOrderByID(orderNumber)
|
|
|
|
|
if !ok {
|
|
|
|
|
return "fail"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attackTarget := ""
|
|
|
|
|
if order.Target == "M" {
|
|
|
|
|
attackTarget = "⚔ 🈳 МИСТИКА"
|
|
|
|
|
} else {
|
|
|
|
|
attackTarget = "⚔ 🈵 ОТВАГА"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
article := tgbotapi.NewInlineQueryResultArticle(strconv.Itoa(orderNumber), "Выполнить приказ отряда:", attackTarget)
|
|
|
|
|
article.Description = attackTarget
|
|
|
|
|
|
|
|
|
|
results = append(results, article)
|
|
|
|
|
} else {
|
|
|
|
|
availableCommands := make(map[string]string)
|
|
|
|
|
availableCommands["10"] = "🌲Лес"
|
|
|
|
|
availableCommands["11"] = "⛰Горы"
|
|
|
|
|
availableCommands["12"] = "🚣Озеро"
|
|
|
|
|
availableCommands["13"] = "🏙Город"
|
|
|
|
|
availableCommands["14"] = "🏛Катакомбы"
|
|
|
|
|
availableCommands["15"] = "⛪️Кладбище"
|
|
|
|
|
outputCommands := make(map[string]string)
|
|
|
|
|
for i, value := range availableCommands {
|
|
|
|
|
if strings.Contains(value, update.InlineQuery.Query) {
|
|
|
|
|
outputCommands[i] = value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i, value := range outputCommands {
|
|
|
|
|
article := tgbotapi.NewInlineQueryResultArticle(i, "Команда боту @PokememBroBot:", value)
|
|
|
|
|
article.Description = value
|
|
|
|
|
|
|
|
|
|
results = append(results, article)
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-26 07:55:13 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inlineConf := tgbotapi.InlineConfig{
|
|
|
|
|
InlineQueryID: update.InlineQuery.ID,
|
|
|
|
|
IsPersonal: true,
|
|
|
|
|
CacheTime: 0,
|
|
|
|
|
Results: results,
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 23:50:25 +04:00
|
|
|
|
_, err = c.Bot.AnswerInlineQuery(inlineConf)
|
2017-11-26 07:55:13 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
c.Log.Error(err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-26 15:28:55 +04:00
|
|
|
|
return "ok"
|
2017-11-26 07:55:13 +04:00
|
|
|
|
}
|