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

141 lines
4.5 KiB
Go
Raw Normal View History

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package talkers
import (
// stdlib
2017-10-18 07:03:34 +04:00
"strconv"
"strings"
2017-10-18 07:03:34 +04:00
// 3rd party
"github.com/go-telegram-bot-api/telegram-bot-api"
// local
"../dbmapping"
)
// Internal functions
func (t *Talkers) pokememesListing(update tgbotapi.Update, page int, pokememesArray []dbmapping.PokememeFull) {
2017-10-18 07:03:34 +04:00
message := "*Известные боту покемемы*\n"
message += "Список отсортирован по грейду и алфавиту.\n"
message += "Покедекс: " + strconv.Itoa(len(pokememesArray)) + " / 219\n"
2017-10-18 07:03:34 +04:00
message += "Отображаем покемемов с " + strconv.Itoa(((page-1)*50)+1) + " по " + strconv.Itoa(page*50) + "\n"
if len(pokememesArray) > page*50 {
2017-10-18 07:03:34 +04:00
message += "Переход на следующую страницу: /pokedeks" + strconv.Itoa(page+1)
}
if page > 1 {
message += "\nПереход на предыдущую страницу: /pokedeks" + strconv.Itoa(page-1)
}
message += "\n\n"
for i := range pokememesArray {
2017-10-18 07:03:34 +04:00
if (i+1 > 50*(page-1)) && (i+1 < (50*page)+1) {
pk := pokememesArray[i].Pokememe
pkE := pokememesArray[i].Elements
2017-10-18 07:03:34 +04:00
message += strconv.Itoa(i+1) + ". " + strconv.Itoa(pk.Grade)
message += "⃣ *" + pk.Name
message += "* (" + c.Parsers.ReturnPoints(pk.HP) + "-" + c.Parsers.ReturnPoints(pk.MP) + ") ⚔️ *"
message += c.Parsers.ReturnPoints(pk.Attack) + "* \\["
for j := range pkE {
message += pkE[j].Symbol
2017-10-18 07:03:34 +04:00
}
message += "] " + c.Parsers.ReturnPoints(pk.Price) + "$ /pk" + strconv.Itoa(pk.ID)
2017-10-18 07:03:34 +04:00
message += "\n"
}
}
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
msg.ParseMode = "Markdown"
c.Bot.Send(msg)
}
// External functions
// PokememesList lists all known pokememes
func (t *Talkers) PokememesList(update tgbotapi.Update, page int) {
pokememesArray, ok := c.Getters.GetPokememes()
2017-10-18 07:03:34 +04:00
if !ok {
t.GetterError(update)
} else {
t.pokememesListing(update, page, pokememesArray)
2017-10-18 07:03:34 +04:00
}
}
// PokememeInfo shows information about single pokememe based on internal ID
func (t *Talkers) PokememeInfo(update tgbotapi.Update, playerRaw dbmapping.Player) string {
pokememeNumber := strings.Replace(update.Message.Text, "/pk", "", 1)
var calculatePossibilites = true
profileRaw, ok := c.Getters.GetProfile(playerRaw.ID)
2017-10-18 07:03:34 +04:00
if !ok {
calculatePossibilites = false
2017-10-18 07:03:34 +04:00
}
pokememe, ok := c.Getters.GetPokememeByID(pokememeNumber)
2017-10-18 07:03:34 +04:00
if !ok {
return "fail"
}
pk := pokememe.Pokememe
message := strconv.Itoa(pk.Grade) + "⃣ *" + pk.Name + "*\n"
message += pk.Description + "\n\n"
message += "Элементы:"
for i := range pokememe.Elements {
message += " " + pokememe.Elements[i].Symbol
}
message += "\n⚔ Атака: *" + c.Parsers.ReturnPoints(pk.Attack)
message += "*\n❤ HP: *" + c.Parsers.ReturnPoints(pk.HP)
message += "*\n💙 MP: *" + c.Parsers.ReturnPoints(pk.MP)
if pk.Defence != pk.Attack {
message += "*\n🛡Защита: *" + c.Parsers.ReturnPoints(pk.Defence) + "* _(сопротивляемость покемема к поимке)_"
} else {
message += "*"
}
message += "\nСтоимость: *" + c.Parsers.ReturnPoints(pk.Price)
message += "*\nКупить: *"
if pk.Purchaseable {
message += "Можно"
} else {
message += "Нельзя"
}
message += "*\nОбитает:"
for i := range pokememe.Locations {
message += " *" + pokememe.Locations[i].Name + "*"
if (i + 1) < len(pokememe.Locations) {
message += ","
}
}
if calculatePossibilites {
if (pk.Grade < profileRaw.LevelID+2) && (pk.Grade > profileRaw.LevelID-3) {
2017-10-18 07:03:34 +04:00
message += "\nВероятность поимки:"
for i := range pokememe.Locations {
percentile, pokeballs := c.Getters.PossibilityRequiredPokeballs(pokememe.Locations[i].ID, pk.Grade, profileRaw.LevelID)
2017-10-18 07:03:34 +04:00
message += "\n" + pokememe.Locations[i].Name + " "
message += strconv.FormatFloat(percentile, 'f', 2, 64) + "% или "
message += strconv.Itoa(pokeballs) + "⭕"
}
}
}
message += "\n" + pk.ImageURL
2017-10-18 07:03:34 +04:00
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
keyboard := tgbotapi.InlineKeyboardMarkup{}
for i := range pokememe.Locations {
var row []tgbotapi.InlineKeyboardButton
btn := tgbotapi.NewInlineKeyboardButtonSwitch(pokememe.Locations[i].Symbol+pokememe.Locations[i].Name, pokememe.Locations[i].Symbol+pokememe.Locations[i].Name)
row = append(row, btn)
keyboard.InlineKeyboard = append(keyboard.InlineKeyboard, row)
}
msg.ReplyMarkup = keyboard
msg.ParseMode = "Markdown"
c.Bot.Send(msg)
return "ok"
}