Best pokememes for user listing
This commit is contained in:
parent
25991e0839
commit
d897d2c3f9
@ -12,7 +12,7 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "0.28"
|
const VERSION = "0.29"
|
||||||
|
|
||||||
type DatabaseConnection struct {
|
type DatabaseConnection struct {
|
||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
|
@ -12,10 +12,12 @@ type GettersInterface interface {
|
|||||||
Init()
|
Init()
|
||||||
// Player
|
// Player
|
||||||
GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool)
|
GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool)
|
||||||
|
GetPlayerByID(player_id int) (dbmapping.Player, bool)
|
||||||
// Profile
|
// Profile
|
||||||
GetProfile(player_id int) (dbmapping.Profile, bool)
|
GetProfile(player_id int) (dbmapping.Profile, bool)
|
||||||
// Pokememes
|
// Pokememes
|
||||||
GetPokememes() ([]dbmapping.PokememeFull, bool)
|
GetPokememes() ([]dbmapping.PokememeFull, bool)
|
||||||
|
GetBestPokememes(player_id int) ([]dbmapping.PokememeFull, bool)
|
||||||
GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool)
|
GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool)
|
||||||
// Possibilities
|
// Possibilities
|
||||||
PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int)
|
PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int)
|
||||||
|
@ -11,6 +11,17 @@ import (
|
|||||||
"../dbmapping"
|
"../dbmapping"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (g *Getters) GetPlayerByID(player_id int) (dbmapping.Player, bool) {
|
||||||
|
player_raw := dbmapping.Player{}
|
||||||
|
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE id=?"), player_id)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return player_raw, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return player_raw, true
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Getters) GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool) {
|
func (g *Getters) GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool) {
|
||||||
player_raw := dbmapping.Player{}
|
player_raw := dbmapping.Player{}
|
||||||
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id=?"), telegram_id)
|
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id=?"), telegram_id)
|
||||||
|
@ -11,16 +11,12 @@ import (
|
|||||||
"../dbmapping"
|
"../dbmapping"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (g *Getters) GetPokememes() ([]dbmapping.PokememeFull, bool) {
|
// Internal functions
|
||||||
|
|
||||||
|
func (g *Getters) formFullPokememes(pokememes []dbmapping.Pokememe) ([]dbmapping.PokememeFull, bool) {
|
||||||
pokememes_full := []dbmapping.PokememeFull{}
|
pokememes_full := []dbmapping.PokememeFull{}
|
||||||
pokememes := []dbmapping.Pokememe{}
|
|
||||||
err := c.Db.Select(&pokememes, "SELECT * FROM pokememes ORDER BY grade asc, name asc");
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
return pokememes_full, false
|
|
||||||
}
|
|
||||||
elements := []dbmapping.Element{}
|
elements := []dbmapping.Element{}
|
||||||
err = c.Db.Select(&elements, "SELECT * FROM elements");
|
err := c.Db.Select(&elements, "SELECT * FROM elements");
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return pokememes_full, false
|
return pokememes_full, false
|
||||||
@ -79,6 +75,48 @@ func (g *Getters) GetPokememes() ([]dbmapping.PokememeFull, bool) {
|
|||||||
return pokememes_full, true
|
return pokememes_full, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// External functions
|
||||||
|
|
||||||
|
func (g *Getters) GetPokememes() ([]dbmapping.PokememeFull, bool) {
|
||||||
|
pokememes_full := []dbmapping.PokememeFull{}
|
||||||
|
pokememes := []dbmapping.Pokememe{}
|
||||||
|
err := c.Db.Select(&pokememes, "SELECT * FROM pokememes ORDER BY grade asc, name asc");
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return pokememes_full, false
|
||||||
|
}
|
||||||
|
|
||||||
|
pokememes_full, ok := g.formFullPokememes(pokememes)
|
||||||
|
return pokememes_full, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Getters) GetBestPokememes(player_id int) ([]dbmapping.PokememeFull, bool) {
|
||||||
|
pokememes_full := []dbmapping.PokememeFull{}
|
||||||
|
player_raw, ok := g.GetPlayerByID(player_id)
|
||||||
|
if !ok {
|
||||||
|
return pokememes_full, ok
|
||||||
|
}
|
||||||
|
profile_raw, ok := g.GetProfile(player_id)
|
||||||
|
if !ok {
|
||||||
|
return pokememes_full, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
if player_raw.League_id == 0 {
|
||||||
|
return pokememes_full, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: make it more complicated
|
||||||
|
pokememes := []dbmapping.Pokememe{}
|
||||||
|
err := c.Db.Select(&pokememes, c.Db.Rebind("SELECT p.* FROM pokememes p, pokememes_elements pe, elements e WHERE e.league_id = ? AND p.grade = ? AND pe.element_id = e.id AND pe.pokememe_id = p.id ORDER BY p.attack DESC"), player_raw.League_id, profile_raw.Level_id + 1)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return pokememes_full, false
|
||||||
|
}
|
||||||
|
|
||||||
|
pokememes_full, ok = g.formFullPokememes(pokememes)
|
||||||
|
return pokememes_full, ok
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Getters) GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool) {
|
func (g *Getters) GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool) {
|
||||||
pokememe_full := dbmapping.PokememeFull{}
|
pokememe_full := dbmapping.PokememeFull{}
|
||||||
pokememe := dbmapping.Pokememe{}
|
pokememe := dbmapping.Pokememe{}
|
||||||
|
@ -10,9 +10,9 @@ import (
|
|||||||
"../dbmapping"
|
"../dbmapping"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (g *Getters) GetProfile(profile_id int) (dbmapping.Profile, bool) {
|
func (g *Getters) GetProfile(player_id int) (dbmapping.Profile, bool) {
|
||||||
profile_raw := dbmapping.Profile{}
|
profile_raw := dbmapping.Profile{}
|
||||||
err := c.Db.Get(&profile_raw, c.Db.Rebind("SELECT * FROM profiles WHERE player_id=? ORDER BY created_at DESC LIMIT 1"), profile_id)
|
err := c.Db.Get(&profile_raw, c.Db.Rebind("SELECT * FROM profiles WHERE player_id=? ORDER BY created_at DESC LIMIT 1"), player_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return profile_raw, false
|
return profile_raw, false
|
||||||
|
@ -39,6 +39,7 @@ func (r *Router) RouteRequest(update tgbotapi.Update) string {
|
|||||||
var pokedexMsg = regexp.MustCompile("/pokede(x|ks)\\d?\\z")
|
var pokedexMsg = regexp.MustCompile("/pokede(x|ks)\\d?\\z")
|
||||||
var pokememeInfoMsg = regexp.MustCompile("/pk(\\d+)")
|
var pokememeInfoMsg = regexp.MustCompile("/pk(\\d+)")
|
||||||
var meMsg = regexp.MustCompile("/me\\z")
|
var meMsg = regexp.MustCompile("/me\\z")
|
||||||
|
var bestMsg = regexp.MustCompile("/best\\z")
|
||||||
|
|
||||||
// Forwards
|
// Forwards
|
||||||
var pokememeMsg = regexp.MustCompile("(Уровень)(.+)(Опыт)(.+)\n(Элементы:)(.+)\n(.+)(💙MP)")
|
var pokememeMsg = regexp.MustCompile("(Уровень)(.+)(Опыт)(.+)\n(Элементы:)(.+)\n(.+)(💙MP)")
|
||||||
@ -114,6 +115,9 @@ func (r *Router) RouteRequest(update tgbotapi.Update) string {
|
|||||||
} else {
|
} else {
|
||||||
c.Talkers.AnyMessageUnauthorized(update)
|
c.Talkers.AnyMessageUnauthorized(update)
|
||||||
}
|
}
|
||||||
|
// Suggestions
|
||||||
|
case bestMsg.MatchString(text):
|
||||||
|
c.Talkers.BestPokememesList(update, player_raw)
|
||||||
// Easter eggs
|
// Easter eggs
|
||||||
case huMsg.MatchString(text):
|
case huMsg.MatchString(text):
|
||||||
c.Talkers.MatMessage(update)
|
c.Talkers.MatMessage(update)
|
||||||
|
@ -15,6 +15,7 @@ func (t *Talkers) HelpMessage(update tgbotapi.Update) {
|
|||||||
help_message += "Текущая версия: *" + config.VERSION + "*\n\n"
|
help_message += "Текущая версия: *" + config.VERSION + "*\n\n"
|
||||||
help_message += "Список команд:\n\n"
|
help_message += "Список команд:\n\n"
|
||||||
help_message += "+ /me – посмотреть свой сохраненный профиль в боте\n"
|
help_message += "+ /me – посмотреть свой сохраненный профиль в боте\n"
|
||||||
|
help_message += "+ /best – посмотреть лучших покемонов для поимки\n"
|
||||||
help_message += "+ /pokedeks – получить список известных боту покемемов\n"
|
help_message += "+ /pokedeks – получить список известных боту покемемов\n"
|
||||||
help_message += "+ /help – выводит данное сообщение\n"
|
help_message += "+ /help – выводит данное сообщение\n"
|
||||||
help_message += "\n\n"
|
help_message += "\n\n"
|
||||||
|
@ -95,7 +95,8 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, player_raw dbmapping.Pl
|
|||||||
}
|
}
|
||||||
message += "\n\n💳" + strconv.Itoa(player_raw.Telegram_id)
|
message += "\n\n💳" + strconv.Itoa(player_raw.Telegram_id)
|
||||||
message += "\n⏰Последнее обновление профиля: " + profile_raw.Created_at.Format("02.01.2006 15:04:05")
|
message += "\n⏰Последнее обновление профиля: " + profile_raw.Created_at.Format("02.01.2006 15:04:05")
|
||||||
message += "\n\nНе забывай обновляться, это важно для получения актуальной информации."
|
message += "\n\nНе забывай обновляться, это важно для получения актуальной информации.\n\n"
|
||||||
|
message += "/best – посмотреть лучших покемемов для поимки"
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||||
msg.ParseMode = "Markdown"
|
msg.ParseMode = "Markdown"
|
||||||
|
@ -12,7 +12,7 @@ func (t *Talkers) ProfileAddSuccessMessage(update tgbotapi.Update) {
|
|||||||
message := "*Профиль успешно обновлен.*\n\n"
|
message := "*Профиль успешно обновлен.*\n\n"
|
||||||
message += "Функциональность бота держится на актуальности профилей. Обновляйся почаще, и да пребудет с тобой Рандом!\n"
|
message += "Функциональность бота держится на актуальности профилей. Обновляйся почаще, и да пребудет с тобой Рандом!\n"
|
||||||
message += "Сохраненный профиль ты можешь просмотреть командой /me.\n\n"
|
message += "Сохраненный профиль ты можешь просмотреть командой /me.\n\n"
|
||||||
message += "– почаще – как можно чаще, но не более 48 раз в сутки."
|
message += "/best – посмотреть лучших покемемов для поимки"
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||||
msg.ParseMode = "Markdown"
|
msg.ParseMode = "Markdown"
|
||||||
|
58
lib/talkers/suggestions.go
Normal file
58
lib/talkers/suggestions.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package talkers
|
||||||
|
|
||||||
|
import (
|
||||||
|
// stdlib
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
|
// 3rd party
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
|
// local
|
||||||
|
"../dbmapping"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (t *Talkers) BestPokememesList(update tgbotapi.Update, player_raw dbmapping.Player) string {
|
||||||
|
pokememes, ok := c.Getters.GetBestPokememes(player_raw.Id)
|
||||||
|
if !ok {
|
||||||
|
log.Printf("Cannot get pokememes from getter!")
|
||||||
|
return "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
message := "*Лучшие покемемы для ловли*\n\n"
|
||||||
|
for i := range(pokememes) {
|
||||||
|
pk := pokememes[i].Pokememe
|
||||||
|
pk_l := pokememes[i].Locations
|
||||||
|
pk_e := pokememes[i].Elements
|
||||||
|
message += strconv.Itoa(pk.Grade) + "⃣ "
|
||||||
|
message += pk.Name + " (⚔"
|
||||||
|
message += c.Parsers.ReturnPoints(pk.Attack)
|
||||||
|
message += ", 🛡" + c.Parsers.ReturnPoints(pk.Defence) + ")"
|
||||||
|
for i := range(pk_e) {
|
||||||
|
message += pk_e[i].Symbol
|
||||||
|
}
|
||||||
|
message += " /pk" + strconv.Itoa(pk.Id) + "\n"
|
||||||
|
message += "Локации: "
|
||||||
|
for i := range(pk_l) {
|
||||||
|
message += pk_l[i].Symbol + pk_l[i].Name
|
||||||
|
if i + 1 < len(pk_l) {
|
||||||
|
message += ", "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message += "\nКупить: "
|
||||||
|
if pk.Purchaseable {
|
||||||
|
message += "💲" + c.Parsers.ReturnPoints(pk.Price * 3)
|
||||||
|
} else {
|
||||||
|
message += "Нельзя"
|
||||||
|
}
|
||||||
|
message += "\n\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||||
|
msg.ParseMode = "Markdown"
|
||||||
|
|
||||||
|
c.Bot.Send(msg)
|
||||||
|
|
||||||
|
return "ok"
|
||||||
|
}
|
@ -18,6 +18,7 @@ type TalkersInterface interface {
|
|||||||
HelpMessage(update tgbotapi.Update)
|
HelpMessage(update tgbotapi.Update)
|
||||||
PokememesList(update tgbotapi.Update, page int)
|
PokememesList(update tgbotapi.Update, page int)
|
||||||
PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Player) string
|
PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Player) string
|
||||||
|
BestPokememesList(update tgbotapi.Update, player_raw dbmapping.Player) string
|
||||||
|
|
||||||
// Returns
|
// Returns
|
||||||
PokememeAddSuccessMessage(update tgbotapi.Update)
|
PokememeAddSuccessMessage(update tgbotapi.Update)
|
||||||
|
Reference in New Issue
Block a user