Move rarely changed data to datamappings, fix profile updating
As result of profile format change, introduced in game update yesterday we need to change profile regexp. As result of some refactoring, rarely changed data removed from database and added to sources of bot.
This commit is contained in:
parent
8d78ef37f1
commit
c9855116da
15
Gopkg.lock
generated
15
Gopkg.lock
generated
@ -73,19 +73,6 @@
|
|||||||
]
|
]
|
||||||
revision = "ff2a66f350cefa5c93a634eadb5d25bb60c85a9c"
|
revision = "ff2a66f350cefa5c93a634eadb5d25bb60c85a9c"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/text"
|
|
||||||
packages = [
|
|
||||||
"internal/gen",
|
|
||||||
"internal/triegen",
|
|
||||||
"internal/ucd",
|
|
||||||
"transform",
|
|
||||||
"unicode/cldr",
|
|
||||||
"unicode/norm"
|
|
||||||
]
|
|
||||||
revision = "e19ae1496984b1c655b8044a65c0300a3c878dd3"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "v2"
|
branch = "v2"
|
||||||
name = "gopkg.in/yaml.v2"
|
name = "gopkg.in/yaml.v2"
|
||||||
@ -95,6 +82,6 @@
|
|||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "99811036e66782056cb66f37e4a2570ac81f0e3da2fe399c4d54d83acc5a368d"
|
inputs-digest = "1f9ca287338c3a5d515174b67ff79568a1e3be9df49bee694fac57d9de9802f9"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# version = "1.0.0"
|
# version = "1.0.0"
|
||||||
#
|
#
|
||||||
# [[constraint]]
|
# [[constraint]]
|
||||||
# name = "github.com/user/project2"
|
# name = "github.com/user/project2"
|
||||||
# branch = "dev"
|
# branch = "dev"
|
||||||
# source = "github.com/myfork/project2"
|
# source = "github.com/myfork/project2"
|
||||||
#
|
#
|
||||||
@ -53,10 +53,6 @@
|
|||||||
name = "github.com/robfig/cron"
|
name = "github.com/robfig/cron"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/text"
|
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
branch = "v2"
|
branch = "v2"
|
||||||
name = "gopkg.in/yaml.v2"
|
name = "gopkg.in/yaml.v2"
|
||||||
|
@ -5,6 +5,7 @@ package datacacheinterface
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,8 +52,11 @@ type DataCacheInterface interface {
|
|||||||
DeletePokememeByID(pokememeID int) error
|
DeletePokememeByID(pokememeID int) error
|
||||||
UpdatePokememe(pokememeData map[string]string, pokememeLocations map[string]string, pokememeElements map[string]string) (int, error)
|
UpdatePokememe(pokememeData map[string]string, pokememeLocations map[string]string, pokememeElements map[string]string) (int, error)
|
||||||
|
|
||||||
GetLeagueBySymbol(symbol string) (*dbmapping.League, error)
|
GetElementByID(elementID int) (*datamapping.Element, error)
|
||||||
|
|
||||||
GetWeaponTypeByID(weaponID int) (*dbmapping.Weapon, error)
|
GetLeagueByID(leagueID int) (*datamapping.League, error)
|
||||||
GetWeaponTypeByName(name string) (*dbmapping.Weapon, error)
|
GetLeagueBySymbol(symbol string) (*datamapping.League, error)
|
||||||
|
|
||||||
|
GetWeaponTypeByID(weaponID int) (*datamapping.Weapon, error)
|
||||||
|
GetWeaponTypeByName(name string) (*datamapping.Weapon, error)
|
||||||
}
|
}
|
||||||
|
@ -5,41 +5,61 @@ package datacache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (dc *DataCache) initElements() {
|
func (dc *DataCache) initElements() {
|
||||||
c.Log.Info("Initializing Elements storage...")
|
c.Log.Info("Initializing Elements storage...")
|
||||||
dc.elements = make(map[int]*dbmapping.Element)
|
dc.elements = make(map[int]*datamapping.Element)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *DataCache) loadElements() {
|
func (dc *DataCache) loadElements() {
|
||||||
c.Log.Info("Load current Elements data from database to DataCache...")
|
c.Log.Info("Load current Elements data to DataCache...")
|
||||||
elements := []dbmapping.Element{}
|
elements := dc.getElements()
|
||||||
err := c.Db.Select(&elements, "SELECT * FROM elements")
|
|
||||||
if err != nil {
|
|
||||||
// This is critical error and we need to stop immediately!
|
|
||||||
c.Log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.elementsMutex.Lock()
|
|
||||||
for i := range elements {
|
for i := range elements {
|
||||||
dc.elements[elements[i].ID] = &elements[i]
|
dc.elements[elements[i].ID] = &elements[i]
|
||||||
}
|
}
|
||||||
c.Log.Info("Loaded elements in DataCache: " + strconv.Itoa(len(dc.elements)))
|
c.Log.Info("Loaded elements in DataCache: " + strconv.Itoa(len(dc.elements)))
|
||||||
dc.elementsMutex.Unlock()
|
}
|
||||||
|
|
||||||
|
func (dc *DataCache) getElements() []datamapping.Element {
|
||||||
|
elements := []datamapping.Element{}
|
||||||
|
|
||||||
|
elements = append(elements, datamapping.Element{1, "👊", "Боевой", 1})
|
||||||
|
elements = append(elements, datamapping.Element{2, "🌀", "Летающий", 1})
|
||||||
|
elements = append(elements, datamapping.Element{3, "💀", "Ядовитый", 1})
|
||||||
|
elements = append(elements, datamapping.Element{4, "🗿", "Каменный", 1})
|
||||||
|
elements = append(elements, datamapping.Element{5, "🔥", "Огненный", 2})
|
||||||
|
elements = append(elements, datamapping.Element{6, "⚡", "Электрический", 2})
|
||||||
|
elements = append(elements, datamapping.Element{7, "💧", "Водяной", 2})
|
||||||
|
elements = append(elements, datamapping.Element{8, "🍀", "Травяной", 2})
|
||||||
|
elements = append(elements, datamapping.Element{9, "💩", "Отважный", 3})
|
||||||
|
elements = append(elements, datamapping.Element{10, "👁", "Психический", 3})
|
||||||
|
elements = append(elements, datamapping.Element{11, "👿", "Тёмный", 3})
|
||||||
|
elements = append(elements, datamapping.Element{12, "⌛", "Времени", 3})
|
||||||
|
|
||||||
|
return elements
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *DataCache) findElementIDBySymbol(symbol string) (int, error) {
|
func (dc *DataCache) findElementIDBySymbol(symbol string) (int, error) {
|
||||||
dc.elementsMutex.Lock()
|
|
||||||
for i := range dc.elements {
|
for i := range dc.elements {
|
||||||
if dc.elements[i].Symbol == symbol {
|
if dc.elements[i].Symbol == symbol {
|
||||||
dc.elementsMutex.Unlock()
|
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.elementsMutex.Unlock()
|
|
||||||
return 0, errors.New("There is no element with symbol = " + symbol)
|
return 0, errors.New("There is no element with symbol = " + symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// External functions
|
||||||
|
|
||||||
|
// GetElementByID returns element with given ID
|
||||||
|
func (dc *DataCache) GetElementByID(elementID int) (*datamapping.Element, error) {
|
||||||
|
if dc.elements[elementID] != nil {
|
||||||
|
return dc.elements[elementID], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("There is no element with ID = " + strconv.Itoa(elementID))
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@ package datacache
|
|||||||
import (
|
import (
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/appcontext"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/appcontext"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/datacache/datacacheinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datacache/datacacheinterface"
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@ -44,18 +45,15 @@ type DataCache struct {
|
|||||||
squadPlayers map[int]map[int]*dbmapping.SquadPlayerFull
|
squadPlayers map[int]map[int]*dbmapping.SquadPlayerFull
|
||||||
squadsMutex sync.Mutex
|
squadsMutex sync.Mutex
|
||||||
|
|
||||||
|
// Non-database data
|
||||||
// Elements
|
// Elements
|
||||||
elements map[int]*dbmapping.Element
|
elements map[int]*datamapping.Element
|
||||||
elementsMutex sync.Mutex
|
|
||||||
// Leagues
|
// Leagues
|
||||||
leagues map[int]*dbmapping.League
|
leagues map[int]*datamapping.League
|
||||||
leaguesMutex sync.Mutex
|
|
||||||
// Locations
|
// Locations
|
||||||
locations map[int]*dbmapping.Location
|
locations map[int]*datamapping.Location
|
||||||
locationsMutex sync.Mutex
|
|
||||||
// Weapons
|
// Weapons
|
||||||
weapons map[int]*dbmapping.Weapon
|
weapons map[int]*datamapping.Weapon
|
||||||
weaponsMutex sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New is an initialization function for appcontext
|
// New is an initialization function for appcontext
|
||||||
|
@ -5,44 +5,53 @@ package datacache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (dc *DataCache) initLeagues() {
|
func (dc *DataCache) initLeagues() {
|
||||||
c.Log.Info("Initializing Leagues storage...")
|
c.Log.Info("Initializing Leagues storage...")
|
||||||
dc.leagues = make(map[int]*dbmapping.League)
|
dc.leagues = make(map[int]*datamapping.League)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *DataCache) loadLeagues() {
|
func (dc *DataCache) loadLeagues() {
|
||||||
c.Log.Info("Load current Leagues data from database to DataCache...")
|
c.Log.Info("Load current Leagues data to DataCache...")
|
||||||
leagues := []dbmapping.League{}
|
leagues := dc.getLeagues()
|
||||||
err := c.Db.Select(&leagues, "SELECT * FROM leagues")
|
|
||||||
if err != nil {
|
|
||||||
// This is critical error and we need to stop immediately!
|
|
||||||
c.Log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.leaguesMutex.Lock()
|
|
||||||
for i := range leagues {
|
for i := range leagues {
|
||||||
dc.leagues[leagues[i].ID] = &leagues[i]
|
dc.leagues[leagues[i].ID] = &leagues[i]
|
||||||
}
|
}
|
||||||
c.Log.Info("Loaded leagues in DataCache: " + strconv.Itoa(len(dc.leagues)))
|
c.Log.Info("Loaded leagues in DataCache: " + strconv.Itoa(len(dc.leagues)))
|
||||||
dc.leaguesMutex.Unlock()
|
}
|
||||||
|
|
||||||
|
func (dc *DataCache) getLeagues() []datamapping.League {
|
||||||
|
leagues := []datamapping.League{}
|
||||||
|
|
||||||
|
leagues = append(leagues, datamapping.League{1, "🈸", "ИНСТИНКТ"})
|
||||||
|
leagues = append(leagues, datamapping.League{2, "🈳 ", "МИСТИКА"})
|
||||||
|
leagues = append(leagues, datamapping.League{3, "🈵", "ОТВАГА"})
|
||||||
|
|
||||||
|
return leagues
|
||||||
}
|
}
|
||||||
|
|
||||||
// External functions
|
// External functions
|
||||||
|
|
||||||
|
// GetLeagueByID returns league from datacache by ID
|
||||||
|
func (dc *DataCache) GetLeagueByID(leagueID int) (*datamapping.League, error) {
|
||||||
|
if dc.leagues[leagueID] != nil {
|
||||||
|
return dc.leagues[leagueID], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("There is no league with ID = " + strconv.Itoa(leagueID))
|
||||||
|
}
|
||||||
|
|
||||||
// GetLeagueBySymbol returns league from datacache by emoji
|
// GetLeagueBySymbol returns league from datacache by emoji
|
||||||
func (dc *DataCache) GetLeagueBySymbol(symbol string) (*dbmapping.League, error) {
|
func (dc *DataCache) GetLeagueBySymbol(symbol string) (*datamapping.League, error) {
|
||||||
dc.leaguesMutex.Lock()
|
|
||||||
for i := range dc.leagues {
|
for i := range dc.leagues {
|
||||||
if dc.leagues[i].Symbol == symbol {
|
if dc.leagues[i].Symbol == symbol {
|
||||||
dc.leaguesMutex.Unlock()
|
|
||||||
return dc.leagues[i], nil
|
return dc.leagues[i], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.leaguesMutex.Unlock()
|
|
||||||
return nil, errors.New("There is no league with symbol = " + symbol)
|
return nil, errors.New("There is no league with symbol = " + symbol)
|
||||||
}
|
}
|
||||||
|
@ -5,41 +5,44 @@ package datacache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (dc *DataCache) initLocations() {
|
func (dc *DataCache) initLocations() {
|
||||||
c.Log.Info("Initializing Locations storage...")
|
c.Log.Info("Initializing Locations storage...")
|
||||||
dc.locations = make(map[int]*dbmapping.Location)
|
dc.locations = make(map[int]*datamapping.Location)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *DataCache) loadLocations() {
|
func (dc *DataCache) loadLocations() {
|
||||||
c.Log.Info("Load current Locations data from database to DataCache...")
|
c.Log.Info("Load current Locations data to DataCache...")
|
||||||
locations := []dbmapping.Location{}
|
locations := dc.getLocations()
|
||||||
err := c.Db.Select(&locations, "SELECT * FROM locations")
|
|
||||||
if err != nil {
|
|
||||||
// This is critical error and we need to stop immediately!
|
|
||||||
c.Log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.locationsMutex.Lock()
|
|
||||||
for i := range locations {
|
for i := range locations {
|
||||||
dc.locations[locations[i].ID] = &locations[i]
|
dc.locations[locations[i].ID] = &locations[i]
|
||||||
}
|
}
|
||||||
c.Log.Info("Loaded locations in DataCache: " + strconv.Itoa(len(dc.locations)))
|
c.Log.Info("Loaded locations in DataCache: " + strconv.Itoa(len(dc.locations)))
|
||||||
dc.locationsMutex.Unlock()
|
}
|
||||||
|
|
||||||
|
func (dc *DataCache) getLocations() []datamapping.Location {
|
||||||
|
locations := []datamapping.Location{}
|
||||||
|
|
||||||
|
locations = append(locations, datamapping.Location{1, "🌲", "Лес"})
|
||||||
|
locations = append(locations, datamapping.Location{2, "⛰", "Горы"})
|
||||||
|
locations = append(locations, datamapping.Location{3, "🚣", "Озеро"})
|
||||||
|
locations = append(locations, datamapping.Location{4, "🏙", "Город"})
|
||||||
|
locations = append(locations, datamapping.Location{5, "🏛", "Катакомбы"})
|
||||||
|
locations = append(locations, datamapping.Location{6, "⛪️", "Кладбище"})
|
||||||
|
|
||||||
|
return locations
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *DataCache) findLocationIDByName(name string) (int, error) {
|
func (dc *DataCache) findLocationIDByName(name string) (int, error) {
|
||||||
dc.locationsMutex.Lock()
|
|
||||||
for i := range dc.locations {
|
for i := range dc.locations {
|
||||||
if dc.locations[i].Name == name {
|
if dc.locations[i].Name == name {
|
||||||
dc.locationsMutex.Unlock()
|
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.locationsMutex.Unlock()
|
|
||||||
return 0, errors.New("There is no location with name = " + name)
|
return 0, errors.New("There is no location with name = " + name)
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ package datacache
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"sort"
|
"sort"
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -46,8 +47,8 @@ func (dc *DataCache) loadPokememes() {
|
|||||||
|
|
||||||
// Filling fullPokememes
|
// Filling fullPokememes
|
||||||
fullPokememe := dbmapping.PokememeFull{}
|
fullPokememe := dbmapping.PokememeFull{}
|
||||||
elementsListed := []dbmapping.Element{}
|
elementsListed := []datamapping.Element{}
|
||||||
locationsListed := []dbmapping.Location{}
|
locationsListed := []datamapping.Location{}
|
||||||
|
|
||||||
for j := range pokememesLocations {
|
for j := range pokememesLocations {
|
||||||
if pokememesLocations[j].PokememeID == pokememes[i].ID {
|
if pokememesLocations[j].PokememeID == pokememes[i].ID {
|
||||||
@ -122,8 +123,8 @@ func (dc *DataCache) AddPokememe(pokememeData map[string]string, pokememeLocatio
|
|||||||
pokememe.PlayerID = creatorID
|
pokememe.PlayerID = creatorID
|
||||||
pokememe.CreatedAt = time.Now().UTC()
|
pokememe.CreatedAt = time.Now().UTC()
|
||||||
|
|
||||||
locations := []dbmapping.Location{}
|
locations := []datamapping.Location{}
|
||||||
elements := []dbmapping.Element{}
|
elements := []datamapping.Element{}
|
||||||
|
|
||||||
for i := range pokememeLocations {
|
for i := range pokememeLocations {
|
||||||
locationID, err := dc.findLocationIDByName(pokememeLocations[i])
|
locationID, err := dc.findLocationIDByName(pokememeLocations[i])
|
||||||
@ -343,8 +344,8 @@ func (dc *DataCache) UpdatePokememe(pokememeData map[string]string, pokememeLoca
|
|||||||
pokememe.PlayerID = creatorID
|
pokememe.PlayerID = creatorID
|
||||||
pokememe.CreatedAt = time.Now().UTC()
|
pokememe.CreatedAt = time.Now().UTC()
|
||||||
|
|
||||||
locations := []dbmapping.Location{}
|
locations := []datamapping.Location{}
|
||||||
elements := []dbmapping.Element{}
|
elements := []datamapping.Element{}
|
||||||
|
|
||||||
for i := range pokememeLocations {
|
for i := range pokememeLocations {
|
||||||
locationID, err := dc.findLocationIDByName(pokememeLocations[i])
|
locationID, err := dc.findLocationIDByName(pokememeLocations[i])
|
||||||
|
@ -5,57 +5,58 @@ package datacache
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (dc *DataCache) initWeapons() {
|
func (dc *DataCache) initWeapons() {
|
||||||
c.Log.Info("Initializing Weapons storage...")
|
c.Log.Info("Initializing Weapons storage...")
|
||||||
dc.weapons = make(map[int]*dbmapping.Weapon)
|
dc.weapons = make(map[int]*datamapping.Weapon)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *DataCache) loadWeapons() {
|
func (dc *DataCache) loadWeapons() {
|
||||||
c.Log.Info("Load current Weapons data from database to DataCache...")
|
c.Log.Info("Load current Weapons data to DataCache...")
|
||||||
weapons := []dbmapping.Weapon{}
|
weapons := dc.getWeapons()
|
||||||
err := c.Db.Select(&weapons, "SELECT * FROM weapons")
|
|
||||||
if err != nil {
|
|
||||||
// This is critical error and we need to stop immediately!
|
|
||||||
c.Log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.weaponsMutex.Lock()
|
|
||||||
for i := range weapons {
|
for i := range weapons {
|
||||||
dc.weapons[weapons[i].ID] = &weapons[i]
|
dc.weapons[weapons[i].ID] = &weapons[i]
|
||||||
}
|
}
|
||||||
c.Log.Info("Loaded weapon types in DataCache: " + strconv.Itoa(len(dc.weapons)))
|
c.Log.Info("Loaded weapon types in DataCache: " + strconv.Itoa(len(dc.weapons)))
|
||||||
dc.weaponsMutex.Unlock()
|
}
|
||||||
|
|
||||||
|
func (dc *DataCache) getWeapons() []datamapping.Weapon {
|
||||||
|
weapons := []datamapping.Weapon{}
|
||||||
|
|
||||||
|
weapons = append(weapons, datamapping.Weapon{1, "Бита", 2, 5})
|
||||||
|
weapons = append(weapons, datamapping.Weapon{2, "Стальная бита", 10, 40})
|
||||||
|
weapons = append(weapons, datamapping.Weapon{3, "Чугунная бита", 200, 500})
|
||||||
|
weapons = append(weapons, datamapping.Weapon{4, "Титановая бита", 2000, 10000})
|
||||||
|
weapons = append(weapons, datamapping.Weapon{5, "Алмазная бита", 10000, 100000})
|
||||||
|
weapons = append(weapons, datamapping.Weapon{6, "Криптонитовая бита", 100000, 500000})
|
||||||
|
weapons = append(weapons, datamapping.Weapon{5, "Буханка из пятёры", 1000000, 5000000})
|
||||||
|
|
||||||
|
return weapons
|
||||||
}
|
}
|
||||||
|
|
||||||
// External functions
|
// External functions
|
||||||
|
|
||||||
// GetWeaponTypeByID returns weapon type from datacache by given ID
|
// GetWeaponTypeByID returns weapon type from datacache by given ID
|
||||||
func (dc *DataCache) GetWeaponTypeByID(weaponID int) (*dbmapping.Weapon, error) {
|
func (dc *DataCache) GetWeaponTypeByID(weaponID int) (*datamapping.Weapon, error) {
|
||||||
dc.weaponsMutex.Lock()
|
|
||||||
if dc.weapons[weaponID] != nil {
|
if dc.weapons[weaponID] != nil {
|
||||||
c.Log.Debug("DataCache: found weapon type with ID = " + strconv.Itoa(weaponID))
|
c.Log.Debug("DataCache: found weapon type with ID = " + strconv.Itoa(weaponID))
|
||||||
dc.weaponsMutex.Unlock()
|
|
||||||
return dc.weapons[weaponID], nil
|
return dc.weapons[weaponID], nil
|
||||||
}
|
}
|
||||||
dc.weaponsMutex.Unlock()
|
|
||||||
return nil, errors.New("There is no weapon type with ID = " + strconv.Itoa(weaponID))
|
return nil, errors.New("There is no weapon type with ID = " + strconv.Itoa(weaponID))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWeaponTypeByName returns weapon type from datacache by weapon name
|
// GetWeaponTypeByName returns weapon type from datacache by weapon name
|
||||||
func (dc *DataCache) GetWeaponTypeByName(name string) (*dbmapping.Weapon, error) {
|
func (dc *DataCache) GetWeaponTypeByName(name string) (*datamapping.Weapon, error) {
|
||||||
dc.weaponsMutex.Lock()
|
|
||||||
for i := range dc.weapons {
|
for i := range dc.weapons {
|
||||||
if strings.HasPrefix(dc.weapons[i].Name, name) {
|
if strings.HasPrefix(dc.weapons[i].Name, name) {
|
||||||
dc.weaponsMutex.Unlock()
|
|
||||||
return dc.weapons[i], nil
|
return dc.weapons[i], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.weaponsMutex.Unlock()
|
|
||||||
return nil, errors.New("There is no weapon type with name = " + name)
|
return nil, errors.New("There is no weapon type with name = " + name)
|
||||||
}
|
}
|
||||||
|
12
lib/datamapping/elements.go
Normal file
12
lib/datamapping/elements.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package datamapping
|
||||||
|
|
||||||
|
// Element is a struct, which represents element data
|
||||||
|
type Element struct {
|
||||||
|
ID int
|
||||||
|
Symbol string
|
||||||
|
Name string
|
||||||
|
LeagueID int
|
||||||
|
}
|
11
lib/datamapping/leagues.go
Normal file
11
lib/datamapping/leagues.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package datamapping
|
||||||
|
|
||||||
|
// League is a struct, which represents league data
|
||||||
|
type League struct {
|
||||||
|
ID int
|
||||||
|
Symbol string
|
||||||
|
Name string
|
||||||
|
}
|
11
lib/datamapping/locations.go
Normal file
11
lib/datamapping/locations.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package datamapping
|
||||||
|
|
||||||
|
// Location is a struct, which represents location data
|
||||||
|
type Location struct {
|
||||||
|
ID int
|
||||||
|
Symbol string
|
||||||
|
Name string
|
||||||
|
}
|
12
lib/datamapping/weapons.go
Normal file
12
lib/datamapping/weapons.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package datamapping
|
||||||
|
|
||||||
|
// Weapon is a struct, which represents weapon data
|
||||||
|
type Weapon struct {
|
||||||
|
ID int
|
||||||
|
Name string
|
||||||
|
Power int
|
||||||
|
Price int
|
||||||
|
}
|
@ -1,17 +0,0 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
||||||
|
|
||||||
package dbmapping
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Element is a struct, which represents `elements` table item in databse.
|
|
||||||
type Element struct {
|
|
||||||
ID int `db:"id"`
|
|
||||||
Symbol string `db:"symbol"`
|
|
||||||
Name string `db:"name"`
|
|
||||||
LeagueID int `db:"league_id"`
|
|
||||||
CreatedAt *time.Time `db:"created_at"`
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
||||||
|
|
||||||
package dbmapping
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// League is a struct, which represents `leagues` table item in databse.
|
|
||||||
type League struct {
|
|
||||||
ID int `db:"id"`
|
|
||||||
Symbol string `db:"symbol"`
|
|
||||||
Name string `db:"name"`
|
|
||||||
CreatedAt *time.Time `db:"created_at"`
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
||||||
|
|
||||||
package dbmapping
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Location is a struct, which represents `locations` table item in databse.
|
|
||||||
type Location struct {
|
|
||||||
ID int `db:"id"`
|
|
||||||
Symbol string `db:"symbol"`
|
|
||||||
Name string `db:"name"`
|
|
||||||
CreatedAt time.Time `db:"created_at"`
|
|
||||||
}
|
|
@ -4,6 +4,7 @@
|
|||||||
package dbmapping
|
package dbmapping
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,6 +22,6 @@ type Player struct {
|
|||||||
type PlayerProfile struct {
|
type PlayerProfile struct {
|
||||||
Player Player
|
Player Player
|
||||||
Profile Profile
|
Profile Profile
|
||||||
League League
|
League datamapping.League
|
||||||
HaveProfile bool
|
HaveProfile bool
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package dbmapping
|
package dbmapping
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,6 +29,6 @@ type Pokememe struct {
|
|||||||
// PokememeFull is a struct for handling pokememe with all informations about locations and elements
|
// PokememeFull is a struct for handling pokememe with all informations about locations and elements
|
||||||
type PokememeFull struct {
|
type PokememeFull struct {
|
||||||
Pokememe Pokememe
|
Pokememe Pokememe
|
||||||
Locations []Location
|
Locations []datamapping.Location
|
||||||
Elements []Element
|
Elements []datamapping.Element
|
||||||
}
|
}
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
||||||
|
|
||||||
package dbmapping
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Weapon is a struct, which represents `weapons` table item in databse.
|
|
||||||
type Weapon struct {
|
|
||||||
ID int `db:"id"`
|
|
||||||
Name string `db:"name"`
|
|
||||||
Power int `db:"power"`
|
|
||||||
Price int `db:"price"`
|
|
||||||
CreatedAt time.Time `db:"created_at"`
|
|
||||||
}
|
|
@ -4,9 +4,9 @@
|
|||||||
package forwarder
|
package forwarder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProcessForward process forwards for single-user chats
|
// ProcessForward process forwards for single-user chats
|
||||||
@ -14,8 +14,8 @@ func (f *Forwarder) ProcessForward(update *tgbotapi.Update, playerRaw *dbmapping
|
|||||||
text := update.Message.Text
|
text := update.Message.Text
|
||||||
// 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\n(.+)(Уровень)(.+)\n`)
|
var profileMsg = regexp.MustCompile(`(Онлайн: )(\d+)(| Турнир: )(.+)\n(.+)\n(.+)\n(👤Уровень)(.+)\n`)
|
||||||
var profileWithEffectsMsg = regexp.MustCompile(`(Онлайн: )(\d+)\n(Турнир через)(.+)\n\n((.*)\n|(.*)\n(.*)\n)(Элементы)(.+)\n(.*)\n(Эффекты)(.*)\n\n(.+)(Уровень)(.+)\n`)
|
var profileWithEffectsMsg = regexp.MustCompile(`(Онлайн: )(\d+)(| Турнир: )(.+)\n(.+)\n(.+)\n(.+)\n(👤Уровень)(.+)\n`)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case pokememeMsg.MatchString(text):
|
case pokememeMsg.MatchString(text):
|
||||||
|
220
lib/migrations/33_delete_datamapped_tables.go
Normal file
220
lib/migrations/33_delete_datamapped_tables.go
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DeleteDataMappedTablesUp drops `locations`, `elements`, `weapons` and `leagues` tables
|
||||||
|
// These tables data is rarely changed, so I decided to hold such data in source code
|
||||||
|
func DeleteDataMappedTablesUp(tx *sql.Tx) error {
|
||||||
|
request := "DROP TABLE IF EXISTS `elements`"
|
||||||
|
_, err := tx.Exec(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
request = "DROP TABLE IF EXISTS `leagues`"
|
||||||
|
_, err = tx.Exec(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
request = "DROP TABLE IF EXISTS `locations`"
|
||||||
|
_, err = tx.Exec(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
request = "DROP TABLE IF EXISTS `weapons`"
|
||||||
|
_, err = tx.Exec(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteDataMappedTablesDown returns old tables with all data
|
||||||
|
func DeleteDataMappedTablesDown(tx *sql.Tx) error {
|
||||||
|
request := "CREATE TABLE `locations` ("
|
||||||
|
request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID локации',"
|
||||||
|
request += "`symbol` varchar(191) COLLATE 'utf8mb4_unicode_520_ci' NOT NULL COMMENT 'Символ локации',"
|
||||||
|
request += "`name` varchar(191) NOT NULL COMMENT 'Имя локации',"
|
||||||
|
request += "`created_at` datetime NOT NULL COMMENT 'Добавлена в базу',"
|
||||||
|
request += "PRIMARY KEY (`id`),"
|
||||||
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
|
request += "KEY `locations_created_at` (`created_at`)"
|
||||||
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Локации';"
|
||||||
|
_, err := tx.Exec(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert locations
|
||||||
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '🌲', 'Лес', NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '⛰', 'Горы', NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '🚣', 'Озеро', NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏙', 'Город', NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏛', 'Катакомбы', NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '⛪', 'Кладбище', NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
request = "CREATE TABLE `elements` ("
|
||||||
|
request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID элемента',"
|
||||||
|
request += "`symbol` varchar(191) COLLATE 'utf8mb4_unicode_520_ci' NOT NULL COMMENT 'Символ элемента',"
|
||||||
|
request += "`name` varchar(191) NOT NULL COMMENT 'Имя элемента',"
|
||||||
|
request += "`league_id` int(11) NOT NULL COMMENT 'ID родной лиги',"
|
||||||
|
request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
||||||
|
request += "PRIMARY KEY (`id`),"
|
||||||
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
|
request += "KEY `elements_created_at` (`created_at`)"
|
||||||
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Элементы';"
|
||||||
|
_, err = tx.Exec(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert elements
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👊', 'Боевой', 1, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🌀', 'Летающий', 1, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💀', 'Ядовитый', 1, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🗿', 'Каменный', 1, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🔥', 'Огненный', 2, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '⚡', 'Электрический', 2, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💧', 'Водяной', 2, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🍀', 'Травяной', 2, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💩', 'Шоколадный', 3, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👁', 'Психический', 3, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👿', 'Темный', 3, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '⌛', 'Времени', 3, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
request = "CREATE TABLE `leagues` ("
|
||||||
|
request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID лиги',"
|
||||||
|
request += "`symbol` varchar(191) COLLATE 'utf8mb4_unicode_520_ci' NOT NULL COMMENT 'Символ лиги',"
|
||||||
|
request += "`name` varchar(191) NOT NULL COMMENT 'Имя лиги',"
|
||||||
|
request += "`created_at` datetime NOT NULL COMMENT 'Добавлена в базу',"
|
||||||
|
request += "PRIMARY KEY (`id`),"
|
||||||
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
|
request += "KEY `leagues_created_at` (`created_at`)"
|
||||||
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Лиги';"
|
||||||
|
_, err = tx.Exec(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert locations
|
||||||
|
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, '🈸', 'ИНСТИНКТ', NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, '🈳', 'ОТВАГА', NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, '🈵', 'МИСТИКА', NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
request = "CREATE TABLE `weapons` ("
|
||||||
|
request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID оружия',"
|
||||||
|
request += "`name` varchar(191) NOT NULL COMMENT 'Название оружия',"
|
||||||
|
request += "`power` int(11) NOT NULL COMMENT 'Атака оружия',"
|
||||||
|
request += "`price` int(11) NOT NULL COMMENT 'Цена в магазине',"
|
||||||
|
request += "`created_at` datetime NOT NULL COMMENT 'Добавлено в базу',"
|
||||||
|
request += "PRIMARY KEY (`id`),"
|
||||||
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
|
request += "KEY `weapons_created_at` (`created_at`)"
|
||||||
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Оружие';"
|
||||||
|
_, err = tx.Exec(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Бита', 2, 5, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Стальная бита', 10, 40, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Чугунная бита ', 200, 500, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Титановая бита', 2000, 10000, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Алмазная бита', 10000, 100000, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Криптонитовая бита', 100000, 500000, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Буханка из пятёры', 1000000, 5000000, NOW());")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -24,29 +24,29 @@ func CreateLocationsUp(tx *sql.Tx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert locations
|
// Insert locations
|
||||||
_, err2 := tx.Exec("INSERT INTO `locations` VALUES(NULL, ':evergreen_tree:', 'Лес', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, ':evergreen_tree:', 'Лес', NOW());")
|
||||||
if err2 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
_, err3 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '⛰', 'Горы', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '⛰', 'Горы', NOW());")
|
||||||
if err3 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
_, err4 := tx.Exec("INSERT INTO `locations` VALUES(NULL, ':rowboat:', 'Озеро', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, ':rowboat:', 'Озеро', NOW());")
|
||||||
if err4 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
_, err5 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏙', 'Город', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏙', 'Город', NOW());")
|
||||||
if err5 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
_, err6 := tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏛', 'Катакомбы', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏛', 'Катакомбы', NOW());")
|
||||||
if err6 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
_, err7 := tx.Exec("INSERT INTO `locations` VALUES(NULL, ':church:', 'Кладбище', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, ':church:', 'Кладбище', NOW());")
|
||||||
if err7 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -25,53 +25,53 @@ func CreateElementsUp(tx *sql.Tx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert elements
|
// Insert elements
|
||||||
_, err2 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '👊', 'Боевой', 1, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👊', 'Боевой', 1, NOW());")
|
||||||
if err2 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
_, err3 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🌀', 'Летающий', 1, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🌀', 'Летающий', 1, NOW());")
|
||||||
if err3 != nil {
|
if err != nil {
|
||||||
return err3
|
return err
|
||||||
}
|
}
|
||||||
_, err4 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '💀', 'Ядовитый', 1, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💀', 'Ядовитый', 1, NOW());")
|
||||||
if err4 != nil {
|
if err != nil {
|
||||||
return err4
|
return err
|
||||||
}
|
}
|
||||||
_, err5 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🗿', 'Каменный', 1, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🗿', 'Каменный', 1, NOW());")
|
||||||
if err5 != nil {
|
if err != nil {
|
||||||
return err5
|
return err
|
||||||
}
|
}
|
||||||
_, err6 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🔥', 'Огненный', 2, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🔥', 'Огненный', 2, NOW());")
|
||||||
if err6 != nil {
|
if err != nil {
|
||||||
return err6
|
return err
|
||||||
}
|
}
|
||||||
_, err7 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '⚡', 'Электрический', 2, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '⚡', 'Электрический', 2, NOW());")
|
||||||
if err7 != nil {
|
if err != nil {
|
||||||
return err7
|
return err
|
||||||
}
|
}
|
||||||
_, err8 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '💧', 'Водяной', 2, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💧', 'Водяной', 2, NOW());")
|
||||||
if err8 != nil {
|
if err != nil {
|
||||||
return err8
|
return err
|
||||||
}
|
}
|
||||||
_, err9 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '🍀', 'Травяной', 2, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🍀', 'Травяной', 2, NOW());")
|
||||||
if err9 != nil {
|
if err != nil {
|
||||||
return err9
|
return err
|
||||||
}
|
}
|
||||||
_, err10 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '💩', 'Шоколадный', 3, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💩', 'Шоколадный', 3, NOW());")
|
||||||
if err10 != nil {
|
if err != nil {
|
||||||
return err10
|
return err
|
||||||
}
|
}
|
||||||
_, err11 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '👁', 'Психический', 3, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👁', 'Психический', 3, NOW());")
|
||||||
if err11 != nil {
|
if err != nil {
|
||||||
return err11
|
return err
|
||||||
}
|
}
|
||||||
_, err12 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '👿', 'Темный', 3, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👿', 'Темный', 3, NOW());")
|
||||||
if err12 != nil {
|
if err != nil {
|
||||||
return err12
|
return err
|
||||||
}
|
}
|
||||||
_, err13 := tx.Exec("INSERT INTO `elements` VALUES(NULL, '⌛', 'Времени', 1, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '⌛', 'Времени', 1, NOW());")
|
||||||
if err13 != nil {
|
if err != nil {
|
||||||
return err13
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -24,17 +24,17 @@ func CreateLeaguesUp(tx *sql.Tx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert locations
|
// Insert locations
|
||||||
_, err2 := tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7533:', 'ИНСТИНКТ', NOW());")
|
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7533:', 'ИНСТИНКТ', NOW());")
|
||||||
if err2 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
_, err3 := tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u6e80', 'ОТВАГА', NOW());")
|
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u6e80', 'ОТВАГА', NOW());")
|
||||||
if err3 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
_, err4 := tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7a7a:', 'МИСТИКА', NOW());")
|
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7a7a:', 'МИСТИКА', NOW());")
|
||||||
if err4 != nil {
|
if err != nil {
|
||||||
return err2
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -43,6 +43,7 @@ func (m *Migrations) Init() {
|
|||||||
goose.AddNamedMigration("30_create_alarms.go", CreateAlarmsUp, CreateAlarmsUp)
|
goose.AddNamedMigration("30_create_alarms.go", CreateAlarmsUp, CreateAlarmsUp)
|
||||||
goose.AddNamedMigration("31_change_squads_table.go", ChangeSquadsTableUp, ChangeSquadsTableDown)
|
goose.AddNamedMigration("31_change_squads_table.go", ChangeSquadsTableUp, ChangeSquadsTableDown)
|
||||||
goose.AddNamedMigration("32_add_is_active_to_pokememes.go", AddIsActiveToPokememesUp, AddIsActiveToPokememesDown)
|
goose.AddNamedMigration("32_add_is_active_to_pokememes.go", AddIsActiveToPokememesUp, AddIsActiveToPokememesDown)
|
||||||
|
goose.AddNamedMigration("33_delete_datamapped_tables.go", DeleteDataMappedTablesUp, DeleteDataMappedTablesDown)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate migrates database to current version
|
// Migrate migrates database to current version
|
||||||
|
@ -6,6 +6,7 @@ package users
|
|||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/datamapping"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -46,7 +47,7 @@ func (u *Users) ParseProfile(update *tgbotapi.Update, playerRaw *dbmapping.Playe
|
|||||||
profileRunesArray = append(profileRunesArray, []rune(profileStringsArray[i]))
|
profileRunesArray = append(profileRunesArray, []rune(profileStringsArray[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
league := dbmapping.League{}
|
league := datamapping.League{}
|
||||||
|
|
||||||
telegramNickname := update.Message.From.UserName
|
telegramNickname := update.Message.From.UserName
|
||||||
nickname := ""
|
nickname := ""
|
||||||
|
@ -117,10 +117,10 @@ func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Pla
|
|||||||
c.Log.Error(err.Error())
|
c.Log.Error(err.Error())
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(update)
|
||||||
}
|
}
|
||||||
league := dbmapping.League{}
|
league, err := c.DataCache.GetLeagueByID(playerRaw.LeagueID)
|
||||||
err = c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE id=?"), playerRaw.LeagueID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log.Error(err)
|
c.Log.Error(err.Error())
|
||||||
|
return c.Talkers.BotError(update)
|
||||||
}
|
}
|
||||||
level := dbmapping.Level{}
|
level := dbmapping.Level{}
|
||||||
err = c.Db.Get(&level, c.Db.Rebind("SELECT * FROM levels WHERE id=?"), profileRaw.LevelID)
|
err = c.Db.Get(&level, c.Db.Rebind("SELECT * FROM levels WHERE id=?"), profileRaw.LevelID)
|
||||||
|
Reference in New Issue
Block a user