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