hdkv
/
i2_bot
Archived
1
Fork 0

/advice command for searching most valuable pokememes

master
Vladimir Hodakov 2018-02-07 15:00:04 +04:00
parent c7a8fcf6de
commit 14413b3167
7 changed files with 97 additions and 14 deletions

View File

@ -82,3 +82,65 @@ func (p *Pokedexer) getBestPokememes(playerID int) ([]*dbmapping.PokememeFull, b
return pokememesArray, true return pokememesArray, true
} }
func (p *Pokedexer) getHighPricedPokememes(playerID int) ([]*dbmapping.PokememeFull, bool) {
pokememesArray := make([]*dbmapping.PokememeFull, 0)
playerRaw, err := c.DataCache.GetPlayerByID(playerID)
if err != nil {
c.Log.Error(err.Error())
return pokememesArray, false
}
profileRaw, err := c.DataCache.GetProfileByPlayerID(playerRaw.ID)
if err != nil {
c.Log.Error(err.Error())
return pokememesArray, false
}
if playerRaw.LeagueID == 0 {
return pokememesArray, false
}
allPokememes := c.DataCache.GetAllPokememes()
for i := range allPokememes {
// Adding only affordable pokememes...
// Only by force: who need to buy pokememe for selling?
if allPokememes[i].Pokememe.Defence < profileRaw.Power {
// ...and only of needed grade (+1 until 9)
neededGrade := 0
if profileRaw.LevelID < 9 {
neededGrade = profileRaw.LevelID + 1
} else {
neededGrade = 9
}
if allPokememes[i].Pokememe.Grade == neededGrade {
pokememesArray = append(pokememesArray, allPokememes[i])
}
}
}
c.Log.Debug(strconv.Itoa(len(pokememesArray)) + " pokememes passed initial /advice filtration.")
// As we have already filtered this array, we need to sort it and pass to view
sort.Slice(pokememesArray, func(i, j int) bool {
return pokememesArray[i].Pokememe.Price > pokememesArray[j].Pokememe.Price
})
if len(pokememesArray) > 10 {
idx := 0
pokememesArrayShorted := make([]*dbmapping.PokememeFull, 0)
for i := range pokememesArray {
if idx < 10 {
pokememesArrayShorted = append(pokememesArrayShorted, pokememesArray[i])
}
idx++
}
pokememesArray = pokememesArrayShorted
}
return pokememesArray, true
}

View File

@ -14,7 +14,7 @@ type PokedexerInterface interface {
PokememesList(update *tgbotapi.Update) PokememesList(update *tgbotapi.Update)
PokememeInfo(update *tgbotapi.Update, playerRaw *dbmapping.Player) string PokememeInfo(update *tgbotapi.Update, playerRaw *dbmapping.Player) string
BestPokememesList(update *tgbotapi.Update, playerRaw *dbmapping.Player) string AdvicePokememesList(update *tgbotapi.Update, playerRaw *dbmapping.Player) string
DeletePokememe(update *tgbotapi.Update) string DeletePokememe(update *tgbotapi.Update) string
} }

View File

@ -6,17 +6,28 @@ package pokedexer
import ( import (
"git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping" "git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping"
"github.com/go-telegram-bot-api/telegram-bot-api" "github.com/go-telegram-bot-api/telegram-bot-api"
"sort"
"strconv" "strconv"
"strings" "strings"
) )
// BestPokememesList shows list for catching based on player league and grade // AdvicePokememesList shows list for catching
func (p *Pokedexer) BestPokememesList(update *tgbotapi.Update, playerRaw *dbmapping.Player) string { // It may be list of best or most valuable pokememes
pokememes, ok := p.getBestPokememes(playerRaw.ID) func (p *Pokedexer) AdvicePokememesList(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
if !ok { pokememes := make([]*dbmapping.PokememeFull, 0)
c.Log.Error("Cannot get pokememes from getter!") if update.Message.Command() == "best" {
return "fail" neededPokememes, ok := p.getBestPokememes(playerRaw.ID)
if !ok {
c.Log.Error("Cannot get pokememes from getter!")
return "fail"
}
pokememes = neededPokememes
} else {
neededPokememes, ok := p.getHighPricedPokememes(playerRaw.ID)
if !ok {
c.Log.Error("Cannot get pokememes from getter!")
return "fail"
}
pokememes = neededPokememes
} }
profileRaw, err := c.DataCache.GetProfileByPlayerID(playerRaw.ID) profileRaw, err := c.DataCache.GetProfileByPlayerID(playerRaw.ID)
@ -25,11 +36,12 @@ func (p *Pokedexer) BestPokememesList(update *tgbotapi.Update, playerRaw *dbmapp
return "fail" return "fail"
} }
sort.Slice(pokememes, func(i, j int) bool { message := ""
return pokememes[i].Pokememe.Attack > pokememes[j].Pokememe.Attack if update.Message.Command() == "best" {
}) message += "*Лучшие покемемы для поимки*\n\n"
} else {
message := "*Лучшие покемемы для ловли*\n\n" message += "*Самые дорогие покемемы для поимки*\n\n"
}
for i := range pokememes { for i := range pokememes {
pk := pokememes[i].Pokememe pk := pokememes[i].Pokememe
pkL := pokememes[i].Locations pkL := pokememes[i].Locations
@ -56,6 +68,9 @@ func (p *Pokedexer) BestPokememesList(update *tgbotapi.Update, playerRaw *dbmapp
} else { } else {
message += "Нельзя" message += "Нельзя"
} }
if update.Message.Command() == "advice" {
message += "\nСтоимость продажи: 💲" + c.Statistics.GetPrintablePoints(pk.Price)
}
if len(message) > 3000 { if len(message) > 3000 {
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
msg.ParseMode = "Markdown" msg.ParseMode = "Markdown"

View File

@ -89,7 +89,10 @@ func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmappi
return c.Talkers.AnyMessageUnauthorized(update) return c.Talkers.AnyMessageUnauthorized(update)
case update.Message.Command() == "best": case update.Message.Command() == "best":
c.Pokedexer.BestPokememesList(update, playerRaw) c.Pokedexer.AdvicePokememesList(update, playerRaw)
return "ok"
case update.Message.Command() == "advice":
c.Pokedexer.AdvicePokememesList(update, playerRaw)
return "ok" return "ok"
case update.Message.Command() == "reminders": case update.Message.Command() == "reminders":
return c.Reminder.AlarmsList(update, playerRaw) return c.Reminder.AlarmsList(update, playerRaw)

View File

@ -54,6 +54,7 @@ func (t *Talkers) HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Play
message += "Список команд\n\n" message += "Список команд\n\n"
message += "\\* /me посмотреть свой сохраненный профиль в боте\n" message += "\\* /me посмотреть свой сохраненный профиль в боте\n"
message += "\\* /best посмотреть лучших покемонов для поимки\n" message += "\\* /best посмотреть лучших покемонов для поимки\n"
message += "\\* /advice посмотреть самых дорогих покемонов для поимки\n"
message += "\\* /top — топ игроков лиги\n" message += "\\* /top — топ игроков лиги\n"
message += "\\* /top\\_my — топ игроков лиги твоего уровня\n" message += "\\* /top\\_my — топ игроков лиги твоего уровня\n"
message += "\\* /pokedeks получить список известных боту покемемов\n" message += "\\* /pokedeks получить список известных боту покемемов\n"

View File

@ -210,6 +210,7 @@ func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Pla
message += "\n\n⏰Последнее обновление профиля: " + profileRaw.CreatedAt.Format("02.01.2006 15:04:05") message += "\n\n⏰Последнее обновление профиля: " + profileRaw.CreatedAt.Format("02.01.2006 15:04:05")
message += "\nНе забывай обновляться, это важно для получения актуальной информации.\n\n" message += "\nНе забывай обновляться, это важно для получения актуальной информации.\n\n"
message += "/best посмотреть лучших покемемов для поимки\n" message += "/best посмотреть лучших покемемов для поимки\n"
message += "/advice посмотреть самых дорогих покемемов для поимки\n"
message += "/top — посмотреть лучших игроков лиги\n" message += "/top — посмотреть лучших игроков лиги\n"
message += "/top\\_my — посмотреть лучших игроков лиги твоего уровня\n" message += "/top\\_my — посмотреть лучших игроков лиги твоего уровня\n"

View File

@ -117,6 +117,7 @@ func (u *Users) profileAddSuccessMessage(update *tgbotapi.Update, leagueID int,
message += "Функциональность бота держится на актуальности профилей. Обновляйся почаще, и да пребудет с тобой Рандом!\n" message += "Функциональность бота держится на актуальности профилей. Обновляйся почаще, и да пребудет с тобой Рандом!\n"
message += "Сохраненный профиль ты можешь просмотреть командой /me.\n\n" message += "Сохраненный профиль ты можешь просмотреть командой /me.\n\n"
message += "/best посмотреть лучших покемемов для поимки\n" message += "/best посмотреть лучших покемемов для поимки\n"
message += "/advice посмотреть самых дорогих покемемов для поимки\n"
message += "/top — посмотреть лучших представителей лиги\n" message += "/top — посмотреть лучших представителей лиги\n"
message += "/top\\_my — посмотреть лучших представителей лиги твоего уровня\n" message += "/top\\_my — посмотреть лучших представителей лиги твоего уровня\n"