Pokememes individual info with search buttons
This commit is contained in:
parent
17a03bf8b2
commit
736d6b9658
@ -3,5 +3,5 @@
|
||||
go get github.com/go-sql-driver/mysql
|
||||
go get github.com/jmoiron/sqlx
|
||||
go get github.com/pressly/goose
|
||||
go get gopkg.in/telegram-bot-api.v4
|
||||
go get github.com/go-telegram-bot-api/telegram-bot-api
|
||||
go get gopkg.in/yaml.v2
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
// stdlib
|
||||
"time"
|
||||
// 3rd-party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"./lib/appcontext"
|
||||
"./lib/migrations"
|
||||
|
@ -6,7 +6,7 @@ package appcontext
|
||||
import (
|
||||
// 3rd-party
|
||||
"github.com/jmoiron/sqlx"
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../config"
|
||||
"../connections"
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const VERSION = "0.1"
|
||||
const VERSION = "0.15"
|
||||
|
||||
type DatabaseConnection struct {
|
||||
Host string `yaml:"host"`
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
// stdlib
|
||||
"log"
|
||||
// 3rd-party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
// local
|
||||
|
43
lib/migrations/9_update_locations.go
Normal file
43
lib/migrations/9_update_locations.go
Normal file
@ -0,0 +1,43 @@
|
||||
// i2_bot – Instinct PokememBro Bot
|
||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func UpdateLocationsUp(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("UPDATE `locations` SET symbol='⛪' WHERE symbol=':church:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol='🌲' WHERE symbol=':evergreen_tree:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol='🚣' WHERE symbol=':rowboat:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateLocationsDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("UPDATE `locations` SET symbol=':church:' WHERE symbol='⛪'';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol=':evergreen_tree:' WHERE symbol='🌲';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol=':rowboat:' WHERE symbol='🚣';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -23,6 +23,7 @@ func (m *Migrations) Init() {
|
||||
goose.AddNamedMigration("6_create_elements.go", CreateElementsUp, CreateElementsDown)
|
||||
goose.AddNamedMigration("7_create_leagues.go", CreateLeaguesUp, CreateLeaguesDown)
|
||||
goose.AddNamedMigration("8_create_relations.go", CreateRelationsUp, CreateRelationsDown)
|
||||
goose.AddNamedMigration("9_update_locations.go", UpdateLocationsUp, UpdateLocationsDown)
|
||||
}
|
||||
|
||||
func (m *Migrations) Migrate() error {
|
||||
|
@ -5,7 +5,7 @@ package router
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
type RouterHandler struct {}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
// 3rd party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../dbmappings"
|
||||
)
|
||||
@ -60,6 +60,7 @@ func (r *Router) RouteRequest(update tgbotapi.Update) string {
|
||||
var helpMsg = regexp.MustCompile("/help\\z")
|
||||
var helloMsg = regexp.MustCompile("/start\\z")
|
||||
var pokedexMsg = regexp.MustCompile("/pokede(x|ks)\\d?\\z")
|
||||
var pokememeInfoMsg = regexp.MustCompile("/pk(\\d+)")
|
||||
|
||||
// Forwards
|
||||
var pokememeMsg = regexp.MustCompile("(Уровень)(.+)(Опыт)(.+)\n(Элементы:)(.+)\n(.+)(💙MP)")
|
||||
@ -115,6 +116,8 @@ func (r *Router) RouteRequest(update tgbotapi.Update) string {
|
||||
} else {
|
||||
c.Talkers.PokememesList(update, 1)
|
||||
}
|
||||
case pokememeInfoMsg.MatchString(text):
|
||||
c.Talkers.PokememeInfo(update)
|
||||
// Easter eggs
|
||||
case huMsg.MatchString(text):
|
||||
c.Talkers.MatMessage(update)
|
||||
|
@ -5,7 +5,7 @@ package routerinterface
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"gopkg.in/telegram-bot-api.v4"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
type RouterInterface interface {
|
||||
|
@ -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