All code formatted with gofmt
This commit is contained in:
parent
df58e25adc
commit
6f374e560e
@ -5,8 +5,8 @@ package appcontext
|
||||
|
||||
import (
|
||||
// 3rd-party
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"github.com/jmoiron/sqlx"
|
||||
// local
|
||||
"../config"
|
||||
"../connections"
|
||||
|
@ -7,9 +7,9 @@ import (
|
||||
// stdlib
|
||||
"log"
|
||||
// 3rd-party
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
// local
|
||||
"../config"
|
||||
)
|
||||
|
@ -16,38 +16,38 @@ import (
|
||||
func (g *Getters) formFullPokememes(pokememes []dbmapping.Pokememe) ([]dbmapping.PokememeFull, bool) {
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
elements := []dbmapping.Element{}
|
||||
err := c.Db.Select(&elements, "SELECT * FROM elements");
|
||||
err := c.Db.Select(&elements, "SELECT * FROM elements")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
locations := []dbmapping.Location{}
|
||||
err = c.Db.Select(&locations, "SELECT * FROM locations");
|
||||
err = c.Db.Select(&locations, "SELECT * FROM locations")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_elements := []dbmapping.PokememeElement{}
|
||||
err = c.Db.Select(&pokememes_elements, "SELECT * FROM pokememes_elements");
|
||||
err = c.Db.Select(&pokememes_elements, "SELECT * FROM pokememes_elements")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_locations := []dbmapping.PokememeLocation{}
|
||||
err = c.Db.Select(&pokememes_locations, "SELECT * FROM pokememes_locations");
|
||||
err = c.Db.Select(&pokememes_locations, "SELECT * FROM pokememes_locations")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
|
||||
for i := range(pokememes) {
|
||||
for i := range pokememes {
|
||||
full_pokememe := dbmapping.PokememeFull{}
|
||||
elements_listed := []dbmapping.Element{}
|
||||
locations_listed := []dbmapping.Location{}
|
||||
|
||||
for j := range(pokememes_locations) {
|
||||
for j := range pokememes_locations {
|
||||
if pokememes_locations[j].Pokememe_id == pokememes[i].Id {
|
||||
for l := range(locations) {
|
||||
for l := range locations {
|
||||
if pokememes_locations[j].Location_id == locations[l].Id {
|
||||
locations_listed = append(locations_listed, locations[l])
|
||||
}
|
||||
@ -55,9 +55,9 @@ func (g *Getters) formFullPokememes(pokememes []dbmapping.Pokememe) ([]dbmapping
|
||||
}
|
||||
}
|
||||
|
||||
for k := range(pokememes_elements) {
|
||||
for k := range pokememes_elements {
|
||||
if pokememes_elements[k].Pokememe_id == pokememes[i].Id {
|
||||
for e := range(elements) {
|
||||
for e := range elements {
|
||||
if pokememes_elements[k].Element_id == elements[e].Id {
|
||||
elements_listed = append(elements_listed, elements[e])
|
||||
}
|
||||
@ -80,7 +80,7 @@ func (g *Getters) formFullPokememes(pokememes []dbmapping.Pokememe) ([]dbmapping
|
||||
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");
|
||||
err := c.Db.Select(&pokememes, "SELECT * FROM pokememes ORDER BY grade asc, name asc")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
@ -126,25 +126,25 @@ func (g *Getters) GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, b
|
||||
return pokememe_full, false
|
||||
}
|
||||
elements := []dbmapping.Element{}
|
||||
err = c.Db.Select(&elements, "SELECT * FROM elements");
|
||||
err = c.Db.Select(&elements, "SELECT * FROM elements")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
locations := []dbmapping.Location{}
|
||||
err = c.Db.Select(&locations, "SELECT * FROM locations");
|
||||
err = c.Db.Select(&locations, "SELECT * FROM locations")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
pokememes_elements := []dbmapping.PokememeElement{}
|
||||
err = c.Db.Select(&pokememes_elements, "SELECT * FROM pokememes_elements WHERE pokememe_id='" + strconv.Itoa(pokememe.Id) + "'");
|
||||
err = c.Db.Select(&pokememes_elements, "SELECT * FROM pokememes_elements WHERE pokememe_id='"+strconv.Itoa(pokememe.Id)+"'")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
pokememes_locations := []dbmapping.PokememeLocation{}
|
||||
err = c.Db.Select(&pokememes_locations, "SELECT * FROM pokememes_locations WHERE pokememe_id='" + strconv.Itoa(pokememe.Id) + "'");
|
||||
err = c.Db.Select(&pokememes_locations, "SELECT * FROM pokememes_locations WHERE pokememe_id='"+strconv.Itoa(pokememe.Id)+"'")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
@ -153,9 +153,9 @@ func (g *Getters) GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, b
|
||||
elements_listed := []dbmapping.Element{}
|
||||
locations_listed := []dbmapping.Location{}
|
||||
|
||||
for j := range(pokememes_locations) {
|
||||
for j := range pokememes_locations {
|
||||
if pokememes_locations[j].Pokememe_id == pokememe.Id {
|
||||
for l := range(locations) {
|
||||
for l := range locations {
|
||||
if pokememes_locations[j].Location_id == locations[l].Id {
|
||||
locations_listed = append(locations_listed, locations[l])
|
||||
}
|
||||
@ -163,9 +163,9 @@ func (g *Getters) GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, b
|
||||
}
|
||||
}
|
||||
|
||||
for k := range(pokememes_elements) {
|
||||
for k := range pokememes_elements {
|
||||
if pokememes_elements[k].Pokememe_id == pokememe.Id {
|
||||
for e := range(elements) {
|
||||
for e := range elements {
|
||||
if pokememes_elements[k].Element_id == elements[e].Id {
|
||||
elements_listed = append(elements_listed, elements[e])
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
"../../dbmapping"
|
||||
)
|
||||
|
||||
|
||||
type ParsersInterface interface {
|
||||
ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
ParseProfile(update tgbotapi.Update, player_raw dbmapping.Player) string
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
// stdlib
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
// local
|
||||
"../dbmapping"
|
||||
@ -38,7 +38,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
var defendable_pokememe bool = false
|
||||
pokememe_info_strings := strings.Split(text, "\n")
|
||||
pokememe_info_runed_strings := make([][]rune, 0)
|
||||
for i := range(pokememe_info_strings) {
|
||||
for i := range pokememe_info_strings {
|
||||
pokememe_info_runed_strings = append(pokememe_info_runed_strings, []rune(pokememe_info_strings[i]))
|
||||
}
|
||||
|
||||
@ -152,7 +152,6 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
image = strings.Replace(string(pokememe_info_runed_strings[11]), " ", "", -1)
|
||||
}
|
||||
|
||||
|
||||
grade := string(pokememe_info_runed_strings[0][0])
|
||||
name := string(pokememe_info_runed_strings[0][3:])
|
||||
description := string(pokememe_info_runed_strings[1])
|
||||
@ -160,7 +159,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
log.Printf("Pokememe name: " + name)
|
||||
log.Printf("Pokememe description: " + description)
|
||||
log.Printf("Elements:")
|
||||
for i := range(elements) {
|
||||
for i := range elements {
|
||||
log.Printf(elements[i].Symbol + " " + elements[i].Name)
|
||||
}
|
||||
log.Printf("Attack: " + hitPoints[0])
|
||||
@ -169,7 +168,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
log.Printf("Defence: " + defence)
|
||||
log.Printf("Price: " + price)
|
||||
log.Printf("Locations:")
|
||||
for i := range(locations) {
|
||||
for i := range locations {
|
||||
log.Printf(locations[i].Symbol + " " + locations[i].Name)
|
||||
}
|
||||
if purchaseable {
|
||||
@ -226,7 +225,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
log.Printf("Pokememe isn't added!")
|
||||
return "fail"
|
||||
}
|
||||
for i := range(elements) {
|
||||
for i := range elements {
|
||||
link := dbmapping.PokememeElement{}
|
||||
link.Pokememe_id = pokememe.Id
|
||||
link.Element_id = elements[i].Id
|
||||
@ -238,7 +237,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
for i := range(locations) {
|
||||
for i := range locations {
|
||||
link := dbmapping.PokememeLocation{}
|
||||
link.Pokememe_id = pokememe.Id
|
||||
link.Location_id = locations[i].Id
|
||||
@ -251,7 +250,6 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return "ok"
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
// stdlib
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
@ -53,7 +53,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
|
||||
profile_info_strings := strings.Split(text, "\n")
|
||||
profile_info_runed_strings := make([][]rune, 0)
|
||||
for i := range(profile_info_strings) {
|
||||
for i := range profile_info_strings {
|
||||
profile_info_runed_strings = append(profile_info_runed_strings, []rune(profile_info_strings[i]))
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
|
||||
// Filling information
|
||||
// We don't know how many strings we got, so we iterating each other
|
||||
for i := range(profile_info_runed_strings) {
|
||||
for i := range profile_info_runed_strings {
|
||||
current_string := string(profile_info_runed_strings[i])
|
||||
current_runes := profile_info_runed_strings[i]
|
||||
if strings.HasPrefix(current_string, "🈸") || strings.HasPrefix(current_string, "🈳 ") || strings.HasPrefix(current_string, "🈵") {
|
||||
@ -88,7 +88,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
log.Println(err1)
|
||||
return "fail"
|
||||
}
|
||||
for j := range(current_runes) {
|
||||
for j := range current_runes {
|
||||
if j > 1 {
|
||||
nickname += string(current_runes[j])
|
||||
}
|
||||
@ -191,7 +191,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
log.Println(crystalls_int)
|
||||
log.Printf("Weapon: " + weapon)
|
||||
if len(pokememes) > 0 {
|
||||
for meme, attack := range(pokememes) {
|
||||
for meme, attack := range pokememes {
|
||||
log.Printf(meme + ": " + attack)
|
||||
}
|
||||
} else {
|
||||
@ -268,8 +268,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
return "fail"
|
||||
}
|
||||
|
||||
|
||||
for meme, attack := range(pokememes) {
|
||||
for meme, attack := range pokememes {
|
||||
rarity := "common"
|
||||
if strings.HasPrefix(meme, "🔸") {
|
||||
rarity = "rare"
|
||||
|
@ -5,8 +5,8 @@ package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
@ -28,7 +28,7 @@ func (t *Talkers) pokememesListing(update tgbotapi.Update, page int, pokememes_f
|
||||
}
|
||||
message += "\n\n"
|
||||
|
||||
for i := range(pokememes_full) {
|
||||
for i := range pokememes_full {
|
||||
if (i+1 > 50*(page-1)) && (i+1 < (50*page)+1) {
|
||||
pk := pokememes_full[i].Pokememe
|
||||
pk_e := pokememes_full[i].Elements
|
||||
@ -36,7 +36,7 @@ func (t *Talkers) pokememesListing(update tgbotapi.Update, page int, pokememes_f
|
||||
message += "⃣ *" + pk.Name
|
||||
message += "* (" + c.Parsers.ReturnPoints(pk.HP) + "-" + c.Parsers.ReturnPoints(pk.MP) + ") ⚔️ *"
|
||||
message += c.Parsers.ReturnPoints(pk.Attack) + "* \\["
|
||||
for j := range(pk_e) {
|
||||
for j := range pk_e {
|
||||
message += pk_e[j].Symbol
|
||||
}
|
||||
message += "] " + c.Parsers.ReturnPoints(pk.Price) + "$ /pk" + strconv.Itoa(pk.Id)
|
||||
@ -80,13 +80,13 @@ func (t *Talkers) PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
message := strconv.Itoa(pk.Grade) + "⃣ *" + pk.Name + "*\n"
|
||||
message += pk.Description + "\n\n"
|
||||
message += "Элементы:"
|
||||
for i := range(pokememe.Elements) {
|
||||
for i := range pokememe.Elements {
|
||||
message += " " + pokememe.Elements[i].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) {
|
||||
if pk.Defence != pk.Attack {
|
||||
message += "*\n🛡Защита: *" + c.Parsers.ReturnPoints(pk.Defence) + "* _(сопротивляемость покемема к поимке)_"
|
||||
} else {
|
||||
message += "*"
|
||||
@ -99,7 +99,7 @@ func (t *Talkers) PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
message += "Нельзя"
|
||||
}
|
||||
message += "*\nОбитает:"
|
||||
for i := range(pokememe.Locations) {
|
||||
for i := range pokememe.Locations {
|
||||
message += " *" + pokememe.Locations[i].Name + "*"
|
||||
if (i + 1) < len(pokememe.Locations) {
|
||||
message += ","
|
||||
@ -109,7 +109,7 @@ func (t *Talkers) PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
if calculate_possibilites {
|
||||
if (pk.Grade < profile_raw.Level_id+2) && (pk.Grade > profile_raw.Level_id-3) {
|
||||
message += "\nВероятность поимки:"
|
||||
for i := range(pokememe.Locations) {
|
||||
for i := range pokememe.Locations {
|
||||
percentile, pokeballs := c.Getters.PossibilityRequiredPokeballs(pokememe.Locations[i].Id, pk.Grade, profile_raw.Level_id)
|
||||
message += "\n" + pokememe.Locations[i].Name + " – "
|
||||
message += strconv.FormatFloat(percentile, 'f', 2, 64) + "% или "
|
||||
@ -122,7 +122,7 @@ func (t *Talkers) PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
keyboard := tgbotapi.InlineKeyboardMarkup{}
|
||||
for i := range(pokememe.Locations) {
|
||||
for i := range pokememe.Locations {
|
||||
var row []tgbotapi.InlineKeyboardButton
|
||||
btn := tgbotapi.NewInlineKeyboardButtonSwitch(pokememe.Locations[i].Symbol+pokememe.Locations[i].Name, pokememe.Locations[i].Symbol+pokememe.Locations[i].Name)
|
||||
row = append(row, btn)
|
||||
|
@ -48,8 +48,8 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, player_raw dbmapping.Pl
|
||||
}
|
||||
|
||||
attack_pm := 0
|
||||
for i := range(p_pk) {
|
||||
for j := range(pokememes) {
|
||||
for i := range p_pk {
|
||||
for j := range pokememes {
|
||||
if p_pk[i].Pokememe_id == pokememes[j].Id {
|
||||
single_attack := float64(pokememes[j].Attack)
|
||||
single_attack = single_attack * float64(p_pk[i].Pokememe_lvl)
|
||||
@ -61,7 +61,6 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, player_raw dbmapping.Pl
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
message := "*Профиль игрока "
|
||||
message += profile_raw.Nickname + "* (@" + profile_raw.TelegramNickname + ")\n"
|
||||
message += "\nЛига: " + league.Symbol + league.Name
|
||||
@ -78,8 +77,8 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, player_raw dbmapping.Pl
|
||||
}
|
||||
|
||||
message += "\n🐱Покемемы:"
|
||||
for i := range(p_pk) {
|
||||
for j := range(pokememes) {
|
||||
for i := range p_pk {
|
||||
for j := range pokememes {
|
||||
if p_pk[i].Pokememe_id == pokememes[j].Id {
|
||||
single_attack := float64(pokememes[j].Attack)
|
||||
single_attack = single_attack * float64(p_pk[i].Pokememe_lvl)
|
||||
|
@ -21,7 +21,7 @@ func (t *Talkers) BestPokememesList(update tgbotapi.Update, player_raw dbmapping
|
||||
}
|
||||
|
||||
message := "*Лучшие покемемы для ловли*\n\n"
|
||||
for i := range(pokememes) {
|
||||
for i := range pokememes {
|
||||
pk := pokememes[i].Pokememe
|
||||
pk_l := pokememes[i].Locations
|
||||
pk_e := pokememes[i].Elements
|
||||
@ -29,12 +29,12 @@ func (t *Talkers) BestPokememesList(update tgbotapi.Update, player_raw dbmapping
|
||||
message += pk.Name + " (⚔"
|
||||
message += c.Parsers.ReturnPoints(pk.Attack)
|
||||
message += ", 🛡" + c.Parsers.ReturnPoints(pk.Defence) + ")"
|
||||
for i := range(pk_e) {
|
||||
for i := range pk_e {
|
||||
message += pk_e[i].Symbol
|
||||
}
|
||||
message += " /pk" + strconv.Itoa(pk.Id) + "\n"
|
||||
message += "Локации: "
|
||||
for i := range(pk_l) {
|
||||
for i := range pk_l {
|
||||
message += pk_l[i].Symbol + pk_l[i].Name
|
||||
if i+1 < len(pk_l) {
|
||||
message += ", "
|
||||
|
Reference in New Issue
Block a user