2017-10-07 02:23:25 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package talkers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
// stdlib
|
2017-10-18 07:03:34 +04:00
|
|
|
|
"strconv"
|
2017-10-07 19:58:14 +04:00
|
|
|
|
"strings"
|
2017-10-18 07:03:34 +04:00
|
|
|
|
// 3rd party
|
2017-10-07 19:58:14 +04:00
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
2017-10-07 02:23:25 +04:00
|
|
|
|
// local
|
2017-10-13 03:05:26 +04:00
|
|
|
|
"../dbmapping"
|
2017-10-07 02:23:25 +04:00
|
|
|
|
)
|
|
|
|
|
|
2017-10-13 03:05:26 +04:00
|
|
|
|
// Internal functions
|
2017-10-07 19:58:14 +04:00
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
func (t *Talkers) pokememesListing(update tgbotapi.Update, page int, pokememesArray []dbmapping.PokememeFull) {
|
2017-10-18 07:03:34 +04:00
|
|
|
|
message := "*Известные боту покемемы*\n"
|
|
|
|
|
message += "Список отсортирован по грейду и алфавиту.\n"
|
2017-10-18 09:39:50 +04:00
|
|
|
|
message += "Покедекс: " + strconv.Itoa(len(pokememesArray)) + " / 206\n"
|
2017-10-18 07:03:34 +04:00
|
|
|
|
message += "Отображаем покемемов с " + strconv.Itoa(((page-1)*50)+1) + " по " + strconv.Itoa(page*50) + "\n"
|
2017-10-18 09:39:50 +04:00
|
|
|
|
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"
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
for i := range pokememesArray {
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if (i+1 > 50*(page-1)) && (i+1 < (50*page)+1) {
|
2017-10-18 09:39:50 +04:00
|
|
|
|
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) + "* \\["
|
2017-10-18 09:39:50 +04:00
|
|
|
|
for j := range pkE {
|
|
|
|
|
message += pkE[j].Symbol
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
2017-10-18 09:39:50 +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)
|
2017-10-07 02:23:25 +04:00
|
|
|
|
|
2017-10-13 03:05:26 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// External functions
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
// PokememesList lists all known pokememes
|
2017-10-13 03:05:26 +04:00
|
|
|
|
func (t *Talkers) PokememesList(update tgbotapi.Update, page int) {
|
2017-10-18 09:39:50 +04:00
|
|
|
|
pokememesArray, ok := c.Getters.GetPokememes()
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if !ok {
|
|
|
|
|
t.GetterError(update)
|
|
|
|
|
} else {
|
2017-10-18 09:39:50 +04:00
|
|
|
|
t.pokememesListing(update, page, pokememesArray)
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
2017-10-13 03:05:26 +04:00
|
|
|
|
}
|
2017-10-07 02:23:25 +04:00
|
|
|
|
|
2017-10-18 09:39:50 +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 {
|
2017-10-18 09:39:50 +04:00
|
|
|
|
calculatePossibilites = false
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 09:39:50 +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 += ","
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
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 {
|
2017-10-18 09:39:50 +04:00
|
|
|
|
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) + "⭕"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
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"
|
2017-10-07 02:23:25 +04:00
|
|
|
|
}
|