Pokememes individual info with search buttons
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
// 3rd party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func (t *Talkers) DurakMessage(update tgbotapi.Update) {
|
||||
|
@@ -5,7 +5,7 @@ package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func (t *Talkers) AnyMessageUnauthorized(update tgbotapi.Update) {
|
||||
|
@@ -5,7 +5,7 @@ package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../dbmappings"
|
||||
)
|
||||
|
@@ -5,7 +5,7 @@ package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../config"
|
||||
)
|
||||
@@ -14,6 +14,7 @@ func (t *Talkers) HelpMessage(update tgbotapi.Update) {
|
||||
help_message := "*Бот Инстинкта Enchanched.*\n\n"
|
||||
help_message += "Текущая версия: *" + config.VERSION + "*\n\n"
|
||||
help_message += "Список команд:\n\n"
|
||||
help_message += "+ /pokedex – получить список известных боту покемемов\n"
|
||||
help_message += "+ /help – выводит данное сообщение\n"
|
||||
help_message += "\n\n"
|
||||
help_message += "Связаться с автором: @fat0troll\n"
|
||||
|
@@ -6,9 +6,10 @@ package talkers
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"strings"
|
||||
"strconv"
|
||||
// 3rd party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../dbmappings"
|
||||
)
|
||||
@@ -19,6 +20,100 @@ type PokememeFull struct {
|
||||
Locations []dbmappings.Locations
|
||||
}
|
||||
|
||||
func (t *Talkers) PokememeInfo(update tgbotapi.Update) string {
|
||||
pokememe_number := strings.Replace(update.Message.Text, "/pk", "", 1)
|
||||
|
||||
// Building pokememe
|
||||
pk := dbmappings.Pokememes{}
|
||||
// Checking if pokememe exists in database
|
||||
err := c.Db.Get(&pk, c.Db.Rebind("SELECT * FROM pokememes WHERE id='" + pokememe_number + "'"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return "fail"
|
||||
}
|
||||
|
||||
elements := []dbmappings.Elements{}
|
||||
err = c.Db.Select(&elements, "SELECT * FROM elements");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
locations := []dbmappings.Locations{}
|
||||
err = c.Db.Select(&locations, "SELECT * FROM locations");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
pokememes_elements := []dbmappings.PokememesElements{}
|
||||
err = c.Db.Select(&pokememes_elements, "SELECT * FROM pokememes_elements WHERE pokememe_id='" + pokememe_number + "'");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
pokememes_locations := []dbmappings.PokememesLocations{}
|
||||
err = c.Db.Select(&pokememes_locations, "SELECT * FROM pokememes_locations WHERE pokememe_id='" + pokememe_number + "'");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
message := strconv.Itoa(pk.Grade) + "⃣ *" + pk.Name + "*\n"
|
||||
message += pk.Description + "\n\n"
|
||||
message += "Элементы:"
|
||||
for i := range(pokememes_elements) {
|
||||
for j := range(elements) {
|
||||
if pokememes_elements[i].Element_id == elements[j].Id {
|
||||
message += " " + elements[j].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(pokememes_locations) {
|
||||
for j := range(locations) {
|
||||
if pokememes_locations[i].Location_id == locations[j].Id {
|
||||
message += " *" + locations[j].Name + "*"
|
||||
if (i + 1) < len(pokememes_locations) {
|
||||
message += ","
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message += "\n" + pk.Image_url
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
keyboard := tgbotapi.InlineKeyboardMarkup{}
|
||||
for i := range(pokememes_locations) {
|
||||
for j := range(locations) {
|
||||
if pokememes_locations[i].Location_id == locations[j].Id {
|
||||
var row []tgbotapi.InlineKeyboardButton
|
||||
btn := tgbotapi.NewInlineKeyboardButtonSwitch(locations[j].Symbol + locations[j].Name, locations[j].Symbol + locations[j].Name)
|
||||
row = append(row, btn)
|
||||
keyboard.InlineKeyboard = append(keyboard.InlineKeyboard, row)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg.ReplyMarkup = keyboard
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
|
||||
return "ok"
|
||||
}
|
||||
|
||||
func (t *Talkers) PokememesList(update tgbotapi.Update, page int) {
|
||||
pokememes := []dbmappings.Pokememes{}
|
||||
err := c.Db.Select(&pokememes, "SELECT * FROM pokememes");
|
||||
|
@@ -5,7 +5,7 @@ package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func (t *Talkers) PokememeAddSuccessMessage(update tgbotapi.Update) {
|
||||
|
@@ -5,7 +5,7 @@ package talkersinterface
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../../dbmappings"
|
||||
)
|
||||
@@ -17,6 +17,7 @@ type TalkersInterface interface {
|
||||
HelloMessageAuthorized(update tgbotapi.Update, player_raw dbmappings.Players)
|
||||
HelpMessage(update tgbotapi.Update)
|
||||
PokememesList(update tgbotapi.Update, page int)
|
||||
PokememeInfo(update tgbotapi.Update) string
|
||||
|
||||
// Returns
|
||||
PokememeAddSuccessMessage(update tgbotapi.Update)
|
||||
|
Reference in New Issue
Block a user