All code formatted with gofmt
This commit is contained in:
parent
df58e25adc
commit
6f374e560e
@ -6,9 +6,9 @@ package main
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// 3rd-party
|
||||
// 3rd-party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
// local
|
||||
"./lib/appcontext"
|
||||
"./lib/getters"
|
||||
"./lib/migrations"
|
||||
@ -44,6 +44,6 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
c.Router.RouteRequest(update)
|
||||
c.Router.RouteRequest(update)
|
||||
}
|
||||
}
|
||||
|
@ -4,35 +4,35 @@
|
||||
package appcontext
|
||||
|
||||
import (
|
||||
// 3rd-party
|
||||
"github.com/jmoiron/sqlx"
|
||||
// 3rd-party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../config"
|
||||
"../connections"
|
||||
"github.com/jmoiron/sqlx"
|
||||
// local
|
||||
"../config"
|
||||
"../connections"
|
||||
// interfaces
|
||||
"../getters/gettersinterface"
|
||||
"../migrations/migrationsinterface"
|
||||
"../parsers/parsersinterface"
|
||||
"../router/routerinterface"
|
||||
"../talkers/talkersinterface"
|
||||
"../getters/gettersinterface"
|
||||
"../migrations/migrationsinterface"
|
||||
"../parsers/parsersinterface"
|
||||
"../router/routerinterface"
|
||||
"../talkers/talkersinterface"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
Cfg *config.Config
|
||||
Bot *tgbotapi.BotAPI
|
||||
Migrations migrationsinterface.MigrationsInterface
|
||||
Router routerinterface.RouterInterface
|
||||
Parsers parsersinterface.ParsersInterface
|
||||
Db *sqlx.DB
|
||||
Talkers talkersinterface.TalkersInterface
|
||||
Getters gettersinterface.GettersInterface
|
||||
Cfg *config.Config
|
||||
Bot *tgbotapi.BotAPI
|
||||
Migrations migrationsinterface.MigrationsInterface
|
||||
Router routerinterface.RouterInterface
|
||||
Parsers parsersinterface.ParsersInterface
|
||||
Db *sqlx.DB
|
||||
Talkers talkersinterface.TalkersInterface
|
||||
Getters gettersinterface.GettersInterface
|
||||
}
|
||||
|
||||
func (c *Context) Init() {
|
||||
c.Cfg = config.New()
|
||||
c.Cfg.Init()
|
||||
c.Bot = connections.BotInit(c.Cfg)
|
||||
c.Cfg = config.New()
|
||||
c.Cfg.Init()
|
||||
c.Bot = connections.BotInit(c.Cfg)
|
||||
c.Db = connections.DBInit(c.Cfg)
|
||||
}
|
||||
|
||||
@ -42,23 +42,23 @@ func (c *Context) RegisterRouterInterface(ri routerinterface.RouterInterface) {
|
||||
}
|
||||
|
||||
func (c *Context) RegisterMigrationsInterface(mi migrationsinterface.MigrationsInterface) {
|
||||
c.Migrations = mi
|
||||
c.Migrations.Init()
|
||||
c.Migrations = mi
|
||||
c.Migrations.Init()
|
||||
}
|
||||
|
||||
func (c *Context) RegisterParsersInterface(pi parsersinterface.ParsersInterface) {
|
||||
c.Parsers = pi
|
||||
c.Parsers = pi
|
||||
}
|
||||
|
||||
func (c *Context) RegisterTalkersInterface(ti talkersinterface.TalkersInterface) {
|
||||
c.Talkers = ti
|
||||
c.Talkers = ti
|
||||
}
|
||||
|
||||
func (c *Context) RegisterGettersInterface(gi gettersinterface.GettersInterface) {
|
||||
c.Getters = gi
|
||||
c.Getters = gi
|
||||
}
|
||||
|
||||
func (c *Context) RunDatabaseMigrations() {
|
||||
c.Migrations.SetDialect("mysql")
|
||||
c.Migrations.Migrate()
|
||||
c.Migrations.SetDialect("mysql")
|
||||
c.Migrations.Migrate()
|
||||
}
|
||||
|
@ -4,10 +4,10 @@
|
||||
package appcontext
|
||||
|
||||
var (
|
||||
a *Context
|
||||
a *Context
|
||||
)
|
||||
|
||||
func New() *Context {
|
||||
c := &Context{}
|
||||
return c
|
||||
c := &Context{}
|
||||
return c
|
||||
}
|
||||
|
@ -4,47 +4,47 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
// 3rd-party
|
||||
"gopkg.in/yaml.v2"
|
||||
// stdlib
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
// 3rd-party
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const VERSION = "0.29"
|
||||
|
||||
type DatabaseConnection struct {
|
||||
Host string `yaml:"host"`
|
||||
Port string `yaml:"port"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
Database string `yaml:"database"`
|
||||
Host string `yaml:"host"`
|
||||
Port string `yaml:"port"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
Database string `yaml:"database"`
|
||||
}
|
||||
|
||||
type TelegramConnection struct {
|
||||
APIToken string `yaml:"api_token"`
|
||||
APIToken string `yaml:"api_token"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Telegram TelegramConnection `yaml:"telegram_connection"`
|
||||
Database DatabaseConnection `yaml:"database_connection"`
|
||||
Telegram TelegramConnection `yaml:"telegram_connection"`
|
||||
Database DatabaseConnection `yaml:"database_connection"`
|
||||
}
|
||||
|
||||
func (c *Config) Init() {
|
||||
fname, _ := filepath.Abs("./config.yml")
|
||||
yamlFile, yerr := ioutil.ReadFile(fname)
|
||||
if yerr != nil {
|
||||
log.Fatal("Can't read config file")
|
||||
}
|
||||
fname, _ := filepath.Abs("./config.yml")
|
||||
yamlFile, yerr := ioutil.ReadFile(fname)
|
||||
if yerr != nil {
|
||||
log.Fatal("Can't read config file")
|
||||
}
|
||||
|
||||
yperr := yaml.Unmarshal(yamlFile, c)
|
||||
if yperr != nil {
|
||||
log.Fatal("Can't parse config file")
|
||||
}
|
||||
yperr := yaml.Unmarshal(yamlFile, c)
|
||||
if yperr != nil {
|
||||
log.Fatal("Can't parse config file")
|
||||
}
|
||||
}
|
||||
|
||||
func New() *Config {
|
||||
c := &Config{}
|
||||
return c
|
||||
c := &Config{}
|
||||
return c
|
||||
}
|
||||
|
@ -4,35 +4,35 @@
|
||||
package connections
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// 3rd-party
|
||||
// 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"
|
||||
"github.com/jmoiron/sqlx"
|
||||
// local
|
||||
"../config"
|
||||
)
|
||||
|
||||
func BotInit(cfg *config.Config) *tgbotapi.BotAPI {
|
||||
bot, err := tgbotapi.NewBotAPI(cfg.Telegram.APIToken)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
bot, err := tgbotapi.NewBotAPI(cfg.Telegram.APIToken)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
bot.Debug = true
|
||||
bot.Debug = true
|
||||
|
||||
log.Printf("Bot version: " + config.VERSION)
|
||||
log.Printf("Authorized on account %s", bot.Self.UserName)
|
||||
log.Printf("Bot version: " + config.VERSION)
|
||||
log.Printf("Authorized on account %s", bot.Self.UserName)
|
||||
|
||||
return bot
|
||||
return bot
|
||||
}
|
||||
|
||||
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")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("Database connection established!")
|
||||
return database
|
||||
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 {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("Database connection established!")
|
||||
return database
|
||||
}
|
||||
|
@ -4,14 +4,14 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type Element struct {
|
||||
Id int `db:"id"`
|
||||
Symbol string `db:"symbol"`
|
||||
Name string `db:"name"`
|
||||
League_id int `db:"league_id"`
|
||||
Created_at *time.Time `db:"created_at"`
|
||||
Id int `db:"id"`
|
||||
Symbol string `db:"symbol"`
|
||||
Name string `db:"name"`
|
||||
League_id int `db:"league_id"`
|
||||
Created_at *time.Time `db:"created_at"`
|
||||
}
|
||||
|
@ -4,13 +4,13 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type League struct {
|
||||
Id int `db:"id"`
|
||||
Symbol string `db:"symbol"`
|
||||
Name string `db:"name"`
|
||||
Created_at *time.Time `db:"created_at"`
|
||||
Id int `db:"id"`
|
||||
Symbol string `db:"symbol"`
|
||||
Name string `db:"name"`
|
||||
Created_at *time.Time `db:"created_at"`
|
||||
}
|
||||
|
@ -4,13 +4,13 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type Level struct {
|
||||
Id int `db:"id"`
|
||||
Max_exp int `db:"max_exp"`
|
||||
Max_egg int `db:"max_egg"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
Id int `db:"id"`
|
||||
Max_exp int `db:"max_exp"`
|
||||
Max_egg int `db:"max_egg"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
}
|
||||
|
@ -4,13 +4,13 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type Location struct {
|
||||
Id int `db:"id"`
|
||||
Symbol string `db:"symbol"`
|
||||
Name string `db:"name"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
Id int `db:"id"`
|
||||
Symbol string `db:"symbol"`
|
||||
Name string `db:"name"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
}
|
||||
|
@ -4,16 +4,16 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
Id int `db:"id"`
|
||||
Telegram_id int `db:"telegram_id"`
|
||||
League_id int `db:"league_id"`
|
||||
Squad_id int `db:"squad_id"`
|
||||
Status string `db:"status"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
Updated_at time.Time `db:"updated_at"`
|
||||
Id int `db:"id"`
|
||||
Telegram_id int `db:"telegram_id"`
|
||||
League_id int `db:"league_id"`
|
||||
Squad_id int `db:"squad_id"`
|
||||
Status string `db:"status"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
Updated_at time.Time `db:"updated_at"`
|
||||
}
|
||||
|
@ -4,30 +4,30 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type Pokememe struct {
|
||||
Id int `db:"id"`
|
||||
Grade int `db:"grade"`
|
||||
Name string `db:"name"`
|
||||
Description string `db:"description"`
|
||||
Attack int `db:"attack"`
|
||||
HP int `db:"hp"`
|
||||
MP int `db:"mp"`
|
||||
Defence int `db:"defence"`
|
||||
Price int `db:"price"`
|
||||
Purchaseable bool `db:"purchaseable"`
|
||||
Image_url string `db:"image_url"`
|
||||
Player_id int `db:"player_id"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
Id int `db:"id"`
|
||||
Grade int `db:"grade"`
|
||||
Name string `db:"name"`
|
||||
Description string `db:"description"`
|
||||
Attack int `db:"attack"`
|
||||
HP int `db:"hp"`
|
||||
MP int `db:"mp"`
|
||||
Defence int `db:"defence"`
|
||||
Price int `db:"price"`
|
||||
Purchaseable bool `db:"purchaseable"`
|
||||
Image_url string `db:"image_url"`
|
||||
Player_id int `db:"player_id"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
}
|
||||
|
||||
// Type for handling pokememe with all informations about locations and elements
|
||||
|
||||
type PokememeFull struct {
|
||||
Pokememe Pokememe
|
||||
Locations []Location
|
||||
Elements []Element
|
||||
Pokememe Pokememe
|
||||
Locations []Location
|
||||
Elements []Element
|
||||
}
|
||||
|
@ -4,13 +4,13 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type PokememeElement struct {
|
||||
Id int `db:"id"`
|
||||
Pokememe_id int `db:"pokememe_id"`
|
||||
Element_id int `db:"element_id"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
Id int `db:"id"`
|
||||
Pokememe_id int `db:"pokememe_id"`
|
||||
Element_id int `db:"element_id"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
}
|
||||
|
@ -4,13 +4,13 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type PokememeLocation struct {
|
||||
Id int `db:"id"`
|
||||
Pokememe_id int `db:"pokememe_id"`
|
||||
Location_id int `db:"location_id"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
Id int `db:"id"`
|
||||
Pokememe_id int `db:"pokememe_id"`
|
||||
Location_id int `db:"location_id"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
}
|
||||
|
@ -4,22 +4,22 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type Profile struct {
|
||||
Id int `db:"id"`
|
||||
Player_id int `db:"player_id"`
|
||||
Nickname string `db:"nickname"`
|
||||
TelegramNickname string `db:"telegram_nickname"`
|
||||
Level_id int `db:"level_id"`
|
||||
Pokeballs int `db:"pokeballs"`
|
||||
Wealth int `db:"wealth"`
|
||||
Exp int `db:"exp"`
|
||||
Egg_exp int `db:"egg_exp"`
|
||||
Power int `db:"power"`
|
||||
Weapon_id int `db:"weapon_id"`
|
||||
Crystalls int `db:"crystalls"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
Id int `db:"id"`
|
||||
Player_id int `db:"player_id"`
|
||||
Nickname string `db:"nickname"`
|
||||
TelegramNickname string `db:"telegram_nickname"`
|
||||
Level_id int `db:"level_id"`
|
||||
Pokeballs int `db:"pokeballs"`
|
||||
Wealth int `db:"wealth"`
|
||||
Exp int `db:"exp"`
|
||||
Egg_exp int `db:"egg_exp"`
|
||||
Power int `db:"power"`
|
||||
Weapon_id int `db:"weapon_id"`
|
||||
Crystalls int `db:"crystalls"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
}
|
||||
|
@ -4,15 +4,15 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type ProfilePokememe struct {
|
||||
Id int `db:"id"`
|
||||
Profile_id int `db:"profile_id"`
|
||||
Pokememe_id int `db:"pokememe_id"`
|
||||
Pokememe_lvl int `db:"pokememe_lvl"`
|
||||
Pokememe_rarity string `db:"pokememe_rarity"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
Id int `db:"id"`
|
||||
Profile_id int `db:"profile_id"`
|
||||
Pokememe_id int `db:"pokememe_id"`
|
||||
Pokememe_lvl int `db:"pokememe_lvl"`
|
||||
Pokememe_rarity string `db:"pokememe_rarity"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
}
|
||||
|
@ -4,14 +4,14 @@
|
||||
package dbmapping
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"time"
|
||||
// stdlib
|
||||
"time"
|
||||
)
|
||||
|
||||
type Weapon struct {
|
||||
Id int `db:"id"`
|
||||
Name string `db:"name"`
|
||||
Power int `db:"power"`
|
||||
Price int `db:"price"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
Id int `db:"id"`
|
||||
Name string `db:"name"`
|
||||
Power int `db:"power"`
|
||||
Price int `db:"price"`
|
||||
Created_at time.Time `db:"created_at"`
|
||||
}
|
||||
|
@ -4,25 +4,25 @@
|
||||
package getters
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../appcontext"
|
||||
"../getters/gettersinterface"
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../appcontext"
|
||||
"../getters/gettersinterface"
|
||||
)
|
||||
|
||||
var (
|
||||
c *appcontext.Context
|
||||
c *appcontext.Context
|
||||
)
|
||||
|
||||
type Getters struct {}
|
||||
type Getters struct{}
|
||||
|
||||
func New(ac *appcontext.Context) {
|
||||
c = ac
|
||||
g := &Getters{}
|
||||
c.RegisterGettersInterface(gettersinterface.GettersInterface(g))
|
||||
c = ac
|
||||
g := &Getters{}
|
||||
c.RegisterGettersInterface(gettersinterface.GettersInterface(g))
|
||||
}
|
||||
|
||||
func (g *Getters) Init() {
|
||||
log.Printf("Initializing getters...")
|
||||
log.Printf("Initializing getters...")
|
||||
}
|
||||
|
@ -4,21 +4,21 @@
|
||||
package gettersinterface
|
||||
|
||||
import (
|
||||
// local
|
||||
"../../dbmapping"
|
||||
// local
|
||||
"../../dbmapping"
|
||||
)
|
||||
|
||||
type GettersInterface interface {
|
||||
Init()
|
||||
// Player
|
||||
GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool)
|
||||
GetPlayerByID(player_id int) (dbmapping.Player, bool)
|
||||
// Profile
|
||||
GetProfile(player_id int) (dbmapping.Profile, bool)
|
||||
// Pokememes
|
||||
GetPokememes() ([]dbmapping.PokememeFull, bool)
|
||||
GetBestPokememes(player_id int) ([]dbmapping.PokememeFull, bool)
|
||||
GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool)
|
||||
// Possibilities
|
||||
PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int)
|
||||
Init()
|
||||
// Player
|
||||
GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool)
|
||||
GetPlayerByID(player_id int) (dbmapping.Player, bool)
|
||||
// Profile
|
||||
GetProfile(player_id int) (dbmapping.Profile, bool)
|
||||
// Pokememes
|
||||
GetPokememes() ([]dbmapping.PokememeFull, bool)
|
||||
GetBestPokememes(player_id int) ([]dbmapping.PokememeFull, bool)
|
||||
GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool)
|
||||
// Possibilities
|
||||
PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int)
|
||||
}
|
||||
|
@ -4,46 +4,46 @@
|
||||
package getters
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"time"
|
||||
// local
|
||||
"../dbmapping"
|
||||
// stdlib
|
||||
"log"
|
||||
"time"
|
||||
// local
|
||||
"../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
|
||||
}
|
||||
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
|
||||
return player_raw, true
|
||||
}
|
||||
|
||||
func (g *Getters) GetOrCreatePlayer(telegram_id int) (dbmapping.Player, bool) {
|
||||
player_raw := dbmapping.Player{}
|
||||
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id=?"), telegram_id)
|
||||
if err != nil {
|
||||
log.Printf("Message user not found in database.")
|
||||
log.Printf(err.Error())
|
||||
player_raw := dbmapping.Player{}
|
||||
err := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id=?"), telegram_id)
|
||||
if err != nil {
|
||||
log.Printf("Message user not found in database.")
|
||||
log.Printf(err.Error())
|
||||
|
||||
// Create "nobody" user
|
||||
player_raw.Telegram_id = telegram_id
|
||||
player_raw.League_id = 0
|
||||
player_raw.Squad_id = 0
|
||||
player_raw.Status = "nobody"
|
||||
player_raw.Created_at = time.Now().UTC()
|
||||
player_raw.Updated_at = time.Now().UTC()
|
||||
_, err = c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :squad_id, :status, :created_at, :updated_at)", &player_raw)
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
return player_raw, false
|
||||
}
|
||||
} else {
|
||||
log.Printf("Message user found in database.")
|
||||
}
|
||||
// Create "nobody" user
|
||||
player_raw.Telegram_id = telegram_id
|
||||
player_raw.League_id = 0
|
||||
player_raw.Squad_id = 0
|
||||
player_raw.Status = "nobody"
|
||||
player_raw.Created_at = time.Now().UTC()
|
||||
player_raw.Updated_at = time.Now().UTC()
|
||||
_, err = c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :squad_id, :status, :created_at, :updated_at)", &player_raw)
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
return player_raw, false
|
||||
}
|
||||
} else {
|
||||
log.Printf("Message user found in database.")
|
||||
}
|
||||
|
||||
return player_raw, true
|
||||
return player_raw, true
|
||||
}
|
||||
|
@ -4,178 +4,178 @@
|
||||
package getters
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"strconv"
|
||||
// local
|
||||
"../dbmapping"
|
||||
// stdlib
|
||||
"log"
|
||||
"strconv"
|
||||
// local
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
// Internal functions
|
||||
|
||||
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");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
locations := []dbmapping.Location{}
|
||||
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");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_locations := []dbmapping.PokememeLocation{}
|
||||
err = c.Db.Select(&pokememes_locations, "SELECT * FROM pokememes_locations");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_full := []dbmapping.PokememeFull{}
|
||||
elements := []dbmapping.Element{}
|
||||
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")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
pokememes_elements := []dbmapping.PokememeElement{}
|
||||
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")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememes_full, false
|
||||
}
|
||||
|
||||
for i := range(pokememes) {
|
||||
full_pokememe := dbmapping.PokememeFull{}
|
||||
elements_listed := []dbmapping.Element{}
|
||||
locations_listed := []dbmapping.Location{}
|
||||
for i := range pokememes {
|
||||
full_pokememe := dbmapping.PokememeFull{}
|
||||
elements_listed := []dbmapping.Element{}
|
||||
locations_listed := []dbmapping.Location{}
|
||||
|
||||
for j := range(pokememes_locations) {
|
||||
if pokememes_locations[j].Pokememe_id == pokememes[i].Id {
|
||||
for l := range(locations) {
|
||||
if pokememes_locations[j].Location_id == locations[l].Id {
|
||||
locations_listed = append(locations_listed, locations[l])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for j := range pokememes_locations {
|
||||
if pokememes_locations[j].Pokememe_id == pokememes[i].Id {
|
||||
for l := range locations {
|
||||
if pokememes_locations[j].Location_id == locations[l].Id {
|
||||
locations_listed = append(locations_listed, locations[l])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k := range(pokememes_elements) {
|
||||
if pokememes_elements[k].Pokememe_id == pokememes[i].Id {
|
||||
for e := range(elements) {
|
||||
if pokememes_elements[k].Element_id == elements[e].Id {
|
||||
elements_listed = append(elements_listed, elements[e])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for k := range pokememes_elements {
|
||||
if pokememes_elements[k].Pokememe_id == pokememes[i].Id {
|
||||
for e := range elements {
|
||||
if pokememes_elements[k].Element_id == elements[e].Id {
|
||||
elements_listed = append(elements_listed, elements[e])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
full_pokememe.Pokememe = pokememes[i]
|
||||
full_pokememe.Elements = elements_listed
|
||||
full_pokememe.Locations = locations_listed
|
||||
full_pokememe.Pokememe = pokememes[i]
|
||||
full_pokememe.Elements = elements_listed
|
||||
full_pokememe.Locations = locations_listed
|
||||
|
||||
pokememes_full = append(pokememes_full, full_pokememe)
|
||||
}
|
||||
pokememes_full = append(pokememes_full, full_pokememe)
|
||||
}
|
||||
|
||||
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 := []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
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
// 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
|
||||
pokememes_full, ok = g.formFullPokememes(pokememes)
|
||||
return pokememes_full, ok
|
||||
}
|
||||
|
||||
func (g *Getters) GetPokememeByID(pokememe_id string) (dbmapping.PokememeFull, bool) {
|
||||
pokememe_full := dbmapping.PokememeFull{}
|
||||
pokememe := dbmapping.Pokememe{}
|
||||
err := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE id=?"), pokememe_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
elements := []dbmapping.Element{}
|
||||
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");
|
||||
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) + "'");
|
||||
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) + "'");
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
pokememe_full := dbmapping.PokememeFull{}
|
||||
pokememe := dbmapping.Pokememe{}
|
||||
err := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE id=?"), pokememe_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
elements := []dbmapping.Element{}
|
||||
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")
|
||||
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)+"'")
|
||||
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)+"'")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return pokememe_full, false
|
||||
}
|
||||
|
||||
elements_listed := []dbmapping.Element{}
|
||||
locations_listed := []dbmapping.Location{}
|
||||
elements_listed := []dbmapping.Element{}
|
||||
locations_listed := []dbmapping.Location{}
|
||||
|
||||
for j := range(pokememes_locations) {
|
||||
if pokememes_locations[j].Pokememe_id == pokememe.Id {
|
||||
for l := range(locations) {
|
||||
if pokememes_locations[j].Location_id == locations[l].Id {
|
||||
locations_listed = append(locations_listed, locations[l])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for j := range pokememes_locations {
|
||||
if pokememes_locations[j].Pokememe_id == pokememe.Id {
|
||||
for l := range locations {
|
||||
if pokememes_locations[j].Location_id == locations[l].Id {
|
||||
locations_listed = append(locations_listed, locations[l])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k := range(pokememes_elements) {
|
||||
if pokememes_elements[k].Pokememe_id == pokememe.Id {
|
||||
for e := range(elements) {
|
||||
if pokememes_elements[k].Element_id == elements[e].Id {
|
||||
elements_listed = append(elements_listed, elements[e])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for k := range pokememes_elements {
|
||||
if pokememes_elements[k].Pokememe_id == pokememe.Id {
|
||||
for e := range elements {
|
||||
if pokememes_elements[k].Element_id == elements[e].Id {
|
||||
elements_listed = append(elements_listed, elements[e])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pokememe_full.Pokememe = pokememe
|
||||
pokememe_full.Elements = elements_listed
|
||||
pokememe_full.Locations = locations_listed
|
||||
pokememe_full.Pokememe = pokememe
|
||||
pokememe_full.Elements = elements_listed
|
||||
pokememe_full.Locations = locations_listed
|
||||
|
||||
return pokememe_full, true
|
||||
return pokememe_full, true
|
||||
}
|
||||
|
@ -4,76 +4,76 @@
|
||||
package getters
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// stdlib
|
||||
"log"
|
||||
)
|
||||
|
||||
func (g *Getters) PossibilityRequiredPokeballs(location int, grade int, lvl int) (float64, int) {
|
||||
var base_possibility float64 = 0.00
|
||||
var required_pokeballs int = 0
|
||||
var percentile = 0.00
|
||||
var base_possibility float64 = 0.00
|
||||
var required_pokeballs int = 0
|
||||
var percentile = 0.00
|
||||
|
||||
if lvl > 3 {
|
||||
switch {
|
||||
case grade == (lvl + 1):
|
||||
base_possibility = 0.05
|
||||
case grade == lvl:
|
||||
base_possibility = 0.5
|
||||
case grade == (lvl - 1):
|
||||
base_possibility = 0.3
|
||||
case grade == (lvl - 2):
|
||||
base_possibility = 0.1
|
||||
case grade == (lvl - 3):
|
||||
base_possibility = 0.05
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 3 {
|
||||
switch grade {
|
||||
case 4:
|
||||
base_possibility = 0.05
|
||||
case 3:
|
||||
base_possibility = 0.5
|
||||
case 2:
|
||||
base_possibility = 0.3
|
||||
case 1:
|
||||
base_possibility = 0.15
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 2 {
|
||||
switch grade {
|
||||
case 3:
|
||||
base_possibility = 0.05
|
||||
case 2:
|
||||
base_possibility = 0.70
|
||||
case 1:
|
||||
base_possibility = 0.25
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 1 {
|
||||
switch grade {
|
||||
case 2:
|
||||
base_possibility = 0.80
|
||||
case 1:
|
||||
base_possibility = 0.20
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
}
|
||||
if lvl > 3 {
|
||||
switch {
|
||||
case grade == (lvl + 1):
|
||||
base_possibility = 0.05
|
||||
case grade == lvl:
|
||||
base_possibility = 0.5
|
||||
case grade == (lvl - 1):
|
||||
base_possibility = 0.3
|
||||
case grade == (lvl - 2):
|
||||
base_possibility = 0.1
|
||||
case grade == (lvl - 3):
|
||||
base_possibility = 0.05
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 3 {
|
||||
switch grade {
|
||||
case 4:
|
||||
base_possibility = 0.05
|
||||
case 3:
|
||||
base_possibility = 0.5
|
||||
case 2:
|
||||
base_possibility = 0.3
|
||||
case 1:
|
||||
base_possibility = 0.15
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 2 {
|
||||
switch grade {
|
||||
case 3:
|
||||
base_possibility = 0.05
|
||||
case 2:
|
||||
base_possibility = 0.70
|
||||
case 1:
|
||||
base_possibility = 0.25
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
} else if lvl == 1 {
|
||||
switch grade {
|
||||
case 2:
|
||||
base_possibility = 0.80
|
||||
case 1:
|
||||
base_possibility = 0.20
|
||||
default:
|
||||
base_possibility = 0.00
|
||||
}
|
||||
}
|
||||
|
||||
var number_of_pokememes int = 0
|
||||
var number_of_pokememes int = 0
|
||||
|
||||
err := c.Db.Get(&number_of_pokememes, c.Db.Rebind("SELECT count(*) FROM pokememes p, pokememes_locations pl WHERE p.grade = ? AND pl.location_id = ? AND pl.pokememe_id = p.id;"), grade, location)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
err := c.Db.Get(&number_of_pokememes, c.Db.Rebind("SELECT count(*) FROM pokememes p, pokememes_locations pl WHERE p.grade = ? AND pl.location_id = ? AND pl.pokememe_id = p.id;"), grade, location)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
if base_possibility != 0 && number_of_pokememes != 0 {
|
||||
percentile = base_possibility * 100.0 / float64(number_of_pokememes)
|
||||
required_pokeballs = int(100.0 / percentile)
|
||||
}
|
||||
if base_possibility != 0 && number_of_pokememes != 0 {
|
||||
percentile = base_possibility * 100.0 / float64(number_of_pokememes)
|
||||
required_pokeballs = int(100.0 / percentile)
|
||||
}
|
||||
|
||||
return percentile, required_pokeballs
|
||||
return percentile, required_pokeballs
|
||||
}
|
||||
|
@ -4,19 +4,19 @@
|
||||
package getters
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../dbmapping"
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
func (g *Getters) GetProfile(player_id int) (dbmapping.Profile, bool) {
|
||||
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"), player_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return profile_raw, false
|
||||
}
|
||||
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"), player_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return profile_raw, false
|
||||
}
|
||||
|
||||
return profile_raw, true
|
||||
return profile_raw, true
|
||||
}
|
||||
|
@ -4,40 +4,40 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func UpdateLeaguesUp(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("UPDATE `leagues` SET symbol='🈸' WHERE symbol=':u7533:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `leagues` SET symbol='🈳 ' WHERE symbol=':u6e80';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `leagues` SET symbol='🈵' WHERE symbol=':u7a7a:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := tx.Exec("UPDATE `leagues` SET symbol='🈸' WHERE symbol=':u7533:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `leagues` SET symbol='🈳 ' WHERE symbol=':u6e80';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `leagues` SET symbol='🈵' WHERE symbol=':u7a7a:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateLeaguesDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("UPDATE `leagues` SET symbol=':u7533:' WHERE symbol='🈸';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `leagues` SET symbol=':u6e80' WHERE symbol='🈳 ';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `leagues` SET symbol=':u7a7a:' WHERE symbol='🈵';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := tx.Exec("UPDATE `leagues` SET symbol=':u7533:' WHERE symbol='🈸';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `leagues` SET symbol=':u6e80' WHERE symbol='🈳 ';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `leagues` SET symbol=':u7a7a:' WHERE symbol='🈵';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
@ -4,81 +4,81 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func ProfileDataAdditionsUp(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE `profiles` ADD `pokeballs` INT(11) DEFAULT 5 NOT NULL COMMENT 'Покеболы' AFTER `level_id`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := tx.Exec("ALTER TABLE `profiles` ADD `pokeballs` INT(11) DEFAULT 5 NOT NULL COMMENT 'Покеболы' AFTER `level_id`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
create_request := "CREATE TABLE `levels` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID уровня и его номер',"
|
||||
create_request += "`max_exp` int(11) NOT NULL COMMENT 'Опыт для прохождения уровня',"
|
||||
create_request += "`max_egg` int(11) NOT NULL COMMENT 'Опыт для открытия яйца',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `levels_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Уровни';"
|
||||
_, err = tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
create_request := "CREATE TABLE `levels` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID уровня и его номер',"
|
||||
create_request += "`max_exp` int(11) NOT NULL COMMENT 'Опыт для прохождения уровня',"
|
||||
create_request += "`max_egg` int(11) NOT NULL COMMENT 'Опыт для открытия яйца',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `levels_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Уровни';"
|
||||
_, err = tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Insert levels
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 200, 6, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 400, 12, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 800, 24, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 1600, 48, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 3200, 96, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 6400, 192, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 12800, 384, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 25600, 768, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 51200, 1536, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Insert levels
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 200, 6, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 400, 12, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 800, 24, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 1600, 48, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 3200, 96, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 6400, 192, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 12800, 384, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 25600, 768, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 51200, 1536, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func ProfileDataAdditionsDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE `profiles` DROP COLUMN `pokeballs`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := tx.Exec("ALTER TABLE `profiles` DROP COLUMN `pokeballs`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec("DROP TABLE `levels`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("DROP TABLE `levels`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
@ -4,33 +4,33 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func CreateProfileRelationsUp(tx *sql.Tx) error {
|
||||
create_request := "CREATE TABLE `profiles_pokememes` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID связи',"
|
||||
create_request += "`profile_id` int(11) NOT NULL COMMENT 'ID профиля',"
|
||||
create_request += "`pokememe_id` int(11) NOT NULL COMMENT 'ID покемема',"
|
||||
create_request += "`pokememe_lvl` int(11) NOT NULL COMMENT 'Уровень покемема',"
|
||||
create_request += "`pokememe_rarity` varchar(191) NOT NULL DEFAULT 'common' COMMENT 'Редкость покемема',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлено в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `profiles_pokememes_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Профили-Покемемы';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
create_request := "CREATE TABLE `profiles_pokememes` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID связи',"
|
||||
create_request += "`profile_id` int(11) NOT NULL COMMENT 'ID профиля',"
|
||||
create_request += "`pokememe_id` int(11) NOT NULL COMMENT 'ID покемема',"
|
||||
create_request += "`pokememe_lvl` int(11) NOT NULL COMMENT 'Уровень покемема',"
|
||||
create_request += "`pokememe_rarity` varchar(191) NOT NULL DEFAULT 'common' COMMENT 'Редкость покемема',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлено в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `profiles_pokememes_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Профили-Покемемы';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateProfileRelationsDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("DROP TABLE `profiles_pokememes`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
_, err := tx.Exec("DROP TABLE `profiles_pokememes`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,69 +4,69 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func CreateWeaponsAndAddWealthUp(tx *sql.Tx) error {
|
||||
create_request := "CREATE TABLE `weapons` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID оружия',"
|
||||
create_request += "`name` varchar(191) NOT NULL COMMENT 'Название оружия',"
|
||||
create_request += "`power` int(11) NOT NULL COMMENT 'Атака оружия',"
|
||||
create_request += "`price` int(11) NOT NULL COMMENT 'Цена в магазине',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлено в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `weapons_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Оружие';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
create_request := "CREATE TABLE `weapons` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID оружия',"
|
||||
create_request += "`name` varchar(191) NOT NULL COMMENT 'Название оружия',"
|
||||
create_request += "`power` int(11) NOT NULL COMMENT 'Атака оружия',"
|
||||
create_request += "`price` int(11) NOT NULL COMMENT 'Цена в магазине',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлено в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `weapons_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Оружие';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Бита', 2, 5, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Стальная бита', 10, 40, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Чугунная бита ', 200, 500, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Титановая бита', 2000, 10000, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Алмазная бита', 10000, 100000, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Криптонитовая бита', 100000, 500000, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Бита', 2, 5, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Стальная бита', 10, 40, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Чугунная бита ', 200, 500, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Титановая бита', 2000, 10000, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Алмазная бита', 10000, 100000, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Криптонитовая бита', 100000, 500000, NOW());")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec("ALTER TABLE `profiles` ADD COLUMN `wealth` INT(11) NOT NULL COMMENT 'Денег на руках' AFTER `pokeballs`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("ALTER TABLE `profiles` ADD COLUMN `wealth` INT(11) NOT NULL COMMENT 'Денег на руках' AFTER `pokeballs`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateWeaponsAndAddWealthDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE `profiles` DROP COLUMN `wealth`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := tx.Exec("ALTER TABLE `profiles` DROP COLUMN `wealth`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec("DROP TABLE `weapons`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("DROP TABLE `weapons`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
@ -4,24 +4,24 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func FixTimeElementUp(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("UPDATE `elements` SET league_id=3 WHERE symbol='⌛';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := tx.Exec("UPDATE `elements` SET league_id=3 WHERE symbol='⌛';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func FixTimeElementDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("UPDATE `elements` SET league_id=1 WHERE symbol='⌛';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := tx.Exec("UPDATE `elements` SET league_id=1 WHERE symbol='⌛';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
@ -4,15 +4,15 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
"log"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
"log"
|
||||
)
|
||||
|
||||
// First migration, added for testing purposes
|
||||
|
||||
func HelloUp(tx *sql.Tx) error {
|
||||
log.Printf("Migration framework loaded. All systems are OK.")
|
||||
log.Printf("Migration framework loaded. All systems are OK.")
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
@ -4,35 +4,35 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func CreatePlayersUp(tx *sql.Tx) error {
|
||||
create_request := "CREATE TABLE `players` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID игрока',"
|
||||
create_request += "`telegram_id` int(11) NOT NULL COMMENT 'ID в телеграме',"
|
||||
create_request += "`league_id` int(11) COMMENT 'ID лиги' DEFAULT 0,"
|
||||
create_request += "`squad_id` int(11) COMMENT 'ID отряда' DEFAULT 0,"
|
||||
create_request += "`status` varchar(191) COMMENT 'Статус в лиге' DEFAULT 'common',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||
create_request += "`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Время последнего обновления',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `players_created_at` (`created_at`),"
|
||||
create_request += "KEY `players_updated_at` (`updated_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Зарегистрированные игроки';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
create_request := "CREATE TABLE `players` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID игрока',"
|
||||
create_request += "`telegram_id` int(11) NOT NULL COMMENT 'ID в телеграме',"
|
||||
create_request += "`league_id` int(11) COMMENT 'ID лиги' DEFAULT 0,"
|
||||
create_request += "`squad_id` int(11) COMMENT 'ID отряда' DEFAULT 0,"
|
||||
create_request += "`status` varchar(191) COMMENT 'Статус в лиге' DEFAULT 'common',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||
create_request += "`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Время последнего обновления',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `players_created_at` (`created_at`),"
|
||||
create_request += "KEY `players_updated_at` (`updated_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Зарегистрированные игроки';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreatePlayersDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("DROP TABLE `players`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
_, err := tx.Exec("DROP TABLE `players`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,39 +4,39 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func CreateProfilesUp(tx *sql.Tx) error {
|
||||
create_request := "CREATE TABLE `profiles` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID сохраненного профиля',"
|
||||
create_request += "`player_id` int(11) NOT NULL COMMENT 'ID игрока в системе',"
|
||||
create_request += "`nickname` varchar(191) NOT NULL COMMENT 'Ник игрока',"
|
||||
create_request += "`telegram_nickname` varchar(191) NOT NULL COMMENT 'Ник в Телеграме (@)',"
|
||||
create_request += "`level_id` int(11) NOT NULL COMMENT 'Уровень',"
|
||||
create_request += "`exp` int(11) NOT NULL COMMENT 'Опыт',"
|
||||
create_request += "`egg_exp` int(11) NOT NULL COMMENT 'Опыт яйца',"
|
||||
create_request += "`power` int(11) NOT NULL COMMENT 'Сила без оружия',"
|
||||
create_request += "`weapon_id` int(11) NOT NULL COMMENT 'Тип оружия',"
|
||||
create_request += "`crystalls` int(11) NOT NULL COMMENT 'Кристаллы',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `profiles_created_at` (`created_at`),"
|
||||
create_request += "KEY `profiles_nickname` (`nickname`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Профили зарегистрированных игроков';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
create_request := "CREATE TABLE `profiles` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID сохраненного профиля',"
|
||||
create_request += "`player_id` int(11) NOT NULL COMMENT 'ID игрока в системе',"
|
||||
create_request += "`nickname` varchar(191) NOT NULL COMMENT 'Ник игрока',"
|
||||
create_request += "`telegram_nickname` varchar(191) NOT NULL COMMENT 'Ник в Телеграме (@)',"
|
||||
create_request += "`level_id` int(11) NOT NULL COMMENT 'Уровень',"
|
||||
create_request += "`exp` int(11) NOT NULL COMMENT 'Опыт',"
|
||||
create_request += "`egg_exp` int(11) NOT NULL COMMENT 'Опыт яйца',"
|
||||
create_request += "`power` int(11) NOT NULL COMMENT 'Сила без оружия',"
|
||||
create_request += "`weapon_id` int(11) NOT NULL COMMENT 'Тип оружия',"
|
||||
create_request += "`crystalls` int(11) NOT NULL COMMENT 'Кристаллы',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `profiles_created_at` (`created_at`),"
|
||||
create_request += "KEY `profiles_nickname` (`nickname`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Профили зарегистрированных игроков';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateProfilesDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("DROP TABLE `profiles`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
_, err := tx.Exec("DROP TABLE `profiles`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,41 +4,41 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func CreatePokememesUp(tx *sql.Tx) error {
|
||||
create_request := "CREATE TABLE `pokememes` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID покемема',"
|
||||
create_request += "`grade` int(11) NOT NULL COMMENT 'Поколение покемема',"
|
||||
create_request += "`name` varchar(191) NOT NULL COMMENT 'Имя покемема',"
|
||||
create_request += "`description` TEXT NOT NULL COMMENT 'Описание покемема',"
|
||||
create_request += "`attack` int(11) NOT NULL COMMENT 'Атака',"
|
||||
create_request += "`hp` int(11) NOT NULL COMMENT 'Здоровье',"
|
||||
create_request += "`mp` int(11) NOT NULL COMMENT 'МР',"
|
||||
create_request += "`defence` int(11) NOT NULL COMMENT 'Защита',"
|
||||
create_request += "`price` int(11) NOT NULL COMMENT 'Стоимость',"
|
||||
create_request += "`purchaseable` bool NOT NULL DEFAULT true COMMENT 'Можно купить?',"
|
||||
create_request += "`image_url` varchar(191) NOT NULL COMMENT 'Изображение покемема',"
|
||||
create_request += "`player_id` int(11) NOT NULL COMMENT 'Кто добавил в базу',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `pokememes_created_at` (`created_at`),"
|
||||
create_request += "KEY `pokememes_player_id` (`player_id`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Покемемы';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
create_request := "CREATE TABLE `pokememes` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID покемема',"
|
||||
create_request += "`grade` int(11) NOT NULL COMMENT 'Поколение покемема',"
|
||||
create_request += "`name` varchar(191) NOT NULL COMMENT 'Имя покемема',"
|
||||
create_request += "`description` TEXT NOT NULL COMMENT 'Описание покемема',"
|
||||
create_request += "`attack` int(11) NOT NULL COMMENT 'Атака',"
|
||||
create_request += "`hp` int(11) NOT NULL COMMENT 'Здоровье',"
|
||||
create_request += "`mp` int(11) NOT NULL COMMENT 'МР',"
|
||||
create_request += "`defence` int(11) NOT NULL COMMENT 'Защита',"
|
||||
create_request += "`price` int(11) NOT NULL COMMENT 'Стоимость',"
|
||||
create_request += "`purchaseable` bool NOT NULL DEFAULT true COMMENT 'Можно купить?',"
|
||||
create_request += "`image_url` varchar(191) NOT NULL COMMENT 'Изображение покемема',"
|
||||
create_request += "`player_id` int(11) NOT NULL COMMENT 'Кто добавил в базу',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `pokememes_created_at` (`created_at`),"
|
||||
create_request += "KEY `pokememes_player_id` (`player_id`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Покемемы';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreatePokememesDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("DROP TABLE `pokememes`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
_, err := tx.Exec("DROP TABLE `pokememes`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,58 +4,58 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func CreateLocationsUp(tx *sql.Tx) error {
|
||||
create_request := "CREATE TABLE `locations` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID локации',"
|
||||
create_request += "`symbol` varchar(191) COLLATE 'utf8mb4_unicode_520_ci' NOT NULL COMMENT 'Символ локации',"
|
||||
create_request += "`name` varchar(191) NOT NULL COMMENT 'Имя локации',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлена в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `locations_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Локации';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
create_request := "CREATE TABLE `locations` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID локации',"
|
||||
create_request += "`symbol` varchar(191) COLLATE 'utf8mb4_unicode_520_ci' NOT NULL COMMENT 'Символ локации',"
|
||||
create_request += "`name` varchar(191) NOT NULL COMMENT 'Имя локации',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлена в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `locations_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Локации';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Insert locations
|
||||
_, err2 := tx.Exec("INSERT INTO `locations` VALUES(NULL, ':evergreen_tree:', 'Лес', NOW());")
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err3 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '⛰', 'Горы', NOW());")
|
||||
if err3 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err4 := tx.Exec("INSERT INTO `locations` VALUES(NULL, ':rowboat:', 'Озеро', NOW());")
|
||||
if err4 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err5 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏙:', 'Город', NOW());")
|
||||
if err5 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err6 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏛', 'Катакомбы', NOW());")
|
||||
if err6 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err7 := tx.Exec("INSERT INTO `locations` VALUES(NULL, ':church:', 'Кладбище', NOW());")
|
||||
if err7 != nil {
|
||||
return err2
|
||||
}
|
||||
// Insert locations
|
||||
_, err2 := tx.Exec("INSERT INTO `locations` VALUES(NULL, ':evergreen_tree:', 'Лес', NOW());")
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err3 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '⛰', 'Горы', NOW());")
|
||||
if err3 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err4 := tx.Exec("INSERT INTO `locations` VALUES(NULL, ':rowboat:', 'Озеро', NOW());")
|
||||
if err4 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err5 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏙:', 'Город', NOW());")
|
||||
if err5 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err6 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏛', 'Катакомбы', NOW());")
|
||||
if err6 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err7 := tx.Exec("INSERT INTO `locations` VALUES(NULL, ':church:', 'Кладбище', NOW());")
|
||||
if err7 != nil {
|
||||
return err2
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateLocationsDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("DROP TABLE `locations`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
_, err := tx.Exec("DROP TABLE `locations`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,83 +4,83 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func CreateElementsUp(tx *sql.Tx) error {
|
||||
create_request := "CREATE TABLE `elements` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID элемента',"
|
||||
create_request += "`symbol` varchar(191) COLLATE 'utf8mb4_unicode_520_ci' NOT NULL COMMENT 'Символ элемента',"
|
||||
create_request += "`name` varchar(191) NOT NULL COMMENT 'Имя элемента',"
|
||||
create_request += "`league_id` int(11) NOT NULL COMMENT 'ID родной лиги',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `elements_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Элементы';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
create_request := "CREATE TABLE `elements` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID элемента',"
|
||||
create_request += "`symbol` varchar(191) COLLATE 'utf8mb4_unicode_520_ci' NOT NULL COMMENT 'Символ элемента',"
|
||||
create_request += "`name` varchar(191) NOT NULL COMMENT 'Имя элемента',"
|
||||
create_request += "`league_id` int(11) NOT NULL COMMENT 'ID родной лиги',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `elements_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Элементы';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Insert elements
|
||||
_, err2 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '👊', 'Боевой', 1, NOW());")
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err3 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🌀', 'Летающий', 1, NOW());")
|
||||
if err3 != nil {
|
||||
return err3
|
||||
}
|
||||
_, err4 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '💀', 'Ядовитый', 1, NOW());")
|
||||
if err4 != nil {
|
||||
return err4
|
||||
}
|
||||
_, err5 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🗿', 'Каменный', 1, NOW());")
|
||||
if err5 != nil {
|
||||
return err5
|
||||
}
|
||||
_, err6 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🔥', 'Огненный', 2, NOW());")
|
||||
if err6 != nil {
|
||||
return err6
|
||||
}
|
||||
_, err7 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '⚡', 'Электрический', 2, NOW());")
|
||||
if err7 != nil {
|
||||
return err7
|
||||
}
|
||||
_, err8 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '💧', 'Водяной', 2, NOW());")
|
||||
if err8 != nil {
|
||||
return err8
|
||||
}
|
||||
_, err9 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🍀', 'Травяной', 2, NOW());")
|
||||
if err9 != nil {
|
||||
return err9
|
||||
}
|
||||
_, err10 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '💩', 'Шоколадный', 3, NOW());")
|
||||
if err10 != nil {
|
||||
return err10
|
||||
}
|
||||
_, err11 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '👁', 'Психический', 3, NOW());")
|
||||
if err11 != nil {
|
||||
return err11
|
||||
}
|
||||
_, err12 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '👿', 'Темный', 3, NOW());")
|
||||
if err12 != nil {
|
||||
return err12
|
||||
}
|
||||
_, err13 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '⌛', 'Времени', 1, NOW());")
|
||||
if err13 != nil {
|
||||
return err13
|
||||
}
|
||||
// Insert elements
|
||||
_, err2 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '👊', 'Боевой', 1, NOW());")
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err3 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🌀', 'Летающий', 1, NOW());")
|
||||
if err3 != nil {
|
||||
return err3
|
||||
}
|
||||
_, err4 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '💀', 'Ядовитый', 1, NOW());")
|
||||
if err4 != nil {
|
||||
return err4
|
||||
}
|
||||
_, err5 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🗿', 'Каменный', 1, NOW());")
|
||||
if err5 != nil {
|
||||
return err5
|
||||
}
|
||||
_, err6 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🔥', 'Огненный', 2, NOW());")
|
||||
if err6 != nil {
|
||||
return err6
|
||||
}
|
||||
_, err7 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '⚡', 'Электрический', 2, NOW());")
|
||||
if err7 != nil {
|
||||
return err7
|
||||
}
|
||||
_, err8 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '💧', 'Водяной', 2, NOW());")
|
||||
if err8 != nil {
|
||||
return err8
|
||||
}
|
||||
_, err9 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🍀', 'Травяной', 2, NOW());")
|
||||
if err9 != nil {
|
||||
return err9
|
||||
}
|
||||
_, err10 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '💩', 'Шоколадный', 3, NOW());")
|
||||
if err10 != nil {
|
||||
return err10
|
||||
}
|
||||
_, err11 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '👁', 'Психический', 3, NOW());")
|
||||
if err11 != nil {
|
||||
return err11
|
||||
}
|
||||
_, err12 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '👿', 'Темный', 3, NOW());")
|
||||
if err12 != nil {
|
||||
return err12
|
||||
}
|
||||
_, err13 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '⌛', 'Времени', 1, NOW());")
|
||||
if err13 != nil {
|
||||
return err13
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateElementsDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("DROP TABLE `elements`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
_, err := tx.Exec("DROP TABLE `elements`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,46 +4,46 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func CreateLeaguesUp(tx *sql.Tx) error {
|
||||
create_request := "CREATE TABLE `leagues` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID лиги',"
|
||||
create_request += "`symbol` varchar(191) COLLATE 'utf8mb4_unicode_520_ci' NOT NULL COMMENT 'Символ лиги',"
|
||||
create_request += "`name` varchar(191) NOT NULL COMMENT 'Имя лиги',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлена в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `leagues_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Лиги';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
create_request := "CREATE TABLE `leagues` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID лиги',"
|
||||
create_request += "`symbol` varchar(191) COLLATE 'utf8mb4_unicode_520_ci' NOT NULL COMMENT 'Символ лиги',"
|
||||
create_request += "`name` varchar(191) NOT NULL COMMENT 'Имя лиги',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлена в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `leagues_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Лиги';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Insert locations
|
||||
_, err2 := tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7533:', 'ИНСТИНКТ', NOW());")
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err3 := tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u6e80', 'ОТВАГА', NOW());")
|
||||
if err3 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err4 := tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7a7a:', 'МИСТИКА', NOW());")
|
||||
if err4 != nil {
|
||||
return err2
|
||||
}
|
||||
// Insert locations
|
||||
_, err2 := tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7533:', 'ИНСТИНКТ', NOW());")
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err3 := tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u6e80', 'ОТВАГА', NOW());")
|
||||
if err3 != nil {
|
||||
return err2
|
||||
}
|
||||
_, err4 := tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7a7a:', 'МИСТИКА', NOW());")
|
||||
if err4 != nil {
|
||||
return err2
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateLeaguesDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("DROP TABLE `leagues`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
_, err := tx.Exec("DROP TABLE `leagues`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,49 +4,49 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func CreateRelationsUp(tx *sql.Tx) error {
|
||||
create_request := "CREATE TABLE `pokememes_locations` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID связи',"
|
||||
create_request += "`pokememe_id` int(11) NOT NULL COMMENT 'ID покемема',"
|
||||
create_request += "`location_id` int(11) NOT NULL COMMENT 'ID локации',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлено в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `pokememes_locations_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Покемемы-Локации';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
create_request := "CREATE TABLE `pokememes_locations` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID связи',"
|
||||
create_request += "`pokememe_id` int(11) NOT NULL COMMENT 'ID покемема',"
|
||||
create_request += "`location_id` int(11) NOT NULL COMMENT 'ID локации',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлено в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `pokememes_locations_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Покемемы-Локации';"
|
||||
_, err := tx.Exec(create_request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
create_request = "CREATE TABLE `pokememes_elements` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID связи',"
|
||||
create_request += "`pokememe_id` int(11) NOT NULL COMMENT 'ID покемема',"
|
||||
create_request += "`element_id` int(11) NOT NULL COMMENT 'ID элемента',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлено в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `pokememes_elements_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Покемемы-Элементы';"
|
||||
_, err2 := tx.Exec(create_request)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
return nil
|
||||
create_request = "CREATE TABLE `pokememes_elements` ("
|
||||
create_request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID связи',"
|
||||
create_request += "`pokememe_id` int(11) NOT NULL COMMENT 'ID покемема',"
|
||||
create_request += "`element_id` int(11) NOT NULL COMMENT 'ID элемента',"
|
||||
create_request += "`created_at` datetime NOT NULL COMMENT 'Добавлено в базу',"
|
||||
create_request += "PRIMARY KEY (`id`),"
|
||||
create_request += "UNIQUE KEY `id` (`id`),"
|
||||
create_request += "KEY `pokememes_elements_created_at` (`created_at`)"
|
||||
create_request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Покемемы-Элементы';"
|
||||
_, err2 := tx.Exec(create_request)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateRelationsDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("DROP TABLE `pokememes_locations`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err2 := tx.Exec("DROP TABLE `pokememes_elements`;")
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
return nil
|
||||
_, err := tx.Exec("DROP TABLE `pokememes_locations`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err2 := tx.Exec("DROP TABLE `pokememes_elements`;")
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -4,40 +4,40 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func UpdateLocationsUp(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("UPDATE `locations` SET symbol='⛪' WHERE symbol=':church:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol='🌲' WHERE symbol=':evergreen_tree:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol='🚣' WHERE symbol=':rowboat:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := tx.Exec("UPDATE `locations` SET symbol='⛪' WHERE symbol=':church:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol='🌲' WHERE symbol=':evergreen_tree:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol='🚣' WHERE symbol=':rowboat:';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateLocationsDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("UPDATE `locations` SET symbol=':church:' WHERE symbol='⛪'';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol=':evergreen_tree:' WHERE symbol='🌲';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol=':rowboat:' WHERE symbol='🚣';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := tx.Exec("UPDATE `locations` SET symbol=':church:' WHERE symbol='⛪'';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol=':evergreen_tree:' WHERE symbol='🌲';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("UPDATE `locations` SET symbol=':rowboat:' WHERE symbol='🚣';")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
@ -4,17 +4,17 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// local
|
||||
"../appcontext"
|
||||
"../migrations/migrationsinterface"
|
||||
// local
|
||||
"../appcontext"
|
||||
"../migrations/migrationsinterface"
|
||||
)
|
||||
|
||||
var (
|
||||
c *appcontext.Context
|
||||
c *appcontext.Context
|
||||
)
|
||||
|
||||
func New(ac *appcontext.Context) {
|
||||
c = ac
|
||||
m := &Migrations{}
|
||||
c.RegisterMigrationsInterface(migrationsinterface.MigrationsInterface(m))
|
||||
c = ac
|
||||
m := &Migrations{}
|
||||
c.RegisterMigrationsInterface(migrationsinterface.MigrationsInterface(m))
|
||||
}
|
||||
|
@ -4,45 +4,45 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// 3rd-party
|
||||
"github.com/pressly/goose"
|
||||
// stdlib
|
||||
"log"
|
||||
// 3rd-party
|
||||
"github.com/pressly/goose"
|
||||
)
|
||||
|
||||
type Migrations struct {}
|
||||
type Migrations struct{}
|
||||
|
||||
func (m *Migrations) Init() {
|
||||
log.Printf("Initializing migrations...")
|
||||
// All migrations are here
|
||||
goose.AddNamedMigration("1_hello.go", HelloUp, nil)
|
||||
goose.AddNamedMigration("2_create_players.go", CreatePlayersUp, CreatePlayersDown)
|
||||
goose.AddNamedMigration("3_create_profiles.go", CreateProfilesUp, CreateProfilesDown)
|
||||
goose.AddNamedMigration("4_create_pokememes.go", CreatePokememesUp, CreatePokememesDown)
|
||||
goose.AddNamedMigration("5_create_locations.go", CreateLocationsUp, CreateLocationsDown)
|
||||
goose.AddNamedMigration("6_create_elements.go", CreateElementsUp, CreateElementsDown)
|
||||
goose.AddNamedMigration("7_create_leagues.go", CreateLeaguesUp, CreateLeaguesDown)
|
||||
goose.AddNamedMigration("8_create_relations.go", CreateRelationsUp, CreateRelationsDown)
|
||||
goose.AddNamedMigration("9_update_locations.go", UpdateLocationsUp, UpdateLocationsDown)
|
||||
goose.AddNamedMigration("10_update_leagues.go", UpdateLeaguesUp, UpdateLeaguesDown)
|
||||
goose.AddNamedMigration("11_profile_data_additions.go", ProfileDataAdditionsUp, ProfileDataAdditionsDown)
|
||||
goose.AddNamedMigration("12_create_profile_relations.go", CreateProfileRelationsUp, CreateProfileRelationsDown)
|
||||
goose.AddNamedMigration("13_create_weapons_and_add_wealth.go", CreateWeaponsAndAddWealthUp, CreateWeaponsAndAddWealthDown)
|
||||
goose.AddNamedMigration("14_fix_time_element.go", FixTimeElementUp, FixTimeElementDown)
|
||||
log.Printf("Initializing migrations...")
|
||||
// All migrations are here
|
||||
goose.AddNamedMigration("1_hello.go", HelloUp, nil)
|
||||
goose.AddNamedMigration("2_create_players.go", CreatePlayersUp, CreatePlayersDown)
|
||||
goose.AddNamedMigration("3_create_profiles.go", CreateProfilesUp, CreateProfilesDown)
|
||||
goose.AddNamedMigration("4_create_pokememes.go", CreatePokememesUp, CreatePokememesDown)
|
||||
goose.AddNamedMigration("5_create_locations.go", CreateLocationsUp, CreateLocationsDown)
|
||||
goose.AddNamedMigration("6_create_elements.go", CreateElementsUp, CreateElementsDown)
|
||||
goose.AddNamedMigration("7_create_leagues.go", CreateLeaguesUp, CreateLeaguesDown)
|
||||
goose.AddNamedMigration("8_create_relations.go", CreateRelationsUp, CreateRelationsDown)
|
||||
goose.AddNamedMigration("9_update_locations.go", UpdateLocationsUp, UpdateLocationsDown)
|
||||
goose.AddNamedMigration("10_update_leagues.go", UpdateLeaguesUp, UpdateLeaguesDown)
|
||||
goose.AddNamedMigration("11_profile_data_additions.go", ProfileDataAdditionsUp, ProfileDataAdditionsDown)
|
||||
goose.AddNamedMigration("12_create_profile_relations.go", CreateProfileRelationsUp, CreateProfileRelationsDown)
|
||||
goose.AddNamedMigration("13_create_weapons_and_add_wealth.go", CreateWeaponsAndAddWealthUp, CreateWeaponsAndAddWealthDown)
|
||||
goose.AddNamedMigration("14_fix_time_element.go", FixTimeElementUp, FixTimeElementDown)
|
||||
}
|
||||
|
||||
func (m *Migrations) Migrate() error {
|
||||
log.Printf("Starting database migrations...")
|
||||
err := goose.Up(c.Db.DB, ".")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Printf("Starting database migrations...")
|
||||
err := goose.Up(c.Db.DB, ".")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Migrations) SetDialect(dialect string) error {
|
||||
return goose.SetDialect(dialect)
|
||||
return goose.SetDialect(dialect)
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
package migrationsinterface
|
||||
|
||||
type MigrationsInterface interface {
|
||||
Init()
|
||||
Migrate() error
|
||||
SetDialect(dialect string) error
|
||||
Init()
|
||||
Migrate() error
|
||||
SetDialect(dialect string) error
|
||||
}
|
||||
|
@ -4,19 +4,19 @@
|
||||
package parsers
|
||||
|
||||
import (
|
||||
// local
|
||||
"../appcontext"
|
||||
"../parsers/parsersinterface"
|
||||
// local
|
||||
"../appcontext"
|
||||
"../parsers/parsersinterface"
|
||||
)
|
||||
|
||||
var (
|
||||
c *appcontext.Context
|
||||
c *appcontext.Context
|
||||
)
|
||||
|
||||
type Parsers struct {}
|
||||
type Parsers struct{}
|
||||
|
||||
func New(ac *appcontext.Context) {
|
||||
c = ac
|
||||
p := &Parsers{}
|
||||
c.RegisterParsersInterface(parsersinterface.ParsersInterface(p))
|
||||
c = ac
|
||||
p := &Parsers{}
|
||||
c.RegisterParsersInterface(parsersinterface.ParsersInterface(p))
|
||||
}
|
||||
|
@ -4,15 +4,14 @@
|
||||
package parsersinterface
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../../dbmapping"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../../dbmapping"
|
||||
)
|
||||
|
||||
|
||||
type ParsersInterface interface {
|
||||
ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
ParseProfile(update tgbotapi.Update, player_raw dbmapping.Player) string
|
||||
ReturnPoints(points int) string
|
||||
ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
ParseProfile(update tgbotapi.Update, player_raw dbmapping.Player) string
|
||||
ReturnPoints(points int) string
|
||||
}
|
||||
|
@ -4,265 +4,263 @@
|
||||
package parsers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"strconv"
|
||||
"time"
|
||||
// local
|
||||
"../dbmapping"
|
||||
// stdlib
|
||||
"log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
// local
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
// Internal functions
|
||||
|
||||
func (p *Parsers) getPoints(points_str string) int {
|
||||
value := 0
|
||||
if strings.HasSuffix(points_str, "K") {
|
||||
value_num := strings.Replace(points_str, "K", "", 1)
|
||||
value_float, _ := strconv.ParseFloat(value_num, 64)
|
||||
value = int(value_float * 1000)
|
||||
} else if strings.HasSuffix(points_str, "M") {
|
||||
value_num := strings.Replace(points_str, "M", "", 1)
|
||||
value_float, _ := strconv.ParseFloat(value_num, 64)
|
||||
value = int(value_float * 1000000)
|
||||
} else {
|
||||
value, _ = strconv.Atoi(points_str)
|
||||
}
|
||||
return value
|
||||
value := 0
|
||||
if strings.HasSuffix(points_str, "K") {
|
||||
value_num := strings.Replace(points_str, "K", "", 1)
|
||||
value_float, _ := strconv.ParseFloat(value_num, 64)
|
||||
value = int(value_float * 1000)
|
||||
} else if strings.HasSuffix(points_str, "M") {
|
||||
value_num := strings.Replace(points_str, "M", "", 1)
|
||||
value_float, _ := strconv.ParseFloat(value_num, 64)
|
||||
value = int(value_float * 1000000)
|
||||
} else {
|
||||
value, _ = strconv.Atoi(points_str)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// External functions
|
||||
|
||||
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) {
|
||||
pokememe_info_runed_strings = append(pokememe_info_runed_strings, []rune(pokememe_info_strings[i]))
|
||||
}
|
||||
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 {
|
||||
pokememe_info_runed_strings = append(pokememe_info_runed_strings, []rune(pokememe_info_strings[i]))
|
||||
}
|
||||
|
||||
if len(pokememe_info_runed_strings) == 13 {
|
||||
defendable_pokememe = true
|
||||
}
|
||||
if len(pokememe_info_runed_strings) == 13 {
|
||||
defendable_pokememe = true
|
||||
}
|
||||
|
||||
// Getting elements
|
||||
elements := []dbmapping.Element{}
|
||||
element_emojis := make([]string, 0)
|
||||
element_emojis = append(element_emojis, string(pokememe_info_runed_strings[4][11]))
|
||||
if len(pokememe_info_runed_strings[4]) > 12 {
|
||||
element_emojis = append(element_emojis, string(pokememe_info_runed_strings[4][13]))
|
||||
}
|
||||
if len(pokememe_info_runed_strings[4]) > 14 {
|
||||
element_emojis = append(element_emojis, string(pokememe_info_runed_strings[4][15]))
|
||||
}
|
||||
// Getting elements
|
||||
elements := []dbmapping.Element{}
|
||||
element_emojis := make([]string, 0)
|
||||
element_emojis = append(element_emojis, string(pokememe_info_runed_strings[4][11]))
|
||||
if len(pokememe_info_runed_strings[4]) > 12 {
|
||||
element_emojis = append(element_emojis, string(pokememe_info_runed_strings[4][13]))
|
||||
}
|
||||
if len(pokememe_info_runed_strings[4]) > 14 {
|
||||
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, "', '") + "')")
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
return "fail"
|
||||
}
|
||||
err := c.Db.Select(&elements, "SELECT * FROM elements WHERE symbol IN ('"+strings.Join(element_emojis, "', '")+"')")
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
return "fail"
|
||||
}
|
||||
|
||||
// Getting hit-points
|
||||
hitPointsRx := regexp.MustCompile("(\\d|\\.)+(K|M)?")
|
||||
hitPoints := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[5]), -1)
|
||||
if len(hitPoints) != 3 {
|
||||
log.Printf("Can't parse hitpoints!")
|
||||
log.Println(pokememe_info_runed_strings[5])
|
||||
return "fail"
|
||||
}
|
||||
// Getting hit-points
|
||||
hitPointsRx := regexp.MustCompile("(\\d|\\.)+(K|M)?")
|
||||
hitPoints := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[5]), -1)
|
||||
if len(hitPoints) != 3 {
|
||||
log.Printf("Can't parse hitpoints!")
|
||||
log.Println(pokememe_info_runed_strings[5])
|
||||
return "fail"
|
||||
}
|
||||
|
||||
defence := "0"
|
||||
price := "0"
|
||||
defence := "0"
|
||||
price := "0"
|
||||
|
||||
locations := []dbmapping.Location{}
|
||||
locations := []dbmapping.Location{}
|
||||
|
||||
purchaseable := false
|
||||
image := ""
|
||||
purchaseable := false
|
||||
image := ""
|
||||
|
||||
if defendable_pokememe {
|
||||
// Actions for high-grade pokememes
|
||||
defenceMatch := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[6]), -1)
|
||||
if len(defenceMatch) < 1 {
|
||||
log.Printf("Can't parse defence!")
|
||||
log.Println(pokememe_info_runed_strings[6])
|
||||
return "fail"
|
||||
}
|
||||
defence = defenceMatch[0]
|
||||
priceMatch := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[7]), -1)
|
||||
if len(priceMatch) < 1 {
|
||||
log.Printf("Can't parse price!")
|
||||
log.Println(pokememe_info_runed_strings[7])
|
||||
return "fail"
|
||||
}
|
||||
price = priceMatch[0]
|
||||
locationsPrepare := strings.Split(string(pokememe_info_runed_strings[8]), ": ")
|
||||
if len(locationsPrepare) < 2 {
|
||||
log.Printf("Can't parse locations!")
|
||||
log.Println(pokememe_info_runed_strings[8])
|
||||
return "fail"
|
||||
}
|
||||
locationsNames := strings.Split(locationsPrepare[1], ", ")
|
||||
if len(locationsNames) < 1 {
|
||||
log.Printf("Can't parse locations!")
|
||||
log.Println(locationsPrepare)
|
||||
return "fail"
|
||||
}
|
||||
if defendable_pokememe {
|
||||
// Actions for high-grade pokememes
|
||||
defenceMatch := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[6]), -1)
|
||||
if len(defenceMatch) < 1 {
|
||||
log.Printf("Can't parse defence!")
|
||||
log.Println(pokememe_info_runed_strings[6])
|
||||
return "fail"
|
||||
}
|
||||
defence = defenceMatch[0]
|
||||
priceMatch := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[7]), -1)
|
||||
if len(priceMatch) < 1 {
|
||||
log.Printf("Can't parse price!")
|
||||
log.Println(pokememe_info_runed_strings[7])
|
||||
return "fail"
|
||||
}
|
||||
price = priceMatch[0]
|
||||
locationsPrepare := strings.Split(string(pokememe_info_runed_strings[8]), ": ")
|
||||
if len(locationsPrepare) < 2 {
|
||||
log.Printf("Can't parse locations!")
|
||||
log.Println(pokememe_info_runed_strings[8])
|
||||
return "fail"
|
||||
}
|
||||
locationsNames := strings.Split(locationsPrepare[1], ", ")
|
||||
if len(locationsNames) < 1 {
|
||||
log.Printf("Can't parse locations!")
|
||||
log.Println(locationsPrepare)
|
||||
return "fail"
|
||||
}
|
||||
|
||||
err2 := c.Db.Select(&locations, "SELECT * FROM locations WHERE name IN ('" + strings.Join(locationsNames, "', '") + "')")
|
||||
if err2 != nil {
|
||||
log.Printf(err2.Error())
|
||||
return "fail"
|
||||
}
|
||||
if strings.HasSuffix(string(pokememe_info_runed_strings[9]), "Можно") {
|
||||
purchaseable = true
|
||||
}
|
||||
image = strings.Replace(string(pokememe_info_runed_strings[12]), " ", "", -1)
|
||||
} else {
|
||||
// Actions for low-grade pokememes
|
||||
defence = hitPoints[0]
|
||||
priceMatch := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[6]), -1)
|
||||
if len(priceMatch) < 1 {
|
||||
log.Printf("Can't parse price!")
|
||||
log.Println(pokememe_info_runed_strings[6])
|
||||
return "fail"
|
||||
}
|
||||
price = priceMatch[0]
|
||||
locationsPrepare := strings.Split(string(pokememe_info_runed_strings[7]), ": ")
|
||||
if len(locationsPrepare) < 2 {
|
||||
log.Printf("Can't parse locations!")
|
||||
log.Println(pokememe_info_runed_strings[7])
|
||||
return "fail"
|
||||
}
|
||||
locationsNames := strings.Split(locationsPrepare[1], ", ")
|
||||
if len(locationsNames) < 1 {
|
||||
log.Printf("Can't parse locations!")
|
||||
log.Println(locationsPrepare)
|
||||
return "fail"
|
||||
}
|
||||
err2 := c.Db.Select(&locations, "SELECT * FROM locations WHERE name IN ('"+strings.Join(locationsNames, "', '")+"')")
|
||||
if err2 != nil {
|
||||
log.Printf(err2.Error())
|
||||
return "fail"
|
||||
}
|
||||
if strings.HasSuffix(string(pokememe_info_runed_strings[9]), "Можно") {
|
||||
purchaseable = true
|
||||
}
|
||||
image = strings.Replace(string(pokememe_info_runed_strings[12]), " ", "", -1)
|
||||
} else {
|
||||
// Actions for low-grade pokememes
|
||||
defence = hitPoints[0]
|
||||
priceMatch := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[6]), -1)
|
||||
if len(priceMatch) < 1 {
|
||||
log.Printf("Can't parse price!")
|
||||
log.Println(pokememe_info_runed_strings[6])
|
||||
return "fail"
|
||||
}
|
||||
price = priceMatch[0]
|
||||
locationsPrepare := strings.Split(string(pokememe_info_runed_strings[7]), ": ")
|
||||
if len(locationsPrepare) < 2 {
|
||||
log.Printf("Can't parse locations!")
|
||||
log.Println(pokememe_info_runed_strings[7])
|
||||
return "fail"
|
||||
}
|
||||
locationsNames := strings.Split(locationsPrepare[1], ", ")
|
||||
if len(locationsNames) < 1 {
|
||||
log.Printf("Can't parse locations!")
|
||||
log.Println(locationsPrepare)
|
||||
return "fail"
|
||||
}
|
||||
|
||||
err2 := c.Db.Select(&locations, "SELECT * FROM locations WHERE name IN ('" + strings.Join(locationsNames, "', '") + "')")
|
||||
if err2 != nil {
|
||||
log.Printf(err2.Error())
|
||||
return "fail"
|
||||
}
|
||||
if strings.HasSuffix(string(pokememe_info_runed_strings[8]), "Можно") {
|
||||
purchaseable = true
|
||||
}
|
||||
image = strings.Replace(string(pokememe_info_runed_strings[11]), " ", "", -1)
|
||||
}
|
||||
err2 := c.Db.Select(&locations, "SELECT * FROM locations WHERE name IN ('"+strings.Join(locationsNames, "', '")+"')")
|
||||
if err2 != nil {
|
||||
log.Printf(err2.Error())
|
||||
return "fail"
|
||||
}
|
||||
if strings.HasSuffix(string(pokememe_info_runed_strings[8]), "Можно") {
|
||||
purchaseable = true
|
||||
}
|
||||
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])
|
||||
log.Printf("Pokememe grade: " + grade)
|
||||
log.Printf("Pokememe name: " + name)
|
||||
log.Printf("Pokememe description: " + description)
|
||||
log.Printf("Elements:")
|
||||
for i := range elements {
|
||||
log.Printf(elements[i].Symbol + " " + elements[i].Name)
|
||||
}
|
||||
log.Printf("Attack: " + hitPoints[0])
|
||||
log.Printf("HP: " + hitPoints[1])
|
||||
log.Printf("MP: " + hitPoints[2])
|
||||
log.Printf("Defence: " + defence)
|
||||
log.Printf("Price: " + price)
|
||||
log.Printf("Locations:")
|
||||
for i := range locations {
|
||||
log.Printf(locations[i].Symbol + " " + locations[i].Name)
|
||||
}
|
||||
if purchaseable {
|
||||
log.Printf("Purchaseable")
|
||||
} else {
|
||||
log.Printf("Non-purchaseable")
|
||||
}
|
||||
log.Printf("Image: " + image)
|
||||
|
||||
grade := string(pokememe_info_runed_strings[0][0])
|
||||
name := string(pokememe_info_runed_strings[0][3:])
|
||||
description := string(pokememe_info_runed_strings[1])
|
||||
log.Printf("Pokememe grade: " + grade)
|
||||
log.Printf("Pokememe name: " + name)
|
||||
log.Printf("Pokememe description: " + description)
|
||||
log.Printf("Elements:")
|
||||
for i := range(elements) {
|
||||
log.Printf(elements[i].Symbol + " " + elements[i].Name)
|
||||
}
|
||||
log.Printf("Attack: " + hitPoints[0])
|
||||
log.Printf("HP: " + hitPoints[1])
|
||||
log.Printf("MP: " + hitPoints[2])
|
||||
log.Printf("Defence: " + defence)
|
||||
log.Printf("Price: " + price)
|
||||
log.Printf("Locations:")
|
||||
for i := range(locations) {
|
||||
log.Printf(locations[i].Symbol + " " + locations[i].Name)
|
||||
}
|
||||
if purchaseable {
|
||||
log.Printf("Purchaseable")
|
||||
} else {
|
||||
log.Printf("Non-purchaseable")
|
||||
}
|
||||
log.Printf("Image: " + image)
|
||||
// Building pokememe
|
||||
pokememe := dbmapping.Pokememe{}
|
||||
// Checking if pokememe exists in database
|
||||
err3 := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE grade='"+grade+"' AND name='"+name+"';"))
|
||||
if err3 != nil {
|
||||
log.Printf("Adding new pokememe...")
|
||||
} else {
|
||||
log.Printf("This pokememe already exist. Return specific error.")
|
||||
return "dup"
|
||||
}
|
||||
|
||||
// Building pokememe
|
||||
pokememe := dbmapping.Pokememe{}
|
||||
// Checking if pokememe exists in database
|
||||
err3 := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE grade='" + grade + "' AND name='" + name + "';"))
|
||||
if err3 != nil {
|
||||
log.Printf("Adding new pokememe...")
|
||||
} else {
|
||||
log.Printf("This pokememe already exist. Return specific error.")
|
||||
return "dup"
|
||||
}
|
||||
grade_int, _ := strconv.Atoi(grade)
|
||||
attack_int := p.getPoints(hitPoints[0])
|
||||
hp_int := p.getPoints(hitPoints[1])
|
||||
mp_int := p.getPoints(hitPoints[2])
|
||||
defence_int := p.getPoints(defence)
|
||||
price_int := p.getPoints(price)
|
||||
|
||||
grade_int, _ := strconv.Atoi(grade)
|
||||
attack_int := p.getPoints(hitPoints[0])
|
||||
hp_int := p.getPoints(hitPoints[1])
|
||||
mp_int := p.getPoints(hitPoints[2])
|
||||
defence_int := p.getPoints(defence)
|
||||
price_int := p.getPoints(price)
|
||||
pokememe.Grade = grade_int
|
||||
pokememe.Name = name
|
||||
pokememe.Description = description
|
||||
pokememe.Attack = attack_int
|
||||
pokememe.HP = hp_int
|
||||
pokememe.MP = mp_int
|
||||
pokememe.Defence = defence_int
|
||||
pokememe.Price = price_int
|
||||
if purchaseable {
|
||||
pokememe.Purchaseable = true
|
||||
} else {
|
||||
pokememe.Purchaseable = false
|
||||
}
|
||||
pokememe.Image_url = image
|
||||
pokememe.Player_id = player_raw.Id
|
||||
pokememe.Created_at = time.Now().UTC()
|
||||
|
||||
pokememe.Grade = grade_int
|
||||
pokememe.Name = name
|
||||
pokememe.Description = description
|
||||
pokememe.Attack = attack_int
|
||||
pokememe.HP = hp_int
|
||||
pokememe.MP = mp_int
|
||||
pokememe.Defence = defence_int
|
||||
pokememe.Price = price_int
|
||||
if purchaseable {
|
||||
pokememe.Purchaseable = true
|
||||
} else {
|
||||
pokememe.Purchaseable = false
|
||||
}
|
||||
pokememe.Image_url = image
|
||||
pokememe.Player_id = player_raw.Id
|
||||
pokememe.Created_at = time.Now().UTC()
|
||||
_, err4 := c.Db.NamedExec("INSERT INTO pokememes VALUES(NULL, :grade, :name, :description, :attack, :hp, :mp, :defence, :price, :purchaseable, :image_url, :player_id, :created_at)", &pokememe)
|
||||
if err4 != nil {
|
||||
log.Printf(err4.Error())
|
||||
return "fail"
|
||||
}
|
||||
|
||||
_, err4 := c.Db.NamedExec("INSERT INTO pokememes VALUES(NULL, :grade, :name, :description, :attack, :hp, :mp, :defence, :price, :purchaseable, :image_url, :player_id, :created_at)", &pokememe)
|
||||
if err4 != nil {
|
||||
log.Printf(err4.Error())
|
||||
return "fail"
|
||||
}
|
||||
// Getting new pokememe
|
||||
err5 := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE grade='"+grade+"' AND name='"+name+"';"))
|
||||
if err5 != nil {
|
||||
log.Printf("Pokememe isn't added!")
|
||||
return "fail"
|
||||
}
|
||||
for i := range elements {
|
||||
link := dbmapping.PokememeElement{}
|
||||
link.Pokememe_id = pokememe.Id
|
||||
link.Element_id = elements[i].Id
|
||||
link.Created_at = time.Now().UTC()
|
||||
|
||||
// Getting new pokememe
|
||||
err5 := c.Db.Get(&pokememe, c.Db.Rebind("SELECT * FROM pokememes WHERE grade='" + grade + "' AND name='" + name + "';"))
|
||||
if err5 != nil {
|
||||
log.Printf("Pokememe isn't added!")
|
||||
return "fail"
|
||||
}
|
||||
for i := range(elements) {
|
||||
link := dbmapping.PokememeElement{}
|
||||
link.Pokememe_id = pokememe.Id
|
||||
link.Element_id = elements[i].Id
|
||||
link.Created_at = time.Now().UTC()
|
||||
_, err6 := c.Db.NamedExec("INSERT INTO pokememes_elements VALUES(NULL, :pokememe_id, :element_id, :created_at)", &link)
|
||||
if err6 != nil {
|
||||
log.Printf(err6.Error())
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
for i := range locations {
|
||||
link := dbmapping.PokememeLocation{}
|
||||
link.Pokememe_id = pokememe.Id
|
||||
link.Location_id = locations[i].Id
|
||||
link.Created_at = time.Now().UTC()
|
||||
|
||||
_, err6 := c.Db.NamedExec("INSERT INTO pokememes_elements VALUES(NULL, :pokememe_id, :element_id, :created_at)", &link)
|
||||
if err6 != nil {
|
||||
log.Printf(err6.Error())
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
for i := range(locations) {
|
||||
link := dbmapping.PokememeLocation{}
|
||||
link.Pokememe_id = pokememe.Id
|
||||
link.Location_id = locations[i].Id
|
||||
link.Created_at = time.Now().UTC()
|
||||
_, err7 := c.Db.NamedExec("INSERT INTO pokememes_locations VALUES(NULL, :pokememe_id, :location_id, :created_at)", &link)
|
||||
if err7 != nil {
|
||||
log.Printf(err7.Error())
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
_, err7 := c.Db.NamedExec("INSERT INTO pokememes_locations VALUES(NULL, :pokememe_id, :location_id, :created_at)", &link)
|
||||
if err7 != nil {
|
||||
log.Printf(err7.Error())
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return "ok"
|
||||
return "ok"
|
||||
}
|
||||
|
||||
func (p *Parsers) ReturnPoints(points int) string {
|
||||
if points < 1000 {
|
||||
return strconv.Itoa(points)
|
||||
} else if points < 1000000 {
|
||||
float_num := float64(points) / 1000.0
|
||||
return strconv.FormatFloat(float_num, 'f', -1, 64) + "K"
|
||||
} else {
|
||||
float_num := float64(points) / 1000000.0
|
||||
return strconv.FormatFloat(float_num, 'f', -1, 64) + "M"
|
||||
}
|
||||
if points < 1000 {
|
||||
return strconv.Itoa(points)
|
||||
} else if points < 1000000 {
|
||||
float_num := float64(points) / 1000.0
|
||||
return strconv.FormatFloat(float_num, 'f', -1, 64) + "K"
|
||||
} else {
|
||||
float_num := float64(points) / 1000000.0
|
||||
return strconv.FormatFloat(float_num, 'f', -1, 64) + "M"
|
||||
}
|
||||
}
|
||||
|
@ -4,279 +4,278 @@
|
||||
package parsers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
"strconv"
|
||||
"time"
|
||||
// 3rd party
|
||||
// stdlib
|
||||
"log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../dbmapping"
|
||||
// local
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
// Internal functions
|
||||
|
||||
func (p *Parsers) fillProfilePokememe(profile_id int, meme string, attack string, rarity string) {
|
||||
spk_raw := dbmapping.Pokememe{}
|
||||
err := c.Db.Get(&spk_raw, c.Db.Rebind("SELECT * FROM pokememes WHERE name='" + meme + "';"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
attack_int := p.getPoints(attack)
|
||||
// Improve it. Game's precision is unstable
|
||||
orig_attack := float64(spk_raw.Attack)
|
||||
if rarity == "rare" {
|
||||
orig_attack = orig_attack * 1.1
|
||||
}
|
||||
level := int(float64(attack_int) / orig_attack)
|
||||
spk_raw := dbmapping.Pokememe{}
|
||||
err := c.Db.Get(&spk_raw, c.Db.Rebind("SELECT * FROM pokememes WHERE name='"+meme+"';"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
attack_int := p.getPoints(attack)
|
||||
// Improve it. Game's precision is unstable
|
||||
orig_attack := float64(spk_raw.Attack)
|
||||
if rarity == "rare" {
|
||||
orig_attack = orig_attack * 1.1
|
||||
}
|
||||
level := int(float64(attack_int) / orig_attack)
|
||||
|
||||
ppk := dbmapping.ProfilePokememe{}
|
||||
ppk.Profile_id = profile_id
|
||||
ppk.Pokememe_id = spk_raw.Id
|
||||
ppk.Pokememe_lvl = level
|
||||
ppk.Pokememe_rarity = rarity
|
||||
ppk.Created_at = time.Now().UTC()
|
||||
_, err2 := c.Db.NamedExec("INSERT INTO `profiles_pokememes` VALUES(NULL, :profile_id, :pokememe_id, :pokememe_lvl, :pokememe_rarity, :created_at)", &ppk)
|
||||
if err2 != nil {
|
||||
log.Println(err2)
|
||||
}
|
||||
}
|
||||
ppk := dbmapping.ProfilePokememe{}
|
||||
ppk.Profile_id = profile_id
|
||||
ppk.Pokememe_id = spk_raw.Id
|
||||
ppk.Pokememe_lvl = level
|
||||
ppk.Pokememe_rarity = rarity
|
||||
ppk.Created_at = time.Now().UTC()
|
||||
_, err2 := c.Db.NamedExec("INSERT INTO `profiles_pokememes` VALUES(NULL, :profile_id, :pokememe_id, :pokememe_lvl, :pokememe_rarity, :created_at)", &ppk)
|
||||
if err2 != nil {
|
||||
log.Println(err2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// External functions
|
||||
|
||||
func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Player) string {
|
||||
text := update.Message.Text
|
||||
log.Println(text)
|
||||
text := update.Message.Text
|
||||
log.Println(text)
|
||||
|
||||
profile_info_strings := strings.Split(text, "\n")
|
||||
profile_info_runed_strings := make([][]rune, 0)
|
||||
for i := range(profile_info_strings) {
|
||||
profile_info_runed_strings = append(profile_info_runed_strings, []rune(profile_info_strings[i]))
|
||||
}
|
||||
profile_info_strings := strings.Split(text, "\n")
|
||||
profile_info_runed_strings := make([][]rune, 0)
|
||||
for i := range profile_info_strings {
|
||||
profile_info_runed_strings = append(profile_info_runed_strings, []rune(profile_info_strings[i]))
|
||||
}
|
||||
|
||||
league := dbmapping.League{}
|
||||
league := dbmapping.League{}
|
||||
|
||||
telegram_nickname := update.Message.From.UserName
|
||||
nickname := ""
|
||||
level := ""
|
||||
level_int := 0
|
||||
exp := ""
|
||||
exp_int := 0
|
||||
egg_exp := ""
|
||||
egg_exp_int := 0
|
||||
pokeballs := ""
|
||||
pokeballs_int := 0
|
||||
wealth := ""
|
||||
wealth_int := 0
|
||||
crystalls := ""
|
||||
crystalls_int := 0
|
||||
weapon := ""
|
||||
pokememes := make(map[string]string)
|
||||
power_int := 1
|
||||
telegram_nickname := update.Message.From.UserName
|
||||
nickname := ""
|
||||
level := ""
|
||||
level_int := 0
|
||||
exp := ""
|
||||
exp_int := 0
|
||||
egg_exp := ""
|
||||
egg_exp_int := 0
|
||||
pokeballs := ""
|
||||
pokeballs_int := 0
|
||||
wealth := ""
|
||||
wealth_int := 0
|
||||
crystalls := ""
|
||||
crystalls_int := 0
|
||||
weapon := ""
|
||||
pokememes := make(map[string]string)
|
||||
power_int := 1
|
||||
|
||||
// Filling information
|
||||
// We don't know how many strings we got, so we iterating each other
|
||||
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, "🈵") {
|
||||
err1 := c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE symbol='" + string(current_runes[0]) + "'"))
|
||||
if err1 != nil {
|
||||
log.Println(err1)
|
||||
return "fail"
|
||||
}
|
||||
for j := range(current_runes) {
|
||||
if j > 1 {
|
||||
nickname += string(current_runes[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(current_string, "👤Уровень:") {
|
||||
levelRx := regexp.MustCompile("\\d+")
|
||||
level_array := levelRx.FindAllString(current_string, -1)
|
||||
if len(level_array) < 1 {
|
||||
log.Println("Level string broken")
|
||||
return "fail"
|
||||
}
|
||||
level = level_array[0]
|
||||
level_int, _ = strconv.Atoi(level)
|
||||
}
|
||||
// Filling information
|
||||
// We don't know how many strings we got, so we iterating each other
|
||||
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, "🈵") {
|
||||
err1 := c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE symbol='"+string(current_runes[0])+"'"))
|
||||
if err1 != nil {
|
||||
log.Println(err1)
|
||||
return "fail"
|
||||
}
|
||||
for j := range current_runes {
|
||||
if j > 1 {
|
||||
nickname += string(current_runes[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(current_string, "👤Уровень:") {
|
||||
levelRx := regexp.MustCompile("\\d+")
|
||||
level_array := levelRx.FindAllString(current_string, -1)
|
||||
if len(level_array) < 1 {
|
||||
log.Println("Level string broken")
|
||||
return "fail"
|
||||
}
|
||||
level = level_array[0]
|
||||
level_int, _ = strconv.Atoi(level)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(current_string, "🎓Опыт") {
|
||||
expRx := regexp.MustCompile("\\d+")
|
||||
exp_array := expRx.FindAllString(current_string, -1)
|
||||
if len(exp_array) < 4 {
|
||||
log.Println("Exp string broken")
|
||||
return "fail"
|
||||
}
|
||||
exp = exp_array[0]
|
||||
exp_int, _ = strconv.Atoi(exp)
|
||||
egg_exp = exp_array[2]
|
||||
egg_exp_int, _ = strconv.Atoi(egg_exp)
|
||||
}
|
||||
if strings.HasPrefix(current_string, "🎓Опыт") {
|
||||
expRx := regexp.MustCompile("\\d+")
|
||||
exp_array := expRx.FindAllString(current_string, -1)
|
||||
if len(exp_array) < 4 {
|
||||
log.Println("Exp string broken")
|
||||
return "fail"
|
||||
}
|
||||
exp = exp_array[0]
|
||||
exp_int, _ = strconv.Atoi(exp)
|
||||
egg_exp = exp_array[2]
|
||||
egg_exp_int, _ = strconv.Atoi(egg_exp)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(current_string, "⭕Покеболы") {
|
||||
pkbRx := regexp.MustCompile("\\d+")
|
||||
pkb_array := pkbRx.FindAllString(current_string, -1)
|
||||
if len(pkb_array) < 2 {
|
||||
log.Println("Pokeballs string broken")
|
||||
return "fail"
|
||||
}
|
||||
pokeballs = pkb_array[1]
|
||||
pokeballs_int, _ = strconv.Atoi(pokeballs)
|
||||
}
|
||||
if strings.HasPrefix(current_string, "⭕Покеболы") {
|
||||
pkbRx := regexp.MustCompile("\\d+")
|
||||
pkb_array := pkbRx.FindAllString(current_string, -1)
|
||||
if len(pkb_array) < 2 {
|
||||
log.Println("Pokeballs string broken")
|
||||
return "fail"
|
||||
}
|
||||
pokeballs = pkb_array[1]
|
||||
pokeballs_int, _ = strconv.Atoi(pokeballs)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(current_string, "💲") {
|
||||
wealthRx := regexp.MustCompile("(\\d|\\.|K|M)+")
|
||||
wealth_array := wealthRx.FindAllString(current_string, -1)
|
||||
if len(wealth_array) < 2 {
|
||||
log.Println("Wealth string broken")
|
||||
return "fail"
|
||||
}
|
||||
wealth = wealth_array[0]
|
||||
wealth_int = p.getPoints(wealth)
|
||||
crystalls =wealth_array[1]
|
||||
crystalls_int = p.getPoints(crystalls)
|
||||
}
|
||||
if strings.HasPrefix(current_string, "💲") {
|
||||
wealthRx := regexp.MustCompile("(\\d|\\.|K|M)+")
|
||||
wealth_array := wealthRx.FindAllString(current_string, -1)
|
||||
if len(wealth_array) < 2 {
|
||||
log.Println("Wealth string broken")
|
||||
return "fail"
|
||||
}
|
||||
wealth = wealth_array[0]
|
||||
wealth_int = p.getPoints(wealth)
|
||||
crystalls = wealth_array[1]
|
||||
crystalls_int = p.getPoints(crystalls)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(current_string, "🔫") {
|
||||
// We need NEXT string!
|
||||
weapon_type_string := strings.Replace(current_string, "🔫 ", "", 1)
|
||||
wnRx := regexp.MustCompile("(.+)(ита)")
|
||||
weapon = wnRx.FindString(weapon_type_string)
|
||||
}
|
||||
if strings.HasPrefix(current_string, "🔫") {
|
||||
// We need NEXT string!
|
||||
weapon_type_string := strings.Replace(current_string, "🔫 ", "", 1)
|
||||
wnRx := regexp.MustCompile("(.+)(ита)")
|
||||
weapon = wnRx.FindString(weapon_type_string)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(current_string, "🐱Покемемы: ") {
|
||||
pkmnumRx := regexp.MustCompile("\\d+")
|
||||
pk_num_array := pkmnumRx.FindAllString(current_string, -1)
|
||||
if len(pk_num_array) < 2 {
|
||||
log.Println("Pokememes count broken")
|
||||
return "fail"
|
||||
}
|
||||
pokememes_count, _ := strconv.Atoi(pk_num_array[0])
|
||||
if pokememes_count > 0 {
|
||||
for pi := 0; pi < pokememes_count; pi++ {
|
||||
pokememe_string := string(profile_info_runed_strings[i + 1 + pi])
|
||||
attackRx := regexp.MustCompile("(\\d|\\.|K|M)+")
|
||||
pk_points_array := attackRx.FindAllString(pokememe_string, -1)
|
||||
pk_attack := pk_points_array[1]
|
||||
pk_name := strings.Split(pokememe_string, "+")[0]
|
||||
pk_name = strings.Replace(pk_name, " ⭐", "", 1)
|
||||
pk_name = strings.TrimSuffix(pk_name, " ")
|
||||
pk_name = strings.Split(pk_name, "⃣ ")[1]
|
||||
pokememes[pk_name] = pk_attack
|
||||
power_int += p.getPoints(pk_attack)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(current_string, "🐱Покемемы: ") {
|
||||
pkmnumRx := regexp.MustCompile("\\d+")
|
||||
pk_num_array := pkmnumRx.FindAllString(current_string, -1)
|
||||
if len(pk_num_array) < 2 {
|
||||
log.Println("Pokememes count broken")
|
||||
return "fail"
|
||||
}
|
||||
pokememes_count, _ := strconv.Atoi(pk_num_array[0])
|
||||
if pokememes_count > 0 {
|
||||
for pi := 0; pi < pokememes_count; pi++ {
|
||||
pokememe_string := string(profile_info_runed_strings[i+1+pi])
|
||||
attackRx := regexp.MustCompile("(\\d|\\.|K|M)+")
|
||||
pk_points_array := attackRx.FindAllString(pokememe_string, -1)
|
||||
pk_attack := pk_points_array[1]
|
||||
pk_name := strings.Split(pokememe_string, "+")[0]
|
||||
pk_name = strings.Replace(pk_name, " ⭐", "", 1)
|
||||
pk_name = strings.TrimSuffix(pk_name, " ")
|
||||
pk_name = strings.Split(pk_name, "⃣ ")[1]
|
||||
pokememes[pk_name] = pk_attack
|
||||
power_int += p.getPoints(pk_attack)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Telegram nickname: " + telegram_nickname)
|
||||
log.Printf("Nickname: " + nickname)
|
||||
log.Printf("League: " + league.Name)
|
||||
log.Printf("Level: " + level)
|
||||
log.Println(level_int)
|
||||
log.Printf("Exp: " + exp)
|
||||
log.Println(exp_int)
|
||||
log.Printf("Egg exp: " + egg_exp)
|
||||
log.Println(egg_exp_int)
|
||||
log.Printf("Pokeballs: " + pokeballs)
|
||||
log.Println(pokeballs_int)
|
||||
log.Printf("Wealth: " + wealth)
|
||||
log.Println(wealth_int)
|
||||
log.Printf("Crystalls: " + crystalls)
|
||||
log.Println(crystalls_int)
|
||||
log.Printf("Weapon: " + weapon)
|
||||
if len(pokememes) > 0 {
|
||||
for meme, attack := range(pokememes) {
|
||||
log.Printf(meme + ": " + attack)
|
||||
}
|
||||
} else {
|
||||
log.Printf("Hand is empty.")
|
||||
}
|
||||
log.Printf("Telegram nickname: " + telegram_nickname)
|
||||
log.Printf("Nickname: " + nickname)
|
||||
log.Printf("League: " + league.Name)
|
||||
log.Printf("Level: " + level)
|
||||
log.Println(level_int)
|
||||
log.Printf("Exp: " + exp)
|
||||
log.Println(exp_int)
|
||||
log.Printf("Egg exp: " + egg_exp)
|
||||
log.Println(egg_exp_int)
|
||||
log.Printf("Pokeballs: " + pokeballs)
|
||||
log.Println(pokeballs_int)
|
||||
log.Printf("Wealth: " + wealth)
|
||||
log.Println(wealth_int)
|
||||
log.Printf("Crystalls: " + crystalls)
|
||||
log.Println(crystalls_int)
|
||||
log.Printf("Weapon: " + weapon)
|
||||
if len(pokememes) > 0 {
|
||||
for meme, attack := range pokememes {
|
||||
log.Printf(meme + ": " + attack)
|
||||
}
|
||||
} else {
|
||||
log.Printf("Hand is empty.")
|
||||
}
|
||||
|
||||
// Information is gathered, let's create profile in database!
|
||||
weapon_raw := dbmapping.Weapon{}
|
||||
err2 := c.Db.Get(&weapon_raw, c.Db.Rebind("SELECT * FROM weapons WHERE name='" + weapon + "'"))
|
||||
if err2 != nil {
|
||||
log.Println(err2)
|
||||
}
|
||||
// Information is gathered, let's create profile in database!
|
||||
weapon_raw := dbmapping.Weapon{}
|
||||
err2 := c.Db.Get(&weapon_raw, c.Db.Rebind("SELECT * FROM weapons WHERE name='"+weapon+"'"))
|
||||
if err2 != nil {
|
||||
log.Println(err2)
|
||||
}
|
||||
|
||||
if player_raw.League_id == 0 {
|
||||
// Updating player with league
|
||||
player_raw.League_id = league.Id
|
||||
if player_raw.Status == "nobody" {
|
||||
player_raw.Status = "common"
|
||||
}
|
||||
_, err4 := c.Db.NamedExec("UPDATE `players` SET league_id=:league_id, status=:status WHERE id=:id", &player_raw)
|
||||
if err4 != nil {
|
||||
log.Println(err4)
|
||||
return "fail"
|
||||
}
|
||||
} else if player_raw.League_id != league.Id {
|
||||
// Duplicate profile: user changed league, beware!
|
||||
player_raw.League_id = league.Id
|
||||
player_raw.Squad_id = 0
|
||||
player_raw.Status = "league_changed"
|
||||
player_raw.Created_at = time.Now().UTC()
|
||||
_, err5 := c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :squad_id, :status, :created_at, :updated_at)", &player_raw)
|
||||
if err5 != nil {
|
||||
log.Println(err5)
|
||||
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) + "';"))
|
||||
if err6 != nil {
|
||||
log.Println(err6)
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
if player_raw.League_id == 0 {
|
||||
// Updating player with league
|
||||
player_raw.League_id = league.Id
|
||||
if player_raw.Status == "nobody" {
|
||||
player_raw.Status = "common"
|
||||
}
|
||||
_, err4 := c.Db.NamedExec("UPDATE `players` SET league_id=:league_id, status=:status WHERE id=:id", &player_raw)
|
||||
if err4 != nil {
|
||||
log.Println(err4)
|
||||
return "fail"
|
||||
}
|
||||
} else if player_raw.League_id != league.Id {
|
||||
// Duplicate profile: user changed league, beware!
|
||||
player_raw.League_id = league.Id
|
||||
player_raw.Squad_id = 0
|
||||
player_raw.Status = "league_changed"
|
||||
player_raw.Created_at = time.Now().UTC()
|
||||
_, err5 := c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :squad_id, :status, :created_at, :updated_at)", &player_raw)
|
||||
if err5 != nil {
|
||||
log.Println(err5)
|
||||
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)+"';"))
|
||||
if err6 != nil {
|
||||
log.Println(err6)
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
profile_raw := dbmapping.Profile{}
|
||||
profile_raw.Player_id = player_raw.Id
|
||||
profile_raw.Nickname = nickname
|
||||
profile_raw.TelegramNickname = telegram_nickname
|
||||
profile_raw.Level_id = level_int
|
||||
profile_raw.Pokeballs = pokeballs_int
|
||||
profile_raw.Wealth = wealth_int
|
||||
profile_raw.Exp = exp_int
|
||||
profile_raw.Egg_exp = egg_exp_int
|
||||
profile_raw.Power = power_int
|
||||
profile_raw.Weapon_id = weapon_raw.Id
|
||||
profile_raw.Crystalls = crystalls_int
|
||||
profile_raw.Created_at = time.Now().UTC()
|
||||
profile_raw := dbmapping.Profile{}
|
||||
profile_raw.Player_id = player_raw.Id
|
||||
profile_raw.Nickname = nickname
|
||||
profile_raw.TelegramNickname = telegram_nickname
|
||||
profile_raw.Level_id = level_int
|
||||
profile_raw.Pokeballs = pokeballs_int
|
||||
profile_raw.Wealth = wealth_int
|
||||
profile_raw.Exp = exp_int
|
||||
profile_raw.Egg_exp = egg_exp_int
|
||||
profile_raw.Power = power_int
|
||||
profile_raw.Weapon_id = weapon_raw.Id
|
||||
profile_raw.Crystalls = crystalls_int
|
||||
profile_raw.Created_at = time.Now().UTC()
|
||||
|
||||
_, err3 := c.Db.NamedExec("INSERT INTO `profiles` VALUES(NULL, :player_id, :nickname, :telegram_nickname, :level_id, :pokeballs, :wealth, :exp, :egg_exp, :power, :weapon_id, :crystalls, :created_at)", &profile_raw)
|
||||
if err3 != nil {
|
||||
log.Println(err3)
|
||||
return "fail"
|
||||
}
|
||||
_, err3 := c.Db.NamedExec("INSERT INTO `profiles` VALUES(NULL, :player_id, :nickname, :telegram_nickname, :level_id, :pokeballs, :wealth, :exp, :egg_exp, :power, :weapon_id, :crystalls, :created_at)", &profile_raw)
|
||||
if err3 != nil {
|
||||
log.Println(err3)
|
||||
return "fail"
|
||||
}
|
||||
|
||||
err8 := c.Db.Get(&profile_raw, c.Db.Rebind("SELECT * FROM profiles WHERE player_id=? AND created_at=?"), profile_raw.Player_id, profile_raw.Created_at)
|
||||
if err8 != nil {
|
||||
log.Println(err8)
|
||||
log.Printf("Profile isn't added!")
|
||||
return "fail"
|
||||
}
|
||||
err8 := c.Db.Get(&profile_raw, c.Db.Rebind("SELECT * FROM profiles WHERE player_id=? AND created_at=?"), profile_raw.Player_id, profile_raw.Created_at)
|
||||
if err8 != nil {
|
||||
log.Println(err8)
|
||||
log.Printf("Profile isn't added!")
|
||||
return "fail"
|
||||
}
|
||||
|
||||
player_raw.Updated_at = time.Now().UTC()
|
||||
_, err7 := c.Db.NamedExec("UPDATE `players` SET updated_at=:updated_at WHERE id=:id", &player_raw)
|
||||
if err7 != nil {
|
||||
log.Println(err7)
|
||||
return "fail"
|
||||
}
|
||||
player_raw.Updated_at = time.Now().UTC()
|
||||
_, err7 := c.Db.NamedExec("UPDATE `players` SET updated_at=:updated_at WHERE id=:id", &player_raw)
|
||||
if err7 != nil {
|
||||
log.Println(err7)
|
||||
return "fail"
|
||||
}
|
||||
|
||||
for meme, attack := range pokememes {
|
||||
rarity := "common"
|
||||
if strings.HasPrefix(meme, "🔸") {
|
||||
rarity = "rare"
|
||||
meme = strings.Replace(meme, "🔸", "", 1)
|
||||
}
|
||||
p.fillProfilePokememe(profile_raw.Id, meme, attack, rarity)
|
||||
}
|
||||
|
||||
for meme, attack := range(pokememes) {
|
||||
rarity := "common"
|
||||
if strings.HasPrefix(meme, "🔸") {
|
||||
rarity = "rare"
|
||||
meme = strings.Replace(meme, "🔸", "", 1)
|
||||
}
|
||||
p.fillProfilePokememe(profile_raw.Id, meme, attack, rarity)
|
||||
}
|
||||
|
||||
return "ok"
|
||||
return "ok"
|
||||
}
|
||||
|
@ -4,23 +4,23 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../appcontext"
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../appcontext"
|
||||
)
|
||||
|
||||
var (
|
||||
c *appcontext.Context
|
||||
r *Router
|
||||
c *appcontext.Context
|
||||
r *Router
|
||||
)
|
||||
|
||||
func New(ac *appcontext.Context) {
|
||||
c = ac
|
||||
rh := RouterHandler{}
|
||||
c.RegisterRouterInterface(rh)
|
||||
c = ac
|
||||
rh := RouterHandler{}
|
||||
c.RegisterRouterInterface(rh)
|
||||
}
|
||||
|
||||
func (r *Router) Init() {
|
||||
log.Printf("Initialized request router...")
|
||||
log.Printf("Initialized request router...")
|
||||
}
|
||||
|
@ -4,16 +4,16 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
type RouterHandler struct {}
|
||||
type RouterHandler struct{}
|
||||
|
||||
func (rh RouterHandler) Init() {
|
||||
r.Init()
|
||||
r.Init()
|
||||
}
|
||||
|
||||
func (rh RouterHandler) RouteRequest(update tgbotapi.Update) string {
|
||||
return r.RouteRequest(update)
|
||||
return r.RouteRequest(update)
|
||||
}
|
||||
|
@ -4,136 +4,136 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
// 3rd party
|
||||
// stdlib
|
||||
"log"
|
||||
"regexp"
|
||||
"strings"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
type Router struct {}
|
||||
type Router struct{}
|
||||
|
||||
// This function will route requests to appropriative modules
|
||||
// It will return "ok" or "fail"
|
||||
// If command doesn't exist, it's "fail"
|
||||
func (r *Router) RouteRequest(update tgbotapi.Update) string {
|
||||
text := update.Message.Text
|
||||
text := update.Message.Text
|
||||
|
||||
player_raw, ok := c.Getters.GetOrCreatePlayer(update.Message.From.ID)
|
||||
if !ok {
|
||||
// Silently fail
|
||||
return "fail"
|
||||
}
|
||||
player_raw, ok := c.Getters.GetOrCreatePlayer(update.Message.From.ID)
|
||||
if !ok {
|
||||
// Silently fail
|
||||
return "fail"
|
||||
}
|
||||
|
||||
// Regular expressions
|
||||
var durakMsg = regexp.MustCompile("(Д|д)(У|у)(Р|р)(А|а|Е|е|О|о)")
|
||||
var huMsg = regexp.MustCompile("(Х|х)(У|у)(Й|й|Я|я|Ю|ю|Е|е)")
|
||||
var blMsg = regexp.MustCompile("(\\s|^)(Б|б)(Л|л)(Я|я)(Т|т|Д|д)")
|
||||
var ebMsg = regexp.MustCompile("(\\s|^|ЗА|За|зА|за)(Е|е|Ё|ё)(Б|б)(\\s|Л|л|А|а|Т|т|У|у|Е|е|Ё|ё|И|и)")
|
||||
var piMsg = regexp.MustCompile("(П|п)(И|и)(З|з)(Д|д)")
|
||||
// Regular expressions
|
||||
var durakMsg = regexp.MustCompile("(Д|д)(У|у)(Р|р)(А|а|Е|е|О|о)")
|
||||
var huMsg = regexp.MustCompile("(Х|х)(У|у)(Й|й|Я|я|Ю|ю|Е|е)")
|
||||
var blMsg = regexp.MustCompile("(\\s|^)(Б|б)(Л|л)(Я|я)(Т|т|Д|д)")
|
||||
var ebMsg = regexp.MustCompile("(\\s|^|ЗА|За|зА|за)(Е|е|Ё|ё)(Б|б)(\\s|Л|л|А|а|Т|т|У|у|Е|е|Ё|ё|И|и)")
|
||||
var piMsg = regexp.MustCompile("(П|п)(И|и)(З|з)(Д|д)")
|
||||
|
||||
// Commands
|
||||
var helpMsg = regexp.MustCompile("/help\\z")
|
||||
var helloMsg = regexp.MustCompile("/start\\z")
|
||||
var pokedexMsg = regexp.MustCompile("/pokede(x|ks)\\d?\\z")
|
||||
var pokememeInfoMsg = regexp.MustCompile("/pk(\\d+)")
|
||||
var meMsg = regexp.MustCompile("/me\\z")
|
||||
var bestMsg = regexp.MustCompile("/best\\z")
|
||||
// Commands
|
||||
var helpMsg = regexp.MustCompile("/help\\z")
|
||||
var helloMsg = regexp.MustCompile("/start\\z")
|
||||
var pokedexMsg = regexp.MustCompile("/pokede(x|ks)\\d?\\z")
|
||||
var pokememeInfoMsg = regexp.MustCompile("/pk(\\d+)")
|
||||
var meMsg = regexp.MustCompile("/me\\z")
|
||||
var bestMsg = regexp.MustCompile("/best\\z")
|
||||
|
||||
// Forwards
|
||||
var pokememeMsg = regexp.MustCompile("(Уровень)(.+)(Опыт)(.+)\n(Элементы:)(.+)\n(.+)(💙MP)")
|
||||
var profileMsg = regexp.MustCompile(`(Онлайн: )(\d+)\n(Турнир через)(.+)\n\n(.*)\n(Элементы)(.+)\n(.*)\n\n(.+)(Уровень)(.+)\n`)
|
||||
// Forwards
|
||||
var pokememeMsg = regexp.MustCompile("(Уровень)(.+)(Опыт)(.+)\n(Элементы:)(.+)\n(.+)(💙MP)")
|
||||
var profileMsg = regexp.MustCompile(`(Онлайн: )(\d+)\n(Турнир через)(.+)\n\n(.*)\n(Элементы)(.+)\n(.*)\n\n(.+)(Уровень)(.+)\n`)
|
||||
|
||||
if update.Message.ForwardFrom != nil {
|
||||
if update.Message.ForwardFrom.ID != 360402625 {
|
||||
log.Printf("Forward from another user or bot. Ignoring")
|
||||
} else {
|
||||
log.Printf("Forward from PokememBro bot! Processing...")
|
||||
if player_raw.Id != 0 {
|
||||
switch {
|
||||
case pokememeMsg.MatchString(text):
|
||||
log.Printf("Pokememe posted!")
|
||||
status := c.Parsers.ParsePokememe(text, player_raw)
|
||||
switch status {
|
||||
case "ok":
|
||||
c.Talkers.PokememeAddSuccessMessage(update)
|
||||
case "dup":
|
||||
c.Talkers.PokememeAddDuplicateMessage(update)
|
||||
case "fail":
|
||||
c.Talkers.PokememeAddFailureMessage(update)
|
||||
}
|
||||
case profileMsg.MatchString(text):
|
||||
log.Printf("Profile posted!")
|
||||
status := c.Parsers.ParseProfile(update, player_raw)
|
||||
switch status {
|
||||
case "ok":
|
||||
c.Talkers.ProfileAddSuccessMessage(update)
|
||||
case "fail":
|
||||
c.Talkers.ProfileAddFailureMessage(update)
|
||||
}
|
||||
default:
|
||||
log.Printf(text)
|
||||
}
|
||||
} else {
|
||||
c.Talkers.AnyMessageUnauthorized(update)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Direct messages from user
|
||||
switch {
|
||||
case helloMsg.MatchString(text):
|
||||
if player_raw.Id != 0 {
|
||||
c.Talkers.HelloMessageAuthorized(update, player_raw)
|
||||
} else {
|
||||
c.Talkers.HelloMessageUnauthorized(update)
|
||||
}
|
||||
// Help
|
||||
case helpMsg.MatchString(text):
|
||||
c.Talkers.HelpMessage(update)
|
||||
// Pokememes info
|
||||
case pokedexMsg.MatchString(text):
|
||||
if strings.HasSuffix(text, "1") {
|
||||
c.Talkers.PokememesList(update, 1)
|
||||
} else if strings.HasSuffix(text, "2") {
|
||||
c.Talkers.PokememesList(update, 2)
|
||||
} else if strings.HasSuffix(text, "3") {
|
||||
c.Talkers.PokememesList(update, 3)
|
||||
} else if strings.HasSuffix(text, "4") {
|
||||
c.Talkers.PokememesList(update, 4)
|
||||
} else if strings.HasSuffix(text, "5") {
|
||||
c.Talkers.PokememesList(update, 5)
|
||||
} else {
|
||||
c.Talkers.PokememesList(update, 1)
|
||||
}
|
||||
case pokememeInfoMsg.MatchString(text):
|
||||
c.Talkers.PokememeInfo(update, player_raw)
|
||||
// Profile info
|
||||
case meMsg.MatchString(text):
|
||||
if player_raw.Id != 0 {
|
||||
c.Talkers.ProfileMessage(update, player_raw)
|
||||
} else {
|
||||
c.Talkers.AnyMessageUnauthorized(update)
|
||||
}
|
||||
// Suggestions
|
||||
case bestMsg.MatchString(text):
|
||||
c.Talkers.BestPokememesList(update, player_raw)
|
||||
// Easter eggs
|
||||
case huMsg.MatchString(text):
|
||||
c.Talkers.MatMessage(update)
|
||||
case blMsg.MatchString(text):
|
||||
c.Talkers.MatMessage(update)
|
||||
case ebMsg.MatchString(text):
|
||||
c.Talkers.MatMessage(update)
|
||||
case piMsg.MatchString(text):
|
||||
c.Talkers.MatMessage(update)
|
||||
case durakMsg.MatchString(text):
|
||||
c.Talkers.DurakMessage(update)
|
||||
default:
|
||||
log.Printf("User posted unknown command.")
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
if update.Message.ForwardFrom != nil {
|
||||
if update.Message.ForwardFrom.ID != 360402625 {
|
||||
log.Printf("Forward from another user or bot. Ignoring")
|
||||
} else {
|
||||
log.Printf("Forward from PokememBro bot! Processing...")
|
||||
if player_raw.Id != 0 {
|
||||
switch {
|
||||
case pokememeMsg.MatchString(text):
|
||||
log.Printf("Pokememe posted!")
|
||||
status := c.Parsers.ParsePokememe(text, player_raw)
|
||||
switch status {
|
||||
case "ok":
|
||||
c.Talkers.PokememeAddSuccessMessage(update)
|
||||
case "dup":
|
||||
c.Talkers.PokememeAddDuplicateMessage(update)
|
||||
case "fail":
|
||||
c.Talkers.PokememeAddFailureMessage(update)
|
||||
}
|
||||
case profileMsg.MatchString(text):
|
||||
log.Printf("Profile posted!")
|
||||
status := c.Parsers.ParseProfile(update, player_raw)
|
||||
switch status {
|
||||
case "ok":
|
||||
c.Talkers.ProfileAddSuccessMessage(update)
|
||||
case "fail":
|
||||
c.Talkers.ProfileAddFailureMessage(update)
|
||||
}
|
||||
default:
|
||||
log.Printf(text)
|
||||
}
|
||||
} else {
|
||||
c.Talkers.AnyMessageUnauthorized(update)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Direct messages from user
|
||||
switch {
|
||||
case helloMsg.MatchString(text):
|
||||
if player_raw.Id != 0 {
|
||||
c.Talkers.HelloMessageAuthorized(update, player_raw)
|
||||
} else {
|
||||
c.Talkers.HelloMessageUnauthorized(update)
|
||||
}
|
||||
// Help
|
||||
case helpMsg.MatchString(text):
|
||||
c.Talkers.HelpMessage(update)
|
||||
// Pokememes info
|
||||
case pokedexMsg.MatchString(text):
|
||||
if strings.HasSuffix(text, "1") {
|
||||
c.Talkers.PokememesList(update, 1)
|
||||
} else if strings.HasSuffix(text, "2") {
|
||||
c.Talkers.PokememesList(update, 2)
|
||||
} else if strings.HasSuffix(text, "3") {
|
||||
c.Talkers.PokememesList(update, 3)
|
||||
} else if strings.HasSuffix(text, "4") {
|
||||
c.Talkers.PokememesList(update, 4)
|
||||
} else if strings.HasSuffix(text, "5") {
|
||||
c.Talkers.PokememesList(update, 5)
|
||||
} else {
|
||||
c.Talkers.PokememesList(update, 1)
|
||||
}
|
||||
case pokememeInfoMsg.MatchString(text):
|
||||
c.Talkers.PokememeInfo(update, player_raw)
|
||||
// Profile info
|
||||
case meMsg.MatchString(text):
|
||||
if player_raw.Id != 0 {
|
||||
c.Talkers.ProfileMessage(update, player_raw)
|
||||
} else {
|
||||
c.Talkers.AnyMessageUnauthorized(update)
|
||||
}
|
||||
// Suggestions
|
||||
case bestMsg.MatchString(text):
|
||||
c.Talkers.BestPokememesList(update, player_raw)
|
||||
// Easter eggs
|
||||
case huMsg.MatchString(text):
|
||||
c.Talkers.MatMessage(update)
|
||||
case blMsg.MatchString(text):
|
||||
c.Talkers.MatMessage(update)
|
||||
case ebMsg.MatchString(text):
|
||||
c.Talkers.MatMessage(update)
|
||||
case piMsg.MatchString(text):
|
||||
c.Talkers.MatMessage(update)
|
||||
case durakMsg.MatchString(text):
|
||||
c.Talkers.DurakMessage(update)
|
||||
default:
|
||||
log.Printf("User posted unknown command.")
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
return "ok"
|
||||
return "ok"
|
||||
}
|
||||
|
@ -4,11 +4,11 @@
|
||||
package routerinterface
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
type RouterInterface interface {
|
||||
Init()
|
||||
RouteRequest(update tgbotapi.Update) string
|
||||
Init()
|
||||
RouteRequest(update tgbotapi.Update) string
|
||||
}
|
||||
|
@ -4,46 +4,46 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
// stdlib
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
// 3rd party
|
||||
"math/rand"
|
||||
"time"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func (t *Talkers) DurakMessage(update tgbotapi.Update) {
|
||||
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
||||
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
||||
|
||||
reactions := make([]string, 0)
|
||||
reactions = append(reactions, "Сам такой!",
|
||||
"А ты типа нет?",
|
||||
"Фу, как некультурно!",
|
||||
"Профессор, если вы такой умный, то почему вы такой бедный? /donate",
|
||||
"Попка – не дурак, Попка – самый непадающий бот!")
|
||||
reactions := make([]string, 0)
|
||||
reactions = append(reactions, "Сам такой!",
|
||||
"А ты типа нет?",
|
||||
"Фу, как некультурно!",
|
||||
"Профессор, если вы такой умный, то почему вы такой бедный? /donate",
|
||||
"Попка – не дурак, Попка – самый непадающий бот!")
|
||||
|
||||
// Praise the Random Gods!
|
||||
rand.Seed(time.Now().Unix())
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, reactions[rand.Intn(len(reactions))])
|
||||
msg.ReplyToMessageID = update.Message.MessageID
|
||||
// Praise the Random Gods!
|
||||
rand.Seed(time.Now().Unix())
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, reactions[rand.Intn(len(reactions))])
|
||||
msg.ReplyToMessageID = update.Message.MessageID
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
||||
func (t *Talkers) MatMessage(update tgbotapi.Update) {
|
||||
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
||||
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
||||
|
||||
reactions := make([]string, 0)
|
||||
reactions = append(reactions, "Фу, как некультурно!",
|
||||
"Иди рот с мылом помой",
|
||||
"Тшшшш!",
|
||||
"Да я твою мамку в кино водил!",
|
||||
reactions := make([]string, 0)
|
||||
reactions = append(reactions, "Фу, как некультурно!",
|
||||
"Иди рот с мылом помой",
|
||||
"Тшшшш!",
|
||||
"Да я твою мамку в кино водил!",
|
||||
"Приятно пообщаться с умным собеседником. К тебе это не относится.")
|
||||
|
||||
// Praise the Random Gods!
|
||||
rand.Seed(time.Now().Unix())
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, reactions[rand.Intn(len(reactions))])
|
||||
msg.ReplyToMessageID = update.Message.MessageID
|
||||
// Praise the Random Gods!
|
||||
rand.Seed(time.Now().Unix())
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, reactions[rand.Intn(len(reactions))])
|
||||
msg.ReplyToMessageID = update.Message.MessageID
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
@ -4,26 +4,26 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func (t *Talkers) AnyMessageUnauthorized(update tgbotapi.Update) {
|
||||
error_message := "Извини, действие для тебя недоступно. Возможно, у меня нет твоего профиля или же твои права недостаточны для совершения данного действия\n\n"
|
||||
error_message += "Если тебе кажется, что это ошибка, пиши @fat0troll.\n"
|
||||
error_message := "Извини, действие для тебя недоступно. Возможно, у меня нет твоего профиля или же твои права недостаточны для совершения данного действия\n\n"
|
||||
error_message += "Если тебе кажется, что это ошибка, пиши @fat0troll.\n"
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, error_message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, error_message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
||||
func (t *Talkers) GetterError(update tgbotapi.Update) {
|
||||
error_message := "Ой, внутренняя ошибка в боте :(\n\n"
|
||||
error_message += "Напиши @fat0troll, приложив форвардом последние сообщения до этого.\n"
|
||||
error_message := "Ой, внутренняя ошибка в боте :(\n\n"
|
||||
error_message += "Напиши @fat0troll, приложив форвардом последние сообщения до этого.\n"
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, error_message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, error_message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
@ -4,25 +4,25 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../appcontext"
|
||||
"../talkers/talkersinterface"
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"../appcontext"
|
||||
"../talkers/talkersinterface"
|
||||
)
|
||||
|
||||
var (
|
||||
c *appcontext.Context
|
||||
c *appcontext.Context
|
||||
)
|
||||
|
||||
type Talkers struct {}
|
||||
type Talkers struct{}
|
||||
|
||||
func New(ac *appcontext.Context) {
|
||||
c = ac
|
||||
m := &Talkers{}
|
||||
c.RegisterTalkersInterface(talkersinterface.TalkersInterface(m))
|
||||
c = ac
|
||||
m := &Talkers{}
|
||||
c.RegisterTalkersInterface(talkersinterface.TalkersInterface(m))
|
||||
}
|
||||
|
||||
func (t *Talkers) Init() {
|
||||
log.Printf("Initializing responders...")
|
||||
log.Printf("Initializing responders...")
|
||||
}
|
||||
|
@ -4,30 +4,30 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
func (t *Talkers) HelloMessageUnauthorized(update tgbotapi.Update) {
|
||||
hello_message := "*Бот Инстинкта приветствует тебя!*\n\n"
|
||||
hello_message += "Для начала работы с ботом, пожалуйста, перешли от бота игры @PokememBroBot профиль героя.\n"
|
||||
hello_message += "Все дальнейшие действия с ботом возможны лишь при наличии профиля игрока."
|
||||
hello_message := "*Бот Инстинкта приветствует тебя!*\n\n"
|
||||
hello_message += "Для начала работы с ботом, пожалуйста, перешли от бота игры @PokememBroBot профиль героя.\n"
|
||||
hello_message += "Все дальнейшие действия с ботом возможны лишь при наличии профиля игрока."
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, hello_message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, hello_message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
||||
func (t *Talkers) HelloMessageAuthorized(update tgbotapi.Update, player_raw dbmapping.Player) {
|
||||
hello_message := "*Бот Инстинкта приветствует тебя. Снова.*\n\n"
|
||||
hello_message += "Привет, " + update.Message.From.FirstName + " " + update.Message.From.LastName + "!\n"
|
||||
hello_message := "*Бот Инстинкта приветствует тебя. Снова.*\n\n"
|
||||
hello_message += "Привет, " + update.Message.From.FirstName + " " + update.Message.From.LastName + "!\n"
|
||||
hello_message += "Последнее обновление информации о тебе: " + player_raw.Updated_at.Format("02.01.2006 15:04:05 -0700")
|
||||
hello_message += "\nПосмотреть информацию о себе: /me"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, hello_message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, hello_message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
@ -4,25 +4,25 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../config"
|
||||
// local
|
||||
"../config"
|
||||
)
|
||||
|
||||
func (t *Talkers) HelpMessage(update tgbotapi.Update) {
|
||||
help_message := "*Бот Инстинкта Enchanched.*\n\n"
|
||||
help_message += "Текущая версия: *" + config.VERSION + "*\n\n"
|
||||
help_message += "Список команд:\n\n"
|
||||
help_message := "*Бот Инстинкта Enchanched.*\n\n"
|
||||
help_message += "Текущая версия: *" + config.VERSION + "*\n\n"
|
||||
help_message += "Список команд:\n\n"
|
||||
help_message += "+ /me – посмотреть свой сохраненный профиль в боте\n"
|
||||
help_message += "+ /best – посмотреть лучших покемонов для поимки\n"
|
||||
help_message += "+ /best – посмотреть лучших покемонов для поимки\n"
|
||||
help_message += "+ /pokedeks – получить список известных боту покемемов\n"
|
||||
help_message += "+ /help – выводит данное сообщение\n"
|
||||
help_message += "\n\n"
|
||||
help_message += "Связаться с автором: @fat0troll\n"
|
||||
help_message += "+ /help – выводит данное сообщение\n"
|
||||
help_message += "\n\n"
|
||||
help_message += "Связаться с автором: @fat0troll\n"
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, help_message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, help_message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"strconv"
|
||||
"strings"
|
||||
"strconv"
|
||||
// 3rd party
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../dbmapping"
|
||||
@ -16,123 +16,123 @@ import (
|
||||
// Internal functions
|
||||
|
||||
func (t *Talkers) pokememesListing(update tgbotapi.Update, page int, pokememes_full []dbmapping.PokememeFull) {
|
||||
message := "*Известные боту покемемы*\n"
|
||||
message += "Список отсортирован по грейду и алфавиту.\n"
|
||||
message += "Покедекс: " + strconv.Itoa(len(pokememes_full)) + " / 206\n"
|
||||
message += "Отображаем покемемов с " + strconv.Itoa(((page - 1)*50)+1) + " по " + strconv.Itoa(page*50) + "\n"
|
||||
if len(pokememes_full) > page*50 {
|
||||
message += "Переход на следующую страницу: /pokedeks" + strconv.Itoa(page + 1)
|
||||
}
|
||||
if page > 1 {
|
||||
message += "\nПереход на предыдущую страницу: /pokedeks" + strconv.Itoa(page - 1)
|
||||
}
|
||||
message += "\n\n"
|
||||
message := "*Известные боту покемемы*\n"
|
||||
message += "Список отсортирован по грейду и алфавиту.\n"
|
||||
message += "Покедекс: " + strconv.Itoa(len(pokememes_full)) + " / 206\n"
|
||||
message += "Отображаем покемемов с " + strconv.Itoa(((page-1)*50)+1) + " по " + strconv.Itoa(page*50) + "\n"
|
||||
if len(pokememes_full) > page*50 {
|
||||
message += "Переход на следующую страницу: /pokedeks" + strconv.Itoa(page+1)
|
||||
}
|
||||
if page > 1 {
|
||||
message += "\nПереход на предыдущую страницу: /pokedeks" + strconv.Itoa(page-1)
|
||||
}
|
||||
message += "\n\n"
|
||||
|
||||
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
|
||||
message += strconv.Itoa(i + 1) + ". " + strconv.Itoa(pk.Grade)
|
||||
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) {
|
||||
message += pk_e[j].Symbol
|
||||
}
|
||||
message += "] " + c.Parsers.ReturnPoints(pk.Price) + "$ /pk" + strconv.Itoa(pk.Id)
|
||||
message += "\n"
|
||||
}
|
||||
}
|
||||
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
|
||||
message += strconv.Itoa(i+1) + ". " + strconv.Itoa(pk.Grade)
|
||||
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 {
|
||||
message += pk_e[j].Symbol
|
||||
}
|
||||
message += "] " + c.Parsers.ReturnPoints(pk.Price) + "$ /pk" + strconv.Itoa(pk.Id)
|
||||
message += "\n"
|
||||
}
|
||||
}
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
|
||||
}
|
||||
|
||||
// External functions
|
||||
|
||||
func (t *Talkers) PokememesList(update tgbotapi.Update, page int) {
|
||||
pokememes_full, ok := c.Getters.GetPokememes()
|
||||
if !ok {
|
||||
t.GetterError(update)
|
||||
} else {
|
||||
t.pokememesListing(update, page, pokememes_full)
|
||||
}
|
||||
pokememes_full, ok := c.Getters.GetPokememes()
|
||||
if !ok {
|
||||
t.GetterError(update)
|
||||
} else {
|
||||
t.pokememesListing(update, page, pokememes_full)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Talkers) PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Player) string {
|
||||
pokememe_number := strings.Replace(update.Message.Text, "/pk", "", 1)
|
||||
var calculate_possibilites bool = true
|
||||
profile_raw, ok := c.Getters.GetProfile(player_raw.Id)
|
||||
if !ok {
|
||||
calculate_possibilites = false
|
||||
}
|
||||
pokememe_number := strings.Replace(update.Message.Text, "/pk", "", 1)
|
||||
var calculate_possibilites bool = true
|
||||
profile_raw, ok := c.Getters.GetProfile(player_raw.Id)
|
||||
if !ok {
|
||||
calculate_possibilites = false
|
||||
}
|
||||
|
||||
pokememe, ok := c.Getters.GetPokememeByID(pokememe_number)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
pokememe, ok := c.Getters.GetPokememeByID(pokememe_number)
|
||||
if !ok {
|
||||
return "fail"
|
||||
}
|
||||
|
||||
pk := pokememe.Pokememe
|
||||
pk := pokememe.Pokememe
|
||||
|
||||
message := strconv.Itoa(pk.Grade) + "⃣ *" + pk.Name + "*\n"
|
||||
message += pk.Description + "\n\n"
|
||||
message += "Элементы:"
|
||||
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) {
|
||||
message += "*\n🛡Защита: *" + c.Parsers.ReturnPoints(pk.Defence) + "* _(сопротивляемость покемема к поимке)_"
|
||||
} else {
|
||||
message += "*"
|
||||
}
|
||||
message += "\nСтоимость: *" + c.Parsers.ReturnPoints(pk.Price)
|
||||
message += "*\nКупить: *"
|
||||
if pk.Purchaseable {
|
||||
message += "Можно"
|
||||
} else {
|
||||
message += "Нельзя"
|
||||
}
|
||||
message += "*\nОбитает:"
|
||||
for i := range(pokememe.Locations) {
|
||||
message += " *" + pokememe.Locations[i].Name + "*"
|
||||
if (i + 1) < len(pokememe.Locations) {
|
||||
message += ","
|
||||
}
|
||||
}
|
||||
message := strconv.Itoa(pk.Grade) + "⃣ *" + pk.Name + "*\n"
|
||||
message += pk.Description + "\n\n"
|
||||
message += "Элементы:"
|
||||
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 {
|
||||
message += "*\n🛡Защита: *" + c.Parsers.ReturnPoints(pk.Defence) + "* _(сопротивляемость покемема к поимке)_"
|
||||
} else {
|
||||
message += "*"
|
||||
}
|
||||
message += "\nСтоимость: *" + c.Parsers.ReturnPoints(pk.Price)
|
||||
message += "*\nКупить: *"
|
||||
if pk.Purchaseable {
|
||||
message += "Можно"
|
||||
} else {
|
||||
message += "Нельзя"
|
||||
}
|
||||
message += "*\nОбитает:"
|
||||
for i := range pokememe.Locations {
|
||||
message += " *" + pokememe.Locations[i].Name + "*"
|
||||
if (i + 1) < len(pokememe.Locations) {
|
||||
message += ","
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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) + "% или "
|
||||
message += strconv.Itoa(pokeballs) + "⭕"
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
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) + "% или "
|
||||
message += strconv.Itoa(pokeballs) + "⭕"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message += "\n" + pk.Image_url
|
||||
message += "\n" + pk.Image_url
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
keyboard := tgbotapi.InlineKeyboardMarkup{}
|
||||
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)
|
||||
keyboard.InlineKeyboard = append(keyboard.InlineKeyboard, row)
|
||||
}
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
keyboard := tgbotapi.InlineKeyboardMarkup{}
|
||||
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)
|
||||
keyboard.InlineKeyboard = append(keyboard.InlineKeyboard, row)
|
||||
}
|
||||
|
||||
msg.ReplyMarkup = keyboard
|
||||
msg.ParseMode = "Markdown"
|
||||
msg.ReplyMarkup = keyboard
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
|
||||
return "ok"
|
||||
return "ok"
|
||||
}
|
||||
|
@ -4,38 +4,38 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func (t *Talkers) PokememeAddSuccessMessage(update tgbotapi.Update) {
|
||||
message := "*Покемем успешно добавлен.*\n\n"
|
||||
message += "Посмотреть всех известных боту покемемов можно командой /pokedeks"
|
||||
message := "*Покемем успешно добавлен.*\n\n"
|
||||
message += "Посмотреть всех известных боту покемемов можно командой /pokedeks"
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
||||
func (t *Talkers) PokememeAddDuplicateMessage(update tgbotapi.Update) {
|
||||
message := "*Мы уже знаем об этом покемеме*\n\n"
|
||||
message += "Посмотреть всех известных боту покемемов можно командой /pokedeks\n\n"
|
||||
message += "Если у покемема изменились описание или характеристики, напиши @fat0troll для обновления базы."
|
||||
message := "*Мы уже знаем об этом покемеме*\n\n"
|
||||
message += "Посмотреть всех известных боту покемемов можно командой /pokedeks\n\n"
|
||||
message += "Если у покемема изменились описание или характеристики, напиши @fat0troll для обновления базы."
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
||||
func (t *Talkers) PokememeAddFailureMessage(update tgbotapi.Update) {
|
||||
message := "*Неудачно получилось :(*\n\n"
|
||||
message += "Случилась жуткая ошибка, и мы не смогли записать покемема в базу. Напиши @fat0troll, он разберется.\n\n"
|
||||
message += "Посмотреть всех известных боту покемемов можно командой /pokedeks"
|
||||
message := "*Неудачно получилось :(*\n\n"
|
||||
message += "Случилась жуткая ошибка, и мы не смогли записать покемема в базу. Напиши @fat0troll, он разберется.\n\n"
|
||||
message += "Посмотреть всех известных боту покемемов можно командой /pokedeks"
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
@ -4,104 +4,103 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"strconv"
|
||||
// 3rd party
|
||||
// stdlib
|
||||
"log"
|
||||
"strconv"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../dbmapping"
|
||||
// local
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
func (t *Talkers) ProfileMessage(update tgbotapi.Update, player_raw dbmapping.Player) string {
|
||||
profile_raw, ok := c.Getters.GetProfile(player_raw.Id)
|
||||
if !ok {
|
||||
c.Talkers.AnyMessageUnauthorized(update)
|
||||
return "fail"
|
||||
}
|
||||
league := dbmapping.League{}
|
||||
err := c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE id=?"), player_raw.League_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
level := dbmapping.Level{}
|
||||
err = c.Db.Get(&level, c.Db.Rebind("SELECT * FROM levels WHERE id=?"), profile_raw.Level_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
weapon := dbmapping.Weapon{}
|
||||
if profile_raw.Weapon_id != 0 {
|
||||
err = c.Db.Get(&weapon, c.Db.Rebind("SELECT * FROM weapons WHERE id=?"), profile_raw.Weapon_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
p_pk := []dbmapping.ProfilePokememe{}
|
||||
err = c.Db.Select(&p_pk, c.Db.Rebind("SELECT * FROM profiles_pokememes WHERE profile_id=?"), profile_raw.Id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
pokememes := []dbmapping.Pokememe{}
|
||||
err = c.Db.Select(&pokememes, c.Db.Rebind("SELECT * FROM pokememes"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
profile_raw, ok := c.Getters.GetProfile(player_raw.Id)
|
||||
if !ok {
|
||||
c.Talkers.AnyMessageUnauthorized(update)
|
||||
return "fail"
|
||||
}
|
||||
league := dbmapping.League{}
|
||||
err := c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE id=?"), player_raw.League_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
level := dbmapping.Level{}
|
||||
err = c.Db.Get(&level, c.Db.Rebind("SELECT * FROM levels WHERE id=?"), profile_raw.Level_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
weapon := dbmapping.Weapon{}
|
||||
if profile_raw.Weapon_id != 0 {
|
||||
err = c.Db.Get(&weapon, c.Db.Rebind("SELECT * FROM weapons WHERE id=?"), profile_raw.Weapon_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
p_pk := []dbmapping.ProfilePokememe{}
|
||||
err = c.Db.Select(&p_pk, c.Db.Rebind("SELECT * FROM profiles_pokememes WHERE profile_id=?"), profile_raw.Id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
pokememes := []dbmapping.Pokememe{}
|
||||
err = c.Db.Select(&pokememes, c.Db.Rebind("SELECT * FROM pokememes"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
attack_pm := 0
|
||||
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)
|
||||
if p_pk[i].Pokememe_rarity == "rare" {
|
||||
single_attack = single_attack * 1.15
|
||||
}
|
||||
attack_pm += int(single_attack)
|
||||
}
|
||||
}
|
||||
}
|
||||
attack_pm := 0
|
||||
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)
|
||||
if p_pk[i].Pokememe_rarity == "rare" {
|
||||
single_attack = single_attack * 1.15
|
||||
}
|
||||
attack_pm += int(single_attack)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message := "*Профиль игрока "
|
||||
message += profile_raw.Nickname + "* (@" + profile_raw.TelegramNickname + ")\n"
|
||||
message += "\nЛига: " + league.Symbol + league.Name
|
||||
message += "\n👤 " + strconv.Itoa(profile_raw.Level_id)
|
||||
message += " | 🎓 " + strconv.Itoa(profile_raw.Exp) + "/" + strconv.Itoa(level.Max_exp)
|
||||
message += " | 🥚 " + strconv.Itoa(profile_raw.Egg_exp) + "/" + strconv.Itoa(level.Max_egg)
|
||||
message += "\n💲" + c.Parsers.ReturnPoints(profile_raw.Wealth)
|
||||
message += " |💎" + strconv.Itoa(profile_raw.Crystalls)
|
||||
message += " |⭕" + strconv.Itoa(profile_raw.Pokeballs)
|
||||
message += "\n⚔Атака: 1 + " + c.Parsers.ReturnPoints(weapon.Power) + " + " + c.Parsers.ReturnPoints(attack_pm) + "\n"
|
||||
|
||||
message := "*Профиль игрока "
|
||||
message += profile_raw.Nickname + "* (@" + profile_raw.TelegramNickname + ")\n"
|
||||
message += "\nЛига: " + league.Symbol + league.Name
|
||||
message += "\n👤 " + strconv.Itoa(profile_raw.Level_id)
|
||||
message += " | 🎓 " + strconv.Itoa(profile_raw.Exp) + "/" + strconv.Itoa(level.Max_exp)
|
||||
message += " | 🥚 " + strconv.Itoa(profile_raw.Egg_exp) + "/" + strconv.Itoa(level.Max_egg)
|
||||
message += "\n💲" + c.Parsers.ReturnPoints(profile_raw.Wealth)
|
||||
message += " |💎" + strconv.Itoa(profile_raw.Crystalls)
|
||||
message += " |⭕" + strconv.Itoa(profile_raw.Pokeballs)
|
||||
message += "\n⚔Атака: 1 + " + c.Parsers.ReturnPoints(weapon.Power) + " + " + c.Parsers.ReturnPoints(attack_pm) + "\n"
|
||||
if profile_raw.Weapon_id != 0 {
|
||||
message += "\n🔫Оружие: " + weapon.Name + " " + c.Parsers.ReturnPoints(weapon.Power) + "⚔"
|
||||
}
|
||||
|
||||
if profile_raw.Weapon_id != 0 {
|
||||
message += "\n🔫Оружие: " + weapon.Name + " " + c.Parsers.ReturnPoints(weapon.Power) + "⚔"
|
||||
}
|
||||
message += "\n🐱Покемемы:"
|
||||
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)
|
||||
if p_pk[i].Pokememe_rarity == "rare" {
|
||||
single_attack = single_attack * 1.15
|
||||
}
|
||||
|
||||
message += "\n🐱Покемемы:"
|
||||
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)
|
||||
if p_pk[i].Pokememe_rarity == "rare" {
|
||||
single_attack = single_attack * 1.15
|
||||
}
|
||||
message += "\n" + strconv.Itoa(pokememes[j].Grade)
|
||||
message += "⃣ " + pokememes[j].Name
|
||||
message += " +" + c.Parsers.ReturnPoints(int(single_attack)) + "⚔"
|
||||
}
|
||||
}
|
||||
}
|
||||
message += "\n\n💳" + strconv.Itoa(player_raw.Telegram_id)
|
||||
message += "\n⏰Последнее обновление профиля: " + profile_raw.Created_at.Format("02.01.2006 15:04:05")
|
||||
message += "\n\nНе забывай обновляться, это важно для получения актуальной информации.\n\n"
|
||||
message += "/best – посмотреть лучших покемемов для поимки"
|
||||
|
||||
message += "\n" + strconv.Itoa(pokememes[j].Grade)
|
||||
message += "⃣ " + pokememes[j].Name
|
||||
message += " +" + c.Parsers.ReturnPoints(int(single_attack)) + "⚔"
|
||||
}
|
||||
}
|
||||
}
|
||||
message += "\n\n💳" + strconv.Itoa(player_raw.Telegram_id)
|
||||
message += "\n⏰Последнее обновление профиля: " + profile_raw.Created_at.Format("02.01.2006 15:04:05")
|
||||
message += "\n\nНе забывай обновляться, это важно для получения актуальной информации.\n\n"
|
||||
message += "/best – посмотреть лучших покемемов для поимки"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
c.Bot.Send(msg)
|
||||
|
||||
c.Bot.Send(msg)
|
||||
|
||||
return "ok"
|
||||
return "ok"
|
||||
}
|
||||
|
@ -4,28 +4,28 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
func (t *Talkers) ProfileAddSuccessMessage(update tgbotapi.Update) {
|
||||
message := "*Профиль успешно обновлен.*\n\n"
|
||||
message += "Функциональность бота держится на актуальности профилей. Обновляйся почаще, и да пребудет с тобой Рандом!\n"
|
||||
message := "*Профиль успешно обновлен.*\n\n"
|
||||
message += "Функциональность бота держится на актуальности профилей. Обновляйся почаще, и да пребудет с тобой Рандом!\n"
|
||||
message += "Сохраненный профиль ты можешь просмотреть командой /me.\n\n"
|
||||
message += "/best – посмотреть лучших покемемов для поимки"
|
||||
message += "/best – посмотреть лучших покемемов для поимки"
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
||||
func (t *Talkers) ProfileAddFailureMessage(update tgbotapi.Update) {
|
||||
message := "*Неудачно получилось :(*\n\n"
|
||||
message += "Случилась жуткая ошибка, и мы не смогли записать профиль в базу. Напиши @fat0troll, он разберется."
|
||||
message := "*Неудачно получилось :(*\n\n"
|
||||
message += "Случилась жуткая ошибка, и мы не смогли записать профиль в базу. Напиши @fat0troll, он разберется."
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
}
|
||||
|
@ -4,55 +4,55 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"strconv"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../dbmapping"
|
||||
// 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"
|
||||
}
|
||||
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"
|
||||
}
|
||||
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"
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||
msg.ParseMode = "Markdown"
|
||||
|
||||
c.Bot.Send(msg)
|
||||
c.Bot.Send(msg)
|
||||
|
||||
return "ok"
|
||||
return "ok"
|
||||
}
|
||||
|
@ -4,35 +4,35 @@
|
||||
package talkersinterface
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../../dbmapping"
|
||||
// local
|
||||
"../../dbmapping"
|
||||
)
|
||||
|
||||
type TalkersInterface interface {
|
||||
Init()
|
||||
// Commands
|
||||
HelloMessageUnauthorized(update tgbotapi.Update)
|
||||
HelloMessageAuthorized(update tgbotapi.Update, player_raw dbmapping.Player)
|
||||
HelpMessage(update tgbotapi.Update)
|
||||
PokememesList(update tgbotapi.Update, page int)
|
||||
Init()
|
||||
// Commands
|
||||
HelloMessageUnauthorized(update tgbotapi.Update)
|
||||
HelloMessageAuthorized(update tgbotapi.Update, player_raw dbmapping.Player)
|
||||
HelpMessage(update tgbotapi.Update)
|
||||
PokememesList(update tgbotapi.Update, page int)
|
||||
PokememeInfo(update tgbotapi.Update, player_raw dbmapping.Player) string
|
||||
BestPokememesList(update tgbotapi.Update, player_raw dbmapping.Player) string
|
||||
BestPokememesList(update tgbotapi.Update, player_raw dbmapping.Player) string
|
||||
|
||||
// Returns
|
||||
PokememeAddSuccessMessage(update tgbotapi.Update)
|
||||
PokememeAddDuplicateMessage(update tgbotapi.Update)
|
||||
PokememeAddFailureMessage(update tgbotapi.Update)
|
||||
ProfileAddSuccessMessage(update tgbotapi.Update)
|
||||
ProfileAddFailureMessage(update tgbotapi.Update)
|
||||
// Returns
|
||||
PokememeAddSuccessMessage(update tgbotapi.Update)
|
||||
PokememeAddDuplicateMessage(update tgbotapi.Update)
|
||||
PokememeAddFailureMessage(update tgbotapi.Update)
|
||||
ProfileAddSuccessMessage(update tgbotapi.Update)
|
||||
ProfileAddFailureMessage(update tgbotapi.Update)
|
||||
ProfileMessage(update tgbotapi.Update, player_raw dbmapping.Player) string
|
||||
|
||||
// Errors
|
||||
AnyMessageUnauthorized(update tgbotapi.Update)
|
||||
GetterError(update tgbotapi.Update)
|
||||
// Errors
|
||||
AnyMessageUnauthorized(update tgbotapi.Update)
|
||||
GetterError(update tgbotapi.Update)
|
||||
|
||||
// Easter eggs
|
||||
DurakMessage(update tgbotapi.Update)
|
||||
MatMessage(update tgbotapi.Update)
|
||||
// Easter eggs
|
||||
DurakMessage(update tgbotapi.Update)
|
||||
MatMessage(update tgbotapi.Update)
|
||||
}
|
||||
|
Reference in New Issue
Block a user