2017-11-21 06:06:32 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package pokedexer
|
|
|
|
|
|
|
|
|
|
import (
|
2018-01-29 23:50:25 +04:00
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
|
|
|
"sort"
|
2018-05-02 00:47:55 +04:00
|
|
|
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
2017-11-21 06:06:32 +04:00
|
|
|
|
"strconv"
|
|
|
|
|
)
|
|
|
|
|
|
2018-05-02 00:47:55 +04:00
|
|
|
|
func (p *Pokedexer) pokememesListingMessage(update *tgbotapi.Update, page int, pokememesArray map[int]*datamapping.PokememeFull) string {
|
|
|
|
|
message := "📕*Покедекс: " + strconv.Itoa(len(pokememesArray)) + " / 733*\n"
|
|
|
|
|
message += "```\nВсе виды покемемов, которые известны боту. [" + strconv.Itoa(page) + "] (" + strconv.Itoa(((page-1)*35)+1) + "-" + strconv.Itoa(page*35) + ")```"
|
2017-11-21 06:06:32 +04:00
|
|
|
|
|
2018-01-29 23:50:25 +04:00
|
|
|
|
var keys []int
|
2017-11-21 06:06:32 +04:00
|
|
|
|
for i := range pokememesArray {
|
2018-01-29 23:50:25 +04:00
|
|
|
|
keys = append(keys, i)
|
|
|
|
|
}
|
|
|
|
|
sort.Ints(keys)
|
|
|
|
|
|
|
|
|
|
for _, i := range keys {
|
2018-05-02 00:47:55 +04:00
|
|
|
|
if (i > 35*(page-1)) && (i < (35*page)+1) {
|
2017-11-21 06:06:32 +04:00
|
|
|
|
pk := pokememesArray[i].Pokememe
|
|
|
|
|
pkE := pokememesArray[i].Elements
|
2018-05-02 00:47:55 +04:00
|
|
|
|
message += strconv.Itoa(pk.ID) + ". *[" + strconv.Itoa(pk.Grade)
|
2018-03-31 09:16:32 +04:00
|
|
|
|
message += "]* *" + pk.Name
|
2018-05-02 00:47:55 +04:00
|
|
|
|
message += "* ❤️" + c.Statistics.GetPrintablePoints(pk.HP) + " ⚔️ "
|
|
|
|
|
message += c.Statistics.GetPrintablePoints(pk.Attack) + " 🛡" + c.Statistics.GetPrintablePoints(pk.Defence) + " \\["
|
2017-11-21 06:06:32 +04:00
|
|
|
|
for j := range pkE {
|
|
|
|
|
message += pkE[j].Symbol
|
|
|
|
|
}
|
|
|
|
|
message += "] " + c.Statistics.GetPrintablePoints(pk.Price) + "$ /pk" + strconv.Itoa(pk.ID)
|
|
|
|
|
message += "\n"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 00:47:55 +04:00
|
|
|
|
return message
|
2017-11-21 06:06:32 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 00:47:55 +04:00
|
|
|
|
func (p *Pokedexer) pokememesListingKeyboard(pokememesArray map[int]*datamapping.PokememeFull) *tgbotapi.InlineKeyboardMarkup {
|
|
|
|
|
keyboard := tgbotapi.InlineKeyboardMarkup{}
|
|
|
|
|
rows := make(map[int][]tgbotapi.InlineKeyboardButton)
|
|
|
|
|
rows[0] = []tgbotapi.InlineKeyboardButton{}
|
|
|
|
|
if len(pokememesArray) > 35*7 {
|
|
|
|
|
rows[1] = []tgbotapi.InlineKeyboardButton{}
|
|
|
|
|
}
|
|
|
|
|
if len(pokememesArray) > 35*14 {
|
|
|
|
|
rows[2] = []tgbotapi.InlineKeyboardButton{}
|
|
|
|
|
}
|
|
|
|
|
totalPages := int(len(pokememesArray)/35) + 1
|
|
|
|
|
for i := 1; i <= totalPages; i++ {
|
|
|
|
|
btn := tgbotapi.NewInlineKeyboardButtonData(strconv.Itoa(i), "pokedeks"+strconv.Itoa(i))
|
|
|
|
|
rows[(i-1)/7] = append(rows[(i-1)/7], btn)
|
|
|
|
|
}
|
|
|
|
|
for i := range rows {
|
|
|
|
|
keyboard.InlineKeyboard = append(keyboard.InlineKeyboard, rows[i])
|
|
|
|
|
}
|
2017-11-21 06:06:32 +04:00
|
|
|
|
|
2018-05-02 00:47:55 +04:00
|
|
|
|
return &keyboard
|
2017-11-21 06:06:32 +04:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 00:47:55 +04:00
|
|
|
|
func (p *Pokedexer) pokememesListing(update *tgbotapi.Update, page int, pokememesArray map[int]*datamapping.PokememeFull) {
|
|
|
|
|
message := p.pokememesListingMessage(update, page, pokememesArray)
|
2017-11-21 06:06:32 +04:00
|
|
|
|
|
|
|
|
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
|
|
|
|
msg.ParseMode = "Markdown"
|
2018-05-02 00:47:55 +04:00
|
|
|
|
msg.ReplyMarkup = p.pokememesListingKeyboard(pokememesArray)
|
2017-11-21 06:06:32 +04:00
|
|
|
|
|
|
|
|
|
c.Bot.Send(msg)
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 00:47:55 +04:00
|
|
|
|
func (p *Pokedexer) pokememesListingUpdate(update *tgbotapi.Update, page int, pokememesArray map[int]*datamapping.PokememeFull) {
|
|
|
|
|
message := p.pokememesListingMessage(update, page, pokememesArray)
|
2017-11-21 06:06:32 +04:00
|
|
|
|
|
2018-05-02 00:47:55 +04:00
|
|
|
|
messageUpdate := tgbotapi.NewEditMessageText(update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Message.MessageID, message)
|
|
|
|
|
messageUpdate.ParseMode = "Markdown"
|
|
|
|
|
messageUpdate.ReplyMarkup = p.pokememesListingKeyboard(pokememesArray)
|
2017-11-21 06:06:32 +04:00
|
|
|
|
|
2018-05-02 00:47:55 +04:00
|
|
|
|
c.Bot.Send(messageUpdate)
|
2017-11-21 06:06:32 +04:00
|
|
|
|
}
|