hdkv
/
i2_bot
Archived
1
Fork 0
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues/pull-requests.
i2_bot/lib/pokedexer/pokedexer.go

83 lines
3.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package pokedexer
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"sort"
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
"strconv"
)
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) + ")```"
var keys []int
for i := range pokememesArray {
keys = append(keys, i)
}
sort.Ints(keys)
for _, i := range keys {
if (i > 35*(page-1)) && (i < (35*page)+1) {
pk := pokememesArray[i].Pokememe
pkE := pokememesArray[i].Elements
message += strconv.Itoa(pk.ID) + ". *[" + strconv.Itoa(pk.Grade)
message += "]* *" + pk.Name
message += "* ❤️" + c.Statistics.GetPrintablePoints(pk.HP) + " ⚔️ "
message += c.Statistics.GetPrintablePoints(pk.Attack) + " 🛡" + c.Statistics.GetPrintablePoints(pk.Defence) + " \\["
for j := range pkE {
message += pkE[j].Symbol
}
message += "] " + c.Statistics.GetPrintablePoints(pk.Price) + "$ /pk" + strconv.Itoa(pk.ID)
message += "\n"
}
}
return message
}
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])
}
return &keyboard
}
func (p *Pokedexer) pokememesListing(update *tgbotapi.Update, page int, pokememesArray map[int]*datamapping.PokememeFull) {
message := p.pokememesListingMessage(update, page, pokememesArray)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
msg.ParseMode = "Markdown"
msg.ReplyMarkup = p.pokememesListingKeyboard(pokememesArray)
c.Bot.Send(msg)
}
func (p *Pokedexer) pokememesListingUpdate(update *tgbotapi.Update, page int, pokememesArray map[int]*datamapping.PokememeFull) {
message := p.pokememesListingMessage(update, page, pokememesArray)
messageUpdate := tgbotapi.NewEditMessageText(update.CallbackQuery.Message.Chat.ID, update.CallbackQuery.Message.MessageID, message)
messageUpdate.ParseMode = "Markdown"
messageUpdate.ReplyMarkup = p.pokememesListingKeyboard(pokememesArray)
c.Bot.Send(messageUpdate)
}