Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
i2_bot/lib/users/responders.go

132 lines
4.6 KiB
Go
Raw Normal View History

2017-10-11 06:53:50 +04:00
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package users
2017-10-11 06:53:50 +04:00
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
2017-10-26 18:17:58 +04:00
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
2017-11-14 03:44:21 +04:00
"strconv"
2017-11-24 00:16:22 +04:00
"strings"
2017-10-11 06:53:50 +04:00
)
// ProfileMessage shows current player's profile
func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
profileRaw, ok := u.GetProfile(playerRaw.ID)
2017-10-18 07:03:34 +04:00
if !ok {
return c.Talkers.AnyMessageUnauthorized(update)
2017-10-18 07:03:34 +04:00
}
league := dbmapping.League{}
err := c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE id=?"), playerRaw.LeagueID)
2017-10-18 07:03:34 +04:00
if err != nil {
2017-11-14 03:44:21 +04:00
c.Log.Error(err)
2017-10-18 07:03:34 +04:00
}
level := dbmapping.Level{}
err = c.Db.Get(&level, c.Db.Rebind("SELECT * FROM levels WHERE id=?"), profileRaw.LevelID)
2017-10-18 07:03:34 +04:00
if err != nil {
2017-11-14 03:44:21 +04:00
c.Log.Error(err)
2017-10-18 07:03:34 +04:00
}
weapon := dbmapping.Weapon{}
if profileRaw.WeaponID != 0 {
err = c.Db.Get(&weapon, c.Db.Rebind("SELECT * FROM weapons WHERE id=?"), profileRaw.WeaponID)
2017-10-18 07:03:34 +04:00
if err != nil {
2017-11-14 03:44:21 +04:00
c.Log.Error(err)
2017-10-18 07:03:34 +04:00
}
}
profilePokememes := []dbmapping.ProfilePokememe{}
err = c.Db.Select(&profilePokememes, c.Db.Rebind("SELECT * FROM profiles_pokememes WHERE profile_id=?"), profileRaw.ID)
2017-10-18 07:03:34 +04:00
if err != nil {
2017-11-14 03:44:21 +04:00
c.Log.Error(err)
2017-10-18 07:03:34 +04:00
}
pokememes := []dbmapping.Pokememe{}
err = c.Db.Select(&pokememes, c.Db.Rebind("SELECT * FROM pokememes"))
if err != nil {
2017-11-14 03:44:21 +04:00
c.Log.Error(err)
2017-10-18 07:03:34 +04:00
}
2017-10-11 06:53:50 +04:00
attackPokememes := 0
for i := range profilePokememes {
2017-10-18 07:03:34 +04:00
for j := range pokememes {
if profilePokememes[i].PokememeID == pokememes[j].ID {
singleAttack := profilePokememes[i].PokememeAttack
attackPokememes += singleAttack
2017-10-18 07:03:34 +04:00
}
}
}
2017-10-11 06:53:50 +04:00
2017-10-18 07:03:34 +04:00
message := "*Профиль игрока "
message += profileRaw.Nickname + "* (@" + profileRaw.TelegramNickname + ")\n"
2017-10-18 07:03:34 +04:00
message += "\nЛига: " + league.Symbol + league.Name
message += "\n👤 " + strconv.Itoa(profileRaw.LevelID)
message += " | 🎓 " + strconv.Itoa(profileRaw.Exp) + "/" + strconv.Itoa(level.MaxExp)
message += " | 🥚 " + strconv.Itoa(profileRaw.EggExp) + "/" + strconv.Itoa(level.MaxEgg)
message += "\n💲" + c.Statistics.GetPrintablePoints(profileRaw.Wealth)
message += " |💎" + strconv.Itoa(profileRaw.Crystalls)
message += " |⭕" + strconv.Itoa(profileRaw.Pokeballs)
message += "\n⚔Атака: 1 + " + c.Statistics.GetPrintablePoints(weapon.Power) + " + " + c.Statistics.GetPrintablePoints(attackPokememes) + "\n"
2017-10-11 06:53:50 +04:00
if profileRaw.WeaponID != 0 {
message += "\n🔫Оружие: " + weapon.Name + " " + c.Statistics.GetPrintablePoints(weapon.Power) + "⚔"
2017-10-18 07:03:34 +04:00
}
2017-10-11 06:53:50 +04:00
2017-10-18 07:03:34 +04:00
message += "\n🐱Покемемы:"
for i := range profilePokememes {
2017-10-18 07:03:34 +04:00
for j := range pokememes {
if profilePokememes[i].PokememeID == pokememes[j].ID {
2017-10-18 07:03:34 +04:00
message += "\n" + strconv.Itoa(pokememes[j].Grade)
message += "⃣ " + pokememes[j].Name
message += " +" + c.Statistics.GetPrintablePoints(profilePokememes[i].PokememeAttack) + "⚔"
2017-10-18 07:03:34 +04:00
}
}
}
message += "\nСтоимость покемемов на руках: " + c.Statistics.GetPrintablePoints(profileRaw.PokememesWealth) + "$"
message += "\n\n💳" + strconv.Itoa(playerRaw.TelegramID)
2017-11-24 00:16:22 +04:00
if playerRaw.Status == "owner" {
message += "\n\nСтатус в боте: _владелец_"
} else if playerRaw.Status == "admin" {
message += "\n\nСтатус в боте: _администратор_"
} else {
message += "\n\nСтатус в боте: _игрок_"
}
squadRoles, ok := c.Squader.GetUserRolesInSquads(playerRaw)
if ok && len(squadRoles) > 0 {
for i := range squadRoles {
if squadRoles[i].UserRole == "commander" {
message += "\nКомандир отряда " + squadRoles[i].Squad.Chat.Name
} else {
message += "\nУчастник отряда " + squadRoles[i].Squad.Chat.Name
}
}
}
message += "\n\n⏰Последнее обновление профиля: " + profileRaw.CreatedAt.Format("02.01.2006 15:04:05")
message += "\nНе забывай обновляться, это важно для получения актуальной информации.\n\n"
2017-10-18 07:03:34 +04:00
message += "/best посмотреть лучших покемемов для поимки"
2017-10-11 06:53:50 +04:00
2017-10-18 07:03:34 +04:00
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
msg.ParseMode = "Markdown"
2017-10-11 06:53:50 +04:00
2017-10-18 07:03:34 +04:00
c.Bot.Send(msg)
2017-10-11 06:53:50 +04:00
2017-10-18 07:03:34 +04:00
return "ok"
2017-10-11 06:53:50 +04:00
}
2017-11-24 00:16:22 +04:00
// UsersList lists all known users
func (u *Users) UsersList(update *tgbotapi.Update) string {
pageNumber := strings.Replace(update.Message.Text, "/users", "", 1)
pageNumber = strings.Replace(pageNumber, "/users", "", 1)
page, _ := strconv.Atoi(pageNumber)
if page == 0 {
page = 1
}
usersArray, ok := u.getUsersWithProfiles()
if !ok {
return c.Talkers.BotError(update)
2017-11-24 00:16:22 +04:00
} else {
u.usersList(update, page, usersArray)
return "ok"
}
}