Archived
1

All code formatted with gofmt

This commit is contained in:
Vladimir Hodakov 2017-10-18 07:03:34 +04:00
parent df58e25adc
commit 6f374e560e
58 changed files with 1957 additions and 1962 deletions

View File

@ -5,8 +5,8 @@ package appcontext
import ( import (
// 3rd-party // 3rd-party
"github.com/jmoiron/sqlx"
"github.com/go-telegram-bot-api/telegram-bot-api" "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/jmoiron/sqlx"
// local // local
"../config" "../config"
"../connections" "../connections"

View File

@ -7,9 +7,9 @@ import (
// stdlib // stdlib
"log" "log"
// 3rd-party // 3rd-party
_ "github.com/go-sql-driver/mysql"
"github.com/go-telegram-bot-api/telegram-bot-api" "github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
_ "github.com/go-sql-driver/mysql"
// local // local
"../config" "../config"
) )
@ -29,7 +29,7 @@ func BotInit(cfg *config.Config) *tgbotapi.BotAPI {
} }
func DBInit(cfg *config.Config) *sqlx.DB { func DBInit(cfg *config.Config) *sqlx.DB {
database, err := sqlx.Connect("mysql", cfg.Database.User + ":" + cfg.Database.Password + "@tcp(" + cfg.Database.Host + ":" + cfg.Database.Port + ")/" + cfg.Database.Database + "?parseTime=true&charset=utf8mb4,utf8") database, err := sqlx.Connect("mysql", cfg.Database.User+":"+cfg.Database.Password+"@tcp("+cfg.Database.Host+":"+cfg.Database.Port+")/"+cfg.Database.Database+"?parseTime=true&charset=utf8mb4,utf8")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -15,7 +15,7 @@ var (
c *appcontext.Context c *appcontext.Context
) )
type Getters struct {} type Getters struct{}
func New(ac *appcontext.Context) { func New(ac *appcontext.Context) {
c = ac c = ac

View File

@ -16,38 +16,38 @@ import (
func (g *Getters) formFullPokememes(pokememes []dbmapping.Pokememe) ([]dbmapping.PokememeFull, bool) { func (g *Getters) formFullPokememes(pokememes []dbmapping.Pokememe) ([]dbmapping.PokememeFull, bool) {
pokememes_full := []dbmapping.PokememeFull{} pokememes_full := []dbmapping.PokememeFull{}
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
} }
locations := []dbmapping.Location{} locations := []dbmapping.Location{}
err = c.Db.Select(&locations, "SELECT * FROM locations"); err = c.Db.Select(&locations, "SELECT * FROM locations")
if err != nil { if err != nil {
log.Println(err) log.Println(err)
return pokememes_full, false return pokememes_full, false
} }
pokememes_elements := []dbmapping.PokememeElement{} 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 { if err != nil {
log.Println(err) log.Println(err)
return pokememes_full, false return pokememes_full, false
} }
pokememes_locations := []dbmapping.PokememeLocation{} 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 { if err != nil {
log.Println(err) log.Println(err)
return pokememes_full, false return pokememes_full, false
} }
for i := range(pokememes) { for i := range pokememes {
full_pokememe := dbmapping.PokememeFull{} full_pokememe := dbmapping.PokememeFull{}
elements_listed := []dbmapping.Element{} elements_listed := []dbmapping.Element{}
locations_listed := []dbmapping.Location{} locations_listed := []dbmapping.Location{}
for j := range(pokememes_locations) { for j := range pokememes_locations {
if pokememes_locations[j].Pokememe_id == pokememes[i].Id { 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 { if pokememes_locations[j].Location_id == locations[l].Id {
locations_listed = append(locations_listed, locations[l]) 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 { 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 { if pokememes_elements[k].Element_id == elements[e].Id {
elements_listed = append(elements_listed, elements[e]) 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) { func (g *Getters) GetPokememes() ([]dbmapping.PokememeFull, bool) {
pokememes_full := []dbmapping.PokememeFull{} pokememes_full := []dbmapping.PokememeFull{}
pokememes := []dbmapping.Pokememe{} 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 { if err != nil {
log.Println(err) log.Println(err)
return pokememes_full, false return pokememes_full, false
@ -107,7 +107,7 @@ func (g *Getters) GetBestPokememes(player_id int) ([]dbmapping.PokememeFull, boo
// TODO: make it more complicated // TODO: make it more complicated
pokememes := []dbmapping.Pokememe{} 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) 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 { if err != nil {
log.Println(err) log.Println(err)
return pokememes_full, false return pokememes_full, false
@ -126,25 +126,25 @@ func (g *Getters) GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, b
return pokememe_full, false return pokememe_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 pokememe_full, false return pokememe_full, false
} }
locations := []dbmapping.Location{} locations := []dbmapping.Location{}
err = c.Db.Select(&locations, "SELECT * FROM locations"); err = c.Db.Select(&locations, "SELECT * FROM locations")
if err != nil { if err != nil {
log.Println(err) log.Println(err)
return pokememe_full, false return pokememe_full, false
} }
pokememes_elements := []dbmapping.PokememeElement{} 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 { if err != nil {
log.Println(err) log.Println(err)
return pokememe_full, false return pokememe_full, false
} }
pokememes_locations := []dbmapping.PokememeLocation{} 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 { if err != nil {
log.Println(err) log.Println(err)
return pokememe_full, false return pokememe_full, false
@ -153,9 +153,9 @@ func (g *Getters) GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, b
elements_listed := []dbmapping.Element{} elements_listed := []dbmapping.Element{}
locations_listed := []dbmapping.Location{} locations_listed := []dbmapping.Location{}
for j := range(pokememes_locations) { for j := range pokememes_locations {
if pokememes_locations[j].Pokememe_id == pokememe.Id { 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 { if pokememes_locations[j].Location_id == locations[l].Id {
locations_listed = append(locations_listed, locations[l]) 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 { 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 { if pokememes_elements[k].Element_id == elements[e].Id {
elements_listed = append(elements_listed, elements[e]) elements_listed = append(elements_listed, elements[e])
} }

View File

@ -10,7 +10,7 @@ import (
"github.com/pressly/goose" "github.com/pressly/goose"
) )
type Migrations struct {} type Migrations struct{}
func (m *Migrations) Init() { func (m *Migrations) Init() {
log.Printf("Initializing migrations...") log.Printf("Initializing migrations...")

View File

@ -13,7 +13,7 @@ var (
c *appcontext.Context c *appcontext.Context
) )
type Parsers struct {} type Parsers struct{}
func New(ac *appcontext.Context) { func New(ac *appcontext.Context) {
c = ac c = ac

View File

@ -10,7 +10,6 @@ import (
"../../dbmapping" "../../dbmapping"
) )
type ParsersInterface interface { type ParsersInterface interface {
ParsePokememe(text string, player_raw dbmapping.Player) string ParsePokememe(text string, player_raw dbmapping.Player) string
ParseProfile(update tgbotapi.Update, player_raw dbmapping.Player) string ParseProfile(update tgbotapi.Update, player_raw dbmapping.Player) string

View File

@ -7,8 +7,8 @@ import (
// stdlib // stdlib
"log" "log"
"regexp" "regexp"
"strings"
"strconv" "strconv"
"strings"
"time" "time"
// local // local
"../dbmapping" "../dbmapping"
@ -38,7 +38,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
var defendable_pokememe bool = false var defendable_pokememe bool = false
pokememe_info_strings := strings.Split(text, "\n") pokememe_info_strings := strings.Split(text, "\n")
pokememe_info_runed_strings := make([][]rune, 0) 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])) pokememe_info_runed_strings = append(pokememe_info_runed_strings, []rune(pokememe_info_strings[i]))
} }
@ -57,7 +57,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
element_emojis = append(element_emojis, string(pokememe_info_runed_strings[4][15])) element_emojis = append(element_emojis, string(pokememe_info_runed_strings[4][15]))
} }
err := c.Db.Select(&elements, "SELECT * FROM elements WHERE symbol IN ('" + strings.Join(element_emojis, "', '") + "')") err := c.Db.Select(&elements, "SELECT * FROM elements WHERE symbol IN ('"+strings.Join(element_emojis, "', '")+"')")
if err != nil { if err != nil {
log.Printf(err.Error()) log.Printf(err.Error())
return "fail" return "fail"
@ -109,7 +109,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
return "fail" return "fail"
} }
err2 := c.Db.Select(&locations, "SELECT * FROM locations WHERE name IN ('" + strings.Join(locationsNames, "', '") + "')") err2 := c.Db.Select(&locations, "SELECT * FROM locations WHERE name IN ('"+strings.Join(locationsNames, "', '")+"')")
if err2 != nil { if err2 != nil {
log.Printf(err2.Error()) log.Printf(err2.Error())
return "fail" return "fail"
@ -141,7 +141,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
return "fail" return "fail"
} }
err2 := c.Db.Select(&locations, "SELECT * FROM locations WHERE name IN ('" + strings.Join(locationsNames, "', '") + "')") err2 := c.Db.Select(&locations, "SELECT * FROM locations WHERE name IN ('"+strings.Join(locationsNames, "', '")+"')")
if err2 != nil { if err2 != nil {
log.Printf(err2.Error()) log.Printf(err2.Error())
return "fail" return "fail"
@ -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) image = strings.Replace(string(pokememe_info_runed_strings[11]), " ", "", -1)
} }
grade := string(pokememe_info_runed_strings[0][0]) grade := string(pokememe_info_runed_strings[0][0])
name := string(pokememe_info_runed_strings[0][3:]) name := string(pokememe_info_runed_strings[0][3:])
description := string(pokememe_info_runed_strings[1]) 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 name: " + name)
log.Printf("Pokememe description: " + description) log.Printf("Pokememe description: " + description)
log.Printf("Elements:") log.Printf("Elements:")
for i := range(elements) { for i := range elements {
log.Printf(elements[i].Symbol + " " + elements[i].Name) log.Printf(elements[i].Symbol + " " + elements[i].Name)
} }
log.Printf("Attack: " + hitPoints[0]) 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("Defence: " + defence)
log.Printf("Price: " + price) log.Printf("Price: " + price)
log.Printf("Locations:") log.Printf("Locations:")
for i := range(locations) { for i := range locations {
log.Printf(locations[i].Symbol + " " + locations[i].Name) log.Printf(locations[i].Symbol + " " + locations[i].Name)
} }
if purchaseable { if purchaseable {
@ -182,7 +181,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
// Building pokememe // Building pokememe
pokememe := dbmapping.Pokememe{} pokememe := dbmapping.Pokememe{}
// Checking if pokememe exists in database // Checking if pokememe exists in database
err3 := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE grade='" + grade + "' AND name='" + name + "';")) err3 := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE grade='"+grade+"' AND name='"+name+"';"))
if err3 != nil { if err3 != nil {
log.Printf("Adding new pokememe...") log.Printf("Adding new pokememe...")
} else { } else {
@ -221,12 +220,12 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
} }
// Getting new pokememe // Getting new pokememe
err5 := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE grade='" + grade + "' AND name='" + name + "';")) err5 := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE grade='"+grade+"' AND name='"+name+"';"))
if err5 != nil { if err5 != nil {
log.Printf("Pokememe isn't added!") log.Printf("Pokememe isn't added!")
return "fail" return "fail"
} }
for i := range(elements) { for i := range elements {
link := dbmapping.PokememeElement{} link := dbmapping.PokememeElement{}
link.Pokememe_id = pokememe.Id link.Pokememe_id = pokememe.Id
link.Element_id = elements[i].Id link.Element_id = elements[i].Id
@ -238,7 +237,7 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
return "fail" return "fail"
} }
} }
for i := range(locations) { for i := range locations {
link := dbmapping.PokememeLocation{} link := dbmapping.PokememeLocation{}
link.Pokememe_id = pokememe.Id link.Pokememe_id = pokememe.Id
link.Location_id = locations[i].Id link.Location_id = locations[i].Id
@ -251,7 +250,6 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
} }
} }
return "ok" return "ok"
} }

View File

@ -7,8 +7,8 @@ import (
// stdlib // stdlib
"log" "log"
"regexp" "regexp"
"strings"
"strconv" "strconv"
"strings"
"time" "time"
// 3rd party // 3rd party
"github.com/go-telegram-bot-api/telegram-bot-api" "github.com/go-telegram-bot-api/telegram-bot-api"
@ -20,7 +20,7 @@ import (
func (p *Parsers) fillProfilePokememe(profile_id int, meme string, attack string, rarity string) { func (p *Parsers) fillProfilePokememe(profile_id int, meme string, attack string, rarity string) {
spk_raw := dbmapping.Pokememe{} spk_raw := dbmapping.Pokememe{}
err := c.Db.Get(&spk_raw, c.Db.Rebind("SELECT * FROM pokememes WHERE name='" + meme + "';")) err := c.Db.Get(&spk_raw, c.Db.Rebind("SELECT * FROM pokememes WHERE name='"+meme+"';"))
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} else { } else {
@ -53,7 +53,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
profile_info_strings := strings.Split(text, "\n") profile_info_strings := strings.Split(text, "\n")
profile_info_runed_strings := make([][]rune, 0) 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])) profile_info_runed_strings = append(profile_info_runed_strings, []rune(profile_info_strings[i]))
} }
@ -79,16 +79,16 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
// Filling information // Filling information
// We don't know how many strings we got, so we iterating each other // 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_string := string(profile_info_runed_strings[i])
current_runes := 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, "🈵") { if strings.HasPrefix(current_string, "🈸") || strings.HasPrefix(current_string, "🈳 ") || strings.HasPrefix(current_string, "🈵") {
err1 := c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE symbol='" + string(current_runes[0]) + "'")) err1 := c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE symbol='"+string(current_runes[0])+"'"))
if err1 != nil { if err1 != nil {
log.Println(err1) log.Println(err1)
return "fail" return "fail"
} }
for j := range(current_runes) { for j := range current_runes {
if j > 1 { if j > 1 {
nickname += string(current_runes[j]) nickname += string(current_runes[j])
} }
@ -138,7 +138,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
} }
wealth = wealth_array[0] wealth = wealth_array[0]
wealth_int = p.getPoints(wealth) wealth_int = p.getPoints(wealth)
crystalls =wealth_array[1] crystalls = wealth_array[1]
crystalls_int = p.getPoints(crystalls) crystalls_int = p.getPoints(crystalls)
} }
@ -159,7 +159,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
pokememes_count, _ := strconv.Atoi(pk_num_array[0]) pokememes_count, _ := strconv.Atoi(pk_num_array[0])
if pokememes_count > 0 { if pokememes_count > 0 {
for pi := 0; pi < pokememes_count; pi++ { for pi := 0; pi < pokememes_count; pi++ {
pokememe_string := string(profile_info_runed_strings[i + 1 + pi]) pokememe_string := string(profile_info_runed_strings[i+1+pi])
attackRx := regexp.MustCompile("(\\d|\\.|K|M)+") attackRx := regexp.MustCompile("(\\d|\\.|K|M)+")
pk_points_array := attackRx.FindAllString(pokememe_string, -1) pk_points_array := attackRx.FindAllString(pokememe_string, -1)
pk_attack := pk_points_array[1] pk_attack := pk_points_array[1]
@ -191,7 +191,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
log.Println(crystalls_int) log.Println(crystalls_int)
log.Printf("Weapon: " + weapon) log.Printf("Weapon: " + weapon)
if len(pokememes) > 0 { if len(pokememes) > 0 {
for meme, attack := range(pokememes) { for meme, attack := range pokememes {
log.Printf(meme + ": " + attack) log.Printf(meme + ": " + attack)
} }
} else { } else {
@ -200,7 +200,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
// Information is gathered, let's create profile in database! // Information is gathered, let's create profile in database!
weapon_raw := dbmapping.Weapon{} weapon_raw := dbmapping.Weapon{}
err2 := c.Db.Get(&weapon_raw, c.Db.Rebind("SELECT * FROM weapons WHERE name='" + weapon + "'")) err2 := c.Db.Get(&weapon_raw, c.Db.Rebind("SELECT * FROM weapons WHERE name='"+weapon+"'"))
if err2 != nil { if err2 != nil {
log.Println(err2) log.Println(err2)
} }
@ -227,7 +227,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
log.Println(err5) log.Println(err5)
return "fail" return "fail"
} }
err6 := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id='" + strconv.Itoa(player_raw.Telegram_id) + "' AND league_id='" + strconv.Itoa(league.Id) + "';")) err6 := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id='"+strconv.Itoa(player_raw.Telegram_id)+"' AND league_id='"+strconv.Itoa(league.Id)+"';"))
if err6 != nil { if err6 != nil {
log.Println(err6) log.Println(err6)
return "fail" return "fail"
@ -268,8 +268,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
return "fail" return "fail"
} }
for meme, attack := range pokememes {
for meme, attack := range(pokememes) {
rarity := "common" rarity := "common"
if strings.HasPrefix(meme, "🔸") { if strings.HasPrefix(meme, "🔸") {
rarity = "rare" rarity = "rare"

View File

@ -8,7 +8,7 @@ import (
"github.com/go-telegram-bot-api/telegram-bot-api" "github.com/go-telegram-bot-api/telegram-bot-api"
) )
type RouterHandler struct {} type RouterHandler struct{}
func (rh RouterHandler) Init() { func (rh RouterHandler) Init() {
r.Init() r.Init()

View File

@ -12,7 +12,7 @@ import (
"github.com/go-telegram-bot-api/telegram-bot-api" "github.com/go-telegram-bot-api/telegram-bot-api"
) )
type Router struct {} type Router struct{}
// This function will route requests to appropriative modules // This function will route requests to appropriative modules
// It will return "ok" or "fail" // It will return "ok" or "fail"

View File

@ -15,7 +15,7 @@ var (
c *appcontext.Context c *appcontext.Context
) )
type Talkers struct {} type Talkers struct{}
func New(ac *appcontext.Context) { func New(ac *appcontext.Context) {
c = ac c = ac

View File

@ -5,8 +5,8 @@ package talkers
import ( import (
// stdlib // stdlib
"strings"
"strconv" "strconv"
"strings"
// 3rd party // 3rd party
"github.com/go-telegram-bot-api/telegram-bot-api" "github.com/go-telegram-bot-api/telegram-bot-api"
// local // local
@ -19,24 +19,24 @@ func (t *Talkers) pokememesListing(update tgbotapi.Update, page int, pokememes_f
message := "*Известные боту покемемы*\n" message := "*Известные боту покемемы*\n"
message += "Список отсортирован по грейду и алфавиту.\n" message += "Список отсортирован по грейду и алфавиту.\n"
message += "Покедекс: " + strconv.Itoa(len(pokememes_full)) + " / 206\n" message += "Покедекс: " + strconv.Itoa(len(pokememes_full)) + " / 206\n"
message += "Отображаем покемемов с " + strconv.Itoa(((page - 1)*50)+1) + " по " + strconv.Itoa(page*50) + "\n" message += "Отображаем покемемов с " + strconv.Itoa(((page-1)*50)+1) + " по " + strconv.Itoa(page*50) + "\n"
if len(pokememes_full) > page*50 { if len(pokememes_full) > page*50 {
message += "Переход на следующую страницу: /pokedeks" + strconv.Itoa(page + 1) message += "Переход на следующую страницу: /pokedeks" + strconv.Itoa(page+1)
} }
if page > 1 { if page > 1 {
message += "\nПереход на предыдущую страницу: /pokedeks" + strconv.Itoa(page - 1) message += "\nПереход на предыдущую страницу: /pokedeks" + strconv.Itoa(page-1)
} }
message += "\n\n" message += "\n\n"
for i := range(pokememes_full) { for i := range pokememes_full {
if (i + 1 > 50*(page - 1)) && (i + 1 < (50*page) + 1) { if (i+1 > 50*(page-1)) && (i+1 < (50*page)+1) {
pk := pokememes_full[i].Pokememe pk := pokememes_full[i].Pokememe
pk_e := pokememes_full[i].Elements pk_e := pokememes_full[i].Elements
message += strconv.Itoa(i + 1) + ". " + strconv.Itoa(pk.Grade) message += strconv.Itoa(i+1) + ". " + strconv.Itoa(pk.Grade)
message += "⃣ *" + pk.Name message += "⃣ *" + pk.Name
message += "* (" + c.Parsers.ReturnPoints(pk.HP) + "-" + c.Parsers.ReturnPoints(pk.MP) + ") ⚔️ *" message += "* (" + c.Parsers.ReturnPoints(pk.HP) + "-" + c.Parsers.ReturnPoints(pk.MP) + ") ⚔️ *"
message += c.Parsers.ReturnPoints(pk.Attack) + "* \\[" message += c.Parsers.ReturnPoints(pk.Attack) + "* \\["
for j := range(pk_e) { for j := range pk_e {
message += pk_e[j].Symbol message += pk_e[j].Symbol
} }
message += "] " + c.Parsers.ReturnPoints(pk.Price) + "$ /pk" + strconv.Itoa(pk.Id) 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 := strconv.Itoa(pk.Grade) + "⃣ *" + pk.Name + "*\n"
message += pk.Description + "\n\n" message += pk.Description + "\n\n"
message += "Элементы:" message += "Элементы:"
for i := range(pokememe.Elements) { for i := range pokememe.Elements {
message += " " + pokememe.Elements[i].Symbol message += " " + pokememe.Elements[i].Symbol
} }
message += "\n⚔ Атака: *" + c.Parsers.ReturnPoints(pk.Attack) message += "\n⚔ Атака: *" + c.Parsers.ReturnPoints(pk.Attack)
message += "*\n❤ HP: *" + c.Parsers.ReturnPoints(pk.HP) message += "*\n❤ HP: *" + c.Parsers.ReturnPoints(pk.HP)
message += "*\n💙 MP: *" + c.Parsers.ReturnPoints(pk.MP) 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) + "* _(сопротивляемость покемема к поимке)_" message += "*\n🛡Защита: *" + c.Parsers.ReturnPoints(pk.Defence) + "* _(сопротивляемость покемема к поимке)_"
} else { } else {
message += "*" message += "*"
@ -99,7 +99,7 @@ func (t *Talkers) PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Play
message += "Нельзя" message += "Нельзя"
} }
message += "*\nОбитает:" message += "*\nОбитает:"
for i := range(pokememe.Locations) { for i := range pokememe.Locations {
message += " *" + pokememe.Locations[i].Name + "*" message += " *" + pokememe.Locations[i].Name + "*"
if (i + 1) < len(pokememe.Locations) { if (i + 1) < len(pokememe.Locations) {
message += "," message += ","
@ -107,9 +107,9 @@ func (t *Talkers) PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Play
} }
if calculate_possibilites { if calculate_possibilites {
if (pk.Grade < profile_raw.Level_id + 2) && (pk.Grade > profile_raw.Level_id - 3) { if (pk.Grade < profile_raw.Level_id+2) && (pk.Grade > profile_raw.Level_id-3) {
message += "\nВероятность поимки:" 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) percentile, pokeballs := c.Getters.PossibilityRequiredPokeballs(pokememe.Locations[i].Id, pk.Grade, profile_raw.Level_id)
message += "\n" + pokememe.Locations[i].Name + " " message += "\n" + pokememe.Locations[i].Name + " "
message += strconv.FormatFloat(percentile, 'f', 2, 64) + "% или " message += strconv.FormatFloat(percentile, 'f', 2, 64) + "% или "
@ -122,9 +122,9 @@ func (t *Talkers) PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Play
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
keyboard := tgbotapi.InlineKeyboardMarkup{} keyboard := tgbotapi.InlineKeyboardMarkup{}
for i := range(pokememe.Locations) { for i := range pokememe.Locations {
var row []tgbotapi.InlineKeyboardButton var row []tgbotapi.InlineKeyboardButton
btn := tgbotapi.NewInlineKeyboardButtonSwitch(pokememe.Locations[i].Symbol + pokememe.Locations[i].Name, pokememe.Locations[i].Symbol + pokememe.Locations[i].Name) btn := tgbotapi.NewInlineKeyboardButtonSwitch(pokememe.Locations[i].Symbol+pokememe.Locations[i].Name, pokememe.Locations[i].Symbol+pokememe.Locations[i].Name)
row = append(row, btn) row = append(row, btn)
keyboard.InlineKeyboard = append(keyboard.InlineKeyboard, row) keyboard.InlineKeyboard = append(keyboard.InlineKeyboard, row)
} }

View File

@ -48,8 +48,8 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, player_raw dbmapping.Pl
} }
attack_pm := 0 attack_pm := 0
for i := range(p_pk) { for i := range p_pk {
for j := range(pokememes) { for j := range pokememes {
if p_pk[i].Pokememe_id == pokememes[j].Id { if p_pk[i].Pokememe_id == pokememes[j].Id {
single_attack := float64(pokememes[j].Attack) single_attack := float64(pokememes[j].Attack)
single_attack = single_attack * float64(p_pk[i].Pokememe_lvl) 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 := "*Профиль игрока "
message += profile_raw.Nickname + "* (@" + profile_raw.TelegramNickname + ")\n" message += profile_raw.Nickname + "* (@" + profile_raw.TelegramNickname + ")\n"
message += "\nЛига: " + league.Symbol + league.Name message += "\nЛига: " + league.Symbol + league.Name
@ -78,8 +77,8 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, player_raw dbmapping.Pl
} }
message += "\n🐱Покемемы:" message += "\n🐱Покемемы:"
for i := range(p_pk) { for i := range p_pk {
for j := range(pokememes) { for j := range pokememes {
if p_pk[i].Pokememe_id == pokememes[j].Id { if p_pk[i].Pokememe_id == pokememes[j].Id {
single_attack := float64(pokememes[j].Attack) single_attack := float64(pokememes[j].Attack)
single_attack = single_attack * float64(p_pk[i].Pokememe_lvl) single_attack = single_attack * float64(p_pk[i].Pokememe_lvl)

View File

@ -21,7 +21,7 @@ func (t *Talkers) BestPokememesList(update tgbotapi.Update, player_raw dbmapping
} }
message := "*Лучшие покемемы для ловли*\n\n" message := "*Лучшие покемемы для ловли*\n\n"
for i := range(pokememes) { for i := range pokememes {
pk := pokememes[i].Pokememe pk := pokememes[i].Pokememe
pk_l := pokememes[i].Locations pk_l := pokememes[i].Locations
pk_e := pokememes[i].Elements pk_e := pokememes[i].Elements
@ -29,20 +29,20 @@ func (t *Talkers) BestPokememesList(update tgbotapi.Update, player_raw dbmapping
message += pk.Name + " (⚔" message += pk.Name + " (⚔"
message += c.Parsers.ReturnPoints(pk.Attack) message += c.Parsers.ReturnPoints(pk.Attack)
message += ", 🛡" + c.Parsers.ReturnPoints(pk.Defence) + ")" message += ", 🛡" + c.Parsers.ReturnPoints(pk.Defence) + ")"
for i := range(pk_e) { for i := range pk_e {
message += pk_e[i].Symbol message += pk_e[i].Symbol
} }
message += " /pk" + strconv.Itoa(pk.Id) + "\n" message += " /pk" + strconv.Itoa(pk.Id) + "\n"
message += "Локации: " message += "Локации: "
for i := range(pk_l) { for i := range pk_l {
message += pk_l[i].Symbol + pk_l[i].Name message += pk_l[i].Symbol + pk_l[i].Name
if i + 1 < len(pk_l) { if i+1 < len(pk_l) {
message += ", " message += ", "
} }
} }
message += "\nКупить: " message += "\nКупить: "
if pk.Purchaseable { if pk.Purchaseable {
message += "💲" + c.Parsers.ReturnPoints(pk.Price * 3) message += "💲" + c.Parsers.ReturnPoints(pk.Price*3)
} else { } else {
message += "Нельзя" message += "Нельзя"
} }