Refactoring: now we respect gofmt and have some comments
This commit is contained in:
@@ -13,8 +13,10 @@ var (
|
||||
c *appcontext.Context
|
||||
)
|
||||
|
||||
// Parsers is a function-handling struct for package parsers
|
||||
type Parsers struct{}
|
||||
|
||||
// New is an initialization function for appcontext
|
||||
func New(ac *appcontext.Context) {
|
||||
c = ac
|
||||
p := &Parsers{}
|
||||
|
@@ -10,8 +10,9 @@ import (
|
||||
"../../dbmapping"
|
||||
)
|
||||
|
||||
// ParsersInterface implements Parsers for importing via appcontext.
|
||||
type ParsersInterface interface {
|
||||
ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
ParseProfile(update tgbotapi.Update, player_raw dbmapping.Player) string
|
||||
ParsePokememe(text string, playerRaw dbmapping.Player) string
|
||||
ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Player) string
|
||||
ReturnPoints(points int) string
|
||||
}
|
||||
|
@@ -16,48 +16,49 @@ import (
|
||||
|
||||
// Internal functions
|
||||
|
||||
func (p *Parsers) getPoints(points_str string) int {
|
||||
func (p *Parsers) getPoints(pointsStr string) int {
|
||||
value := 0
|
||||
if strings.HasSuffix(points_str, "K") {
|
||||
value_num := strings.Replace(points_str, "K", "", 1)
|
||||
value_float, _ := strconv.ParseFloat(value_num, 64)
|
||||
value = int(value_float * 1000)
|
||||
} else if strings.HasSuffix(points_str, "M") {
|
||||
value_num := strings.Replace(points_str, "M", "", 1)
|
||||
value_float, _ := strconv.ParseFloat(value_num, 64)
|
||||
value = int(value_float * 1000000)
|
||||
if strings.HasSuffix(pointsStr, "K") {
|
||||
valueNumber := strings.Replace(pointsStr, "K", "", 1)
|
||||
valueFloat, _ := strconv.ParseFloat(valueNumber, 64)
|
||||
value = int(valueFloat * 1000)
|
||||
} else if strings.HasSuffix(pointsStr, "M") {
|
||||
valueNumber := strings.Replace(pointsStr, "M", "", 1)
|
||||
valueFloat, _ := strconv.ParseFloat(valueNumber, 64)
|
||||
value = int(valueFloat * 1000000)
|
||||
} else {
|
||||
value, _ = strconv.Atoi(points_str)
|
||||
value, _ = strconv.Atoi(pointsStr)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// External functions
|
||||
|
||||
func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string {
|
||||
var defendable_pokememe bool = false
|
||||
pokememe_info_strings := strings.Split(text, "\n")
|
||||
pokememe_info_runed_strings := make([][]rune, 0)
|
||||
for i := range pokememe_info_strings {
|
||||
pokememe_info_runed_strings = append(pokememe_info_runed_strings, []rune(pokememe_info_strings[i]))
|
||||
// ParsePokememe parses pokememe, forwarded from PokememeBroBot, to database
|
||||
func (p *Parsers) ParsePokememe(text string, playerRaw dbmapping.Player) string {
|
||||
var defendablePokememe = false
|
||||
pokememeStringsArray := strings.Split(text, "\n")
|
||||
pokememeRunesArray := make([][]rune, 0)
|
||||
for i := range pokememeStringsArray {
|
||||
pokememeRunesArray = append(pokememeRunesArray, []rune(pokememeStringsArray[i]))
|
||||
}
|
||||
|
||||
if len(pokememe_info_runed_strings) == 13 {
|
||||
defendable_pokememe = true
|
||||
if len(pokememeRunesArray) == 13 {
|
||||
defendablePokememe = true
|
||||
}
|
||||
|
||||
// Getting elements
|
||||
elements := []dbmapping.Element{}
|
||||
element_emojis := make([]string, 0)
|
||||
element_emojis = append(element_emojis, string(pokememe_info_runed_strings[4][11]))
|
||||
if len(pokememe_info_runed_strings[4]) > 12 {
|
||||
element_emojis = append(element_emojis, string(pokememe_info_runed_strings[4][13]))
|
||||
elementEmojis := make([]string, 0)
|
||||
elementEmojis = append(elementEmojis, string(pokememeRunesArray[4][11]))
|
||||
if len(pokememeRunesArray[4]) > 12 {
|
||||
elementEmojis = append(elementEmojis, string(pokememeRunesArray[4][13]))
|
||||
}
|
||||
if len(pokememe_info_runed_strings[4]) > 14 {
|
||||
element_emojis = append(element_emojis, string(pokememe_info_runed_strings[4][15]))
|
||||
if len(pokememeRunesArray[4]) > 14 {
|
||||
elementEmojis = append(elementEmojis, string(pokememeRunesArray[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(elementEmojis, "', '")+"')")
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
return "fail"
|
||||
@@ -65,10 +66,10 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
|
||||
// Getting hit-points
|
||||
hitPointsRx := regexp.MustCompile("(\\d|\\.)+(K|M)?")
|
||||
hitPoints := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[5]), -1)
|
||||
hitPoints := hitPointsRx.FindAllString(string(pokememeRunesArray[5]), -1)
|
||||
if len(hitPoints) != 3 {
|
||||
log.Printf("Can't parse hitpoints!")
|
||||
log.Println(pokememe_info_runed_strings[5])
|
||||
log.Println(pokememeRunesArray[5])
|
||||
return "fail"
|
||||
}
|
||||
|
||||
@@ -80,26 +81,26 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
purchaseable := false
|
||||
image := ""
|
||||
|
||||
if defendable_pokememe {
|
||||
if defendablePokememe {
|
||||
// Actions for high-grade pokememes
|
||||
defenceMatch := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[6]), -1)
|
||||
defenceMatch := hitPointsRx.FindAllString(string(pokememeRunesArray[6]), -1)
|
||||
if len(defenceMatch) < 1 {
|
||||
log.Printf("Can't parse defence!")
|
||||
log.Println(pokememe_info_runed_strings[6])
|
||||
log.Println(pokememeRunesArray[6])
|
||||
return "fail"
|
||||
}
|
||||
defence = defenceMatch[0]
|
||||
priceMatch := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[7]), -1)
|
||||
priceMatch := hitPointsRx.FindAllString(string(pokememeRunesArray[7]), -1)
|
||||
if len(priceMatch) < 1 {
|
||||
log.Printf("Can't parse price!")
|
||||
log.Println(pokememe_info_runed_strings[7])
|
||||
log.Println(pokememeRunesArray[7])
|
||||
return "fail"
|
||||
}
|
||||
price = priceMatch[0]
|
||||
locationsPrepare := strings.Split(string(pokememe_info_runed_strings[8]), ": ")
|
||||
locationsPrepare := strings.Split(string(pokememeRunesArray[8]), ": ")
|
||||
if len(locationsPrepare) < 2 {
|
||||
log.Printf("Can't parse locations!")
|
||||
log.Println(pokememe_info_runed_strings[8])
|
||||
log.Println(pokememeRunesArray[8])
|
||||
return "fail"
|
||||
}
|
||||
locationsNames := strings.Split(locationsPrepare[1], ", ")
|
||||
@@ -114,24 +115,24 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
log.Printf(err2.Error())
|
||||
return "fail"
|
||||
}
|
||||
if strings.HasSuffix(string(pokememe_info_runed_strings[9]), "Можно") {
|
||||
if strings.HasSuffix(string(pokememeRunesArray[9]), "Можно") {
|
||||
purchaseable = true
|
||||
}
|
||||
image = strings.Replace(string(pokememe_info_runed_strings[12]), " ", "", -1)
|
||||
image = strings.Replace(string(pokememeRunesArray[12]), " ", "", -1)
|
||||
} else {
|
||||
// Actions for low-grade pokememes
|
||||
defence = hitPoints[0]
|
||||
priceMatch := hitPointsRx.FindAllString(string(pokememe_info_runed_strings[6]), -1)
|
||||
priceMatch := hitPointsRx.FindAllString(string(pokememeRunesArray[6]), -1)
|
||||
if len(priceMatch) < 1 {
|
||||
log.Printf("Can't parse price!")
|
||||
log.Println(pokememe_info_runed_strings[6])
|
||||
log.Println(pokememeRunesArray[6])
|
||||
return "fail"
|
||||
}
|
||||
price = priceMatch[0]
|
||||
locationsPrepare := strings.Split(string(pokememe_info_runed_strings[7]), ": ")
|
||||
locationsPrepare := strings.Split(string(pokememeRunesArray[7]), ": ")
|
||||
if len(locationsPrepare) < 2 {
|
||||
log.Printf("Can't parse locations!")
|
||||
log.Println(pokememe_info_runed_strings[7])
|
||||
log.Println(pokememeRunesArray[7])
|
||||
return "fail"
|
||||
}
|
||||
locationsNames := strings.Split(locationsPrepare[1], ", ")
|
||||
@@ -146,15 +147,15 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
log.Printf(err2.Error())
|
||||
return "fail"
|
||||
}
|
||||
if strings.HasSuffix(string(pokememe_info_runed_strings[8]), "Можно") {
|
||||
if strings.HasSuffix(string(pokememeRunesArray[8]), "Можно") {
|
||||
purchaseable = true
|
||||
}
|
||||
image = strings.Replace(string(pokememe_info_runed_strings[11]), " ", "", -1)
|
||||
image = strings.Replace(string(pokememeRunesArray[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])
|
||||
grade := string(pokememeRunesArray[0][0])
|
||||
name := string(pokememeRunesArray[0][3:])
|
||||
description := string(pokememeRunesArray[1])
|
||||
log.Printf("Pokememe grade: " + grade)
|
||||
log.Printf("Pokememe name: " + name)
|
||||
log.Printf("Pokememe description: " + description)
|
||||
@@ -189,29 +190,29 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
return "dup"
|
||||
}
|
||||
|
||||
grade_int, _ := strconv.Atoi(grade)
|
||||
attack_int := p.getPoints(hitPoints[0])
|
||||
hp_int := p.getPoints(hitPoints[1])
|
||||
mp_int := p.getPoints(hitPoints[2])
|
||||
defence_int := p.getPoints(defence)
|
||||
price_int := p.getPoints(price)
|
||||
gradeInt, _ := strconv.Atoi(grade)
|
||||
attackInt := p.getPoints(hitPoints[0])
|
||||
hpInt := p.getPoints(hitPoints[1])
|
||||
mpInt := p.getPoints(hitPoints[2])
|
||||
defenceInt := p.getPoints(defence)
|
||||
priceInt := p.getPoints(price)
|
||||
|
||||
pokememe.Grade = grade_int
|
||||
pokememe.Grade = gradeInt
|
||||
pokememe.Name = name
|
||||
pokememe.Description = description
|
||||
pokememe.Attack = attack_int
|
||||
pokememe.HP = hp_int
|
||||
pokememe.MP = mp_int
|
||||
pokememe.Defence = defence_int
|
||||
pokememe.Price = price_int
|
||||
pokememe.Attack = attackInt
|
||||
pokememe.HP = hpInt
|
||||
pokememe.MP = mpInt
|
||||
pokememe.Defence = defenceInt
|
||||
pokememe.Price = priceInt
|
||||
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.ImageURL = image
|
||||
pokememe.PlayerID = playerRaw.ID
|
||||
pokememe.CreatedAt = time.Now().UTC()
|
||||
|
||||
_, err4 := c.Db.NamedExec("INSERT INTO pokememes VALUES(NULL, :grade, :name, :description, :attack, :hp, :mp, :defence, :price, :purchaseable, :image_url, :player_id, :created_at)", &pokememe)
|
||||
if err4 != nil {
|
||||
@@ -227,9 +228,9 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
}
|
||||
for i := range elements {
|
||||
link := dbmapping.PokememeElement{}
|
||||
link.Pokememe_id = pokememe.Id
|
||||
link.Element_id = elements[i].Id
|
||||
link.Created_at = time.Now().UTC()
|
||||
link.PokememeID = pokememe.ID
|
||||
link.ElementID = elements[i].ID
|
||||
link.CreatedAt = time.Now().UTC()
|
||||
|
||||
_, err6 := c.Db.NamedExec("INSERT INTO pokememes_elements VALUES(NULL, :pokememe_id, :element_id, :created_at)", &link)
|
||||
if err6 != nil {
|
||||
@@ -239,9 +240,9 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
}
|
||||
for i := range locations {
|
||||
link := dbmapping.PokememeLocation{}
|
||||
link.Pokememe_id = pokememe.Id
|
||||
link.Location_id = locations[i].Id
|
||||
link.Created_at = time.Now().UTC()
|
||||
link.PokememeID = pokememe.ID
|
||||
link.LocationID = locations[i].ID
|
||||
link.CreatedAt = time.Now().UTC()
|
||||
|
||||
_, err7 := c.Db.NamedExec("INSERT INTO pokememes_locations VALUES(NULL, :pokememe_id, :location_id, :created_at)", &link)
|
||||
if err7 != nil {
|
||||
@@ -253,14 +254,16 @@ func (p *Parsers) ParsePokememe(text string, player_raw dbmapping.Player) string
|
||||
return "ok"
|
||||
}
|
||||
|
||||
// ReturnPoints returns to output points (ht, attack, mp...) formatted
|
||||
// like in PokememBroBot itself.
|
||||
func (p *Parsers) ReturnPoints(points int) string {
|
||||
if points < 1000 {
|
||||
return strconv.Itoa(points)
|
||||
} else if points < 1000000 {
|
||||
float_num := float64(points) / 1000.0
|
||||
return strconv.FormatFloat(float_num, 'f', -1, 64) + "K"
|
||||
floatNum := float64(points) / 1000.0
|
||||
return strconv.FormatFloat(floatNum, 'f', -1, 64) + "K"
|
||||
} else {
|
||||
float_num := float64(points) / 1000000.0
|
||||
return strconv.FormatFloat(float_num, 'f', -1, 64) + "M"
|
||||
floatNum := float64(points) / 1000000.0
|
||||
return strconv.FormatFloat(floatNum, 'f', -1, 64) + "M"
|
||||
}
|
||||
}
|
||||
|
@@ -18,26 +18,26 @@ import (
|
||||
|
||||
// Internal functions
|
||||
|
||||
func (p *Parsers) fillProfilePokememe(profile_id int, meme string, attack string, rarity string) {
|
||||
spk_raw := dbmapping.Pokememe{}
|
||||
err := c.Db.Get(&spk_raw, c.Db.Rebind("SELECT * FROM pokememes WHERE name='"+meme+"';"))
|
||||
func (p *Parsers) fillProfilePokememe(profileID int, meme string, attack string, rarity string) {
|
||||
spkRaw := dbmapping.Pokememe{}
|
||||
err := c.Db.Get(&spkRaw, c.Db.Rebind("SELECT * FROM pokememes WHERE name='"+meme+"';"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
attack_int := p.getPoints(attack)
|
||||
attackInt := p.getPoints(attack)
|
||||
// Improve it. Game's precision is unstable
|
||||
orig_attack := float64(spk_raw.Attack)
|
||||
origAttack := float64(spkRaw.Attack)
|
||||
if rarity == "rare" {
|
||||
orig_attack = orig_attack * 1.1
|
||||
origAttack = origAttack * 1.1
|
||||
}
|
||||
level := int(float64(attack_int) / orig_attack)
|
||||
level := int(float64(attackInt) / origAttack)
|
||||
|
||||
ppk := dbmapping.ProfilePokememe{}
|
||||
ppk.Profile_id = profile_id
|
||||
ppk.Pokememe_id = spk_raw.Id
|
||||
ppk.Pokememe_lvl = level
|
||||
ppk.Pokememe_rarity = rarity
|
||||
ppk.Created_at = time.Now().UTC()
|
||||
ppk.ProfileID = profileID
|
||||
ppk.PokememeID = spkRaw.ID
|
||||
ppk.PokememeLevel = level
|
||||
ppk.PokememeRarity = rarity
|
||||
ppk.CreatedAt = time.Now().UTC()
|
||||
_, err2 := c.Db.NamedExec("INSERT INTO `profiles_pokememes` VALUES(NULL, :profile_id, :pokememe_id, :pokememe_lvl, :pokememe_rarity, :created_at)", &ppk)
|
||||
if err2 != nil {
|
||||
log.Println(err2)
|
||||
@@ -47,148 +47,149 @@ func (p *Parsers) fillProfilePokememe(profile_id int, meme string, attack string
|
||||
|
||||
// External functions
|
||||
|
||||
func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Player) string {
|
||||
// ParseProfile parses user profile, forwarded from PokememBroBot, to database
|
||||
func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Player) string {
|
||||
text := update.Message.Text
|
||||
log.Println(text)
|
||||
|
||||
profile_info_strings := strings.Split(text, "\n")
|
||||
profile_info_runed_strings := make([][]rune, 0)
|
||||
for i := range profile_info_strings {
|
||||
profile_info_runed_strings = append(profile_info_runed_strings, []rune(profile_info_strings[i]))
|
||||
profileStringsArray := strings.Split(text, "\n")
|
||||
profileRunesArray := make([][]rune, 0)
|
||||
for i := range profileStringsArray {
|
||||
profileRunesArray = append(profileRunesArray, []rune(profileStringsArray[i]))
|
||||
}
|
||||
|
||||
league := dbmapping.League{}
|
||||
|
||||
telegram_nickname := update.Message.From.UserName
|
||||
telegramNickname := update.Message.From.UserName
|
||||
nickname := ""
|
||||
level := ""
|
||||
level_int := 0
|
||||
levelInt := 0
|
||||
exp := ""
|
||||
exp_int := 0
|
||||
egg_exp := ""
|
||||
egg_exp_int := 0
|
||||
expInt := 0
|
||||
eggexp := ""
|
||||
eggexpInt := 0
|
||||
pokeballs := ""
|
||||
pokeballs_int := 0
|
||||
pokeballsInt := 0
|
||||
wealth := ""
|
||||
wealth_int := 0
|
||||
wealthInt := 0
|
||||
crystalls := ""
|
||||
crystalls_int := 0
|
||||
crystallsInt := 0
|
||||
weapon := ""
|
||||
pokememes := make(map[string]string)
|
||||
power_int := 1
|
||||
powerInt := 1
|
||||
|
||||
// Filling information
|
||||
// We don't know how many strings we got, so we iterating each other
|
||||
for i := range profile_info_runed_strings {
|
||||
current_string := string(profile_info_runed_strings[i])
|
||||
current_runes := profile_info_runed_strings[i]
|
||||
if strings.HasPrefix(current_string, "🈸") || strings.HasPrefix(current_string, "🈳 ") || strings.HasPrefix(current_string, "🈵") {
|
||||
err1 := c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE symbol='"+string(current_runes[0])+"'"))
|
||||
for i := range profileRunesArray {
|
||||
currentString := string(profileRunesArray[i])
|
||||
currentRunes := profileRunesArray[i]
|
||||
if strings.HasPrefix(currentString, "🈸") || strings.HasPrefix(currentString, "🈳 ") || strings.HasPrefix(currentString, "🈵") {
|
||||
err1 := c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE symbol='"+string(currentRunes[0])+"'"))
|
||||
if err1 != nil {
|
||||
log.Println(err1)
|
||||
return "fail"
|
||||
}
|
||||
for j := range current_runes {
|
||||
for j := range currentRunes {
|
||||
if j > 1 {
|
||||
nickname += string(current_runes[j])
|
||||
nickname += string(currentRunes[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(current_string, "👤Уровень:") {
|
||||
if strings.HasPrefix(currentString, "👤Уровень:") {
|
||||
levelRx := regexp.MustCompile("\\d+")
|
||||
level_array := levelRx.FindAllString(current_string, -1)
|
||||
if len(level_array) < 1 {
|
||||
levelArray := levelRx.FindAllString(currentString, -1)
|
||||
if len(levelArray) < 1 {
|
||||
log.Println("Level string broken")
|
||||
return "fail"
|
||||
}
|
||||
level = level_array[0]
|
||||
level_int, _ = strconv.Atoi(level)
|
||||
level = levelArray[0]
|
||||
levelInt, _ = strconv.Atoi(level)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(current_string, "🎓Опыт") {
|
||||
if strings.HasPrefix(currentString, "🎓Опыт") {
|
||||
expRx := regexp.MustCompile("\\d+")
|
||||
exp_array := expRx.FindAllString(current_string, -1)
|
||||
if len(exp_array) < 4 {
|
||||
expArray := expRx.FindAllString(currentString, -1)
|
||||
if len(expArray) < 4 {
|
||||
log.Println("Exp string broken")
|
||||
return "fail"
|
||||
}
|
||||
exp = exp_array[0]
|
||||
exp_int, _ = strconv.Atoi(exp)
|
||||
egg_exp = exp_array[2]
|
||||
egg_exp_int, _ = strconv.Atoi(egg_exp)
|
||||
exp = expArray[0]
|
||||
expInt, _ = strconv.Atoi(exp)
|
||||
eggexp = expArray[2]
|
||||
eggexpInt, _ = strconv.Atoi(eggexp)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(current_string, "⭕Покеболы") {
|
||||
if strings.HasPrefix(currentString, "⭕Покеболы") {
|
||||
pkbRx := regexp.MustCompile("\\d+")
|
||||
pkb_array := pkbRx.FindAllString(current_string, -1)
|
||||
if len(pkb_array) < 2 {
|
||||
pkbArray := pkbRx.FindAllString(currentString, -1)
|
||||
if len(pkbArray) < 2 {
|
||||
log.Println("Pokeballs string broken")
|
||||
return "fail"
|
||||
}
|
||||
pokeballs = pkb_array[1]
|
||||
pokeballs_int, _ = strconv.Atoi(pokeballs)
|
||||
pokeballs = pkbArray[1]
|
||||
pokeballsInt, _ = strconv.Atoi(pokeballs)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(current_string, "💲") {
|
||||
if strings.HasPrefix(currentString, "💲") {
|
||||
wealthRx := regexp.MustCompile("(\\d|\\.|K|M)+")
|
||||
wealth_array := wealthRx.FindAllString(current_string, -1)
|
||||
if len(wealth_array) < 2 {
|
||||
wealthArray := wealthRx.FindAllString(currentString, -1)
|
||||
if len(wealthArray) < 2 {
|
||||
log.Println("Wealth string broken")
|
||||
return "fail"
|
||||
}
|
||||
wealth = wealth_array[0]
|
||||
wealth_int = p.getPoints(wealth)
|
||||
crystalls = wealth_array[1]
|
||||
crystalls_int = p.getPoints(crystalls)
|
||||
wealth = wealthArray[0]
|
||||
wealthInt = p.getPoints(wealth)
|
||||
crystalls = wealthArray[1]
|
||||
crystallsInt = p.getPoints(crystalls)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(current_string, "🔫") {
|
||||
if strings.HasPrefix(currentString, "🔫") {
|
||||
// We need NEXT string!
|
||||
weapon_type_string := strings.Replace(current_string, "🔫 ", "", 1)
|
||||
weaponType := strings.Replace(currentString, "🔫 ", "", 1)
|
||||
wnRx := regexp.MustCompile("(.+)(ита)")
|
||||
weapon = wnRx.FindString(weapon_type_string)
|
||||
weapon = wnRx.FindString(weaponType)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(current_string, "🐱Покемемы: ") {
|
||||
if strings.HasPrefix(currentString, "🐱Покемемы: ") {
|
||||
pkmnumRx := regexp.MustCompile("\\d+")
|
||||
pk_num_array := pkmnumRx.FindAllString(current_string, -1)
|
||||
if len(pk_num_array) < 2 {
|
||||
pkNumArray := pkmnumRx.FindAllString(currentString, -1)
|
||||
if len(pkNumArray) < 2 {
|
||||
log.Println("Pokememes count broken")
|
||||
return "fail"
|
||||
}
|
||||
pokememes_count, _ := strconv.Atoi(pk_num_array[0])
|
||||
if pokememes_count > 0 {
|
||||
for pi := 0; pi < pokememes_count; pi++ {
|
||||
pokememe_string := string(profile_info_runed_strings[i+1+pi])
|
||||
pokememesCount, _ := strconv.Atoi(pkNumArray[0])
|
||||
if pokememesCount > 0 {
|
||||
for pi := 0; pi < pokememesCount; pi++ {
|
||||
pokememeString := string(profileRunesArray[i+1+pi])
|
||||
attackRx := regexp.MustCompile("(\\d|\\.|K|M)+")
|
||||
pk_points_array := attackRx.FindAllString(pokememe_string, -1)
|
||||
pk_attack := pk_points_array[1]
|
||||
pk_name := strings.Split(pokememe_string, "+")[0]
|
||||
pk_name = strings.Replace(pk_name, " ⭐", "", 1)
|
||||
pk_name = strings.TrimSuffix(pk_name, " ")
|
||||
pk_name = strings.Split(pk_name, "⃣ ")[1]
|
||||
pokememes[pk_name] = pk_attack
|
||||
power_int += p.getPoints(pk_attack)
|
||||
pkPointsArray := attackRx.FindAllString(pokememeString, -1)
|
||||
pkAttack := pkPointsArray[1]
|
||||
pkName := strings.Split(pokememeString, "+")[0]
|
||||
pkName = strings.Replace(pkName, " ⭐", "", 1)
|
||||
pkName = strings.TrimSuffix(pkName, " ")
|
||||
pkName = strings.Split(pkName, "⃣ ")[1]
|
||||
pokememes[pkName] = pkAttack
|
||||
powerInt += p.getPoints(pkAttack)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Telegram nickname: " + telegram_nickname)
|
||||
log.Printf("Telegram nickname: " + telegramNickname)
|
||||
log.Printf("Nickname: " + nickname)
|
||||
log.Printf("League: " + league.Name)
|
||||
log.Printf("Level: " + level)
|
||||
log.Println(level_int)
|
||||
log.Println(levelInt)
|
||||
log.Printf("Exp: " + exp)
|
||||
log.Println(exp_int)
|
||||
log.Printf("Egg exp: " + egg_exp)
|
||||
log.Println(egg_exp_int)
|
||||
log.Println(expInt)
|
||||
log.Printf("Egg exp: " + eggexp)
|
||||
log.Println(eggexpInt)
|
||||
log.Printf("Pokeballs: " + pokeballs)
|
||||
log.Println(pokeballs_int)
|
||||
log.Println(pokeballsInt)
|
||||
log.Printf("Wealth: " + wealth)
|
||||
log.Println(wealth_int)
|
||||
log.Println(wealthInt)
|
||||
log.Printf("Crystalls: " + crystalls)
|
||||
log.Println(crystalls_int)
|
||||
log.Println(crystallsInt)
|
||||
log.Printf("Weapon: " + weapon)
|
||||
if len(pokememes) > 0 {
|
||||
for meme, attack := range pokememes {
|
||||
@@ -199,70 +200,70 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
}
|
||||
|
||||
// Information is gathered, let's create profile in database!
|
||||
weapon_raw := dbmapping.Weapon{}
|
||||
err2 := c.Db.Get(&weapon_raw, c.Db.Rebind("SELECT * FROM weapons WHERE name='"+weapon+"'"))
|
||||
weaponRaw := dbmapping.Weapon{}
|
||||
err2 := c.Db.Get(&weaponRaw, c.Db.Rebind("SELECT * FROM weapons WHERE name='"+weapon+"'"))
|
||||
if err2 != nil {
|
||||
log.Println(err2)
|
||||
}
|
||||
|
||||
if player_raw.League_id == 0 {
|
||||
if playerRaw.LeagueID == 0 {
|
||||
// Updating player with league
|
||||
player_raw.League_id = league.Id
|
||||
if player_raw.Status == "nobody" {
|
||||
player_raw.Status = "common"
|
||||
playerRaw.LeagueID = league.ID
|
||||
if playerRaw.Status == "nobody" {
|
||||
playerRaw.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", &playerRaw)
|
||||
if err4 != nil {
|
||||
log.Println(err4)
|
||||
return "fail"
|
||||
}
|
||||
} else if player_raw.League_id != league.Id {
|
||||
} else if playerRaw.LeagueID != league.ID {
|
||||
// Duplicate profile: user changed league, beware!
|
||||
player_raw.League_id = league.Id
|
||||
player_raw.Squad_id = 0
|
||||
player_raw.Status = "league_changed"
|
||||
player_raw.Created_at = time.Now().UTC()
|
||||
_, err5 := c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :squad_id, :status, :created_at, :updated_at)", &player_raw)
|
||||
playerRaw.LeagueID = league.ID
|
||||
playerRaw.SquadID = 0
|
||||
playerRaw.Status = "league_changed"
|
||||
playerRaw.CreatedAt = time.Now().UTC()
|
||||
_, err5 := c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :squad_id, :status, :created_at, :updated_at)", &playerRaw)
|
||||
if err5 != nil {
|
||||
log.Println(err5)
|
||||
return "fail"
|
||||
}
|
||||
err6 := c.Db.Get(&player_raw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id='"+strconv.Itoa(player_raw.Telegram_id)+"' AND league_id='"+strconv.Itoa(league.Id)+"';"))
|
||||
err6 := c.Db.Get(&playerRaw, c.Db.Rebind("SELECT * FROM players WHERE telegram_id='"+strconv.Itoa(playerRaw.TelegramID)+"' AND league_id='"+strconv.Itoa(league.ID)+"';"))
|
||||
if err6 != nil {
|
||||
log.Println(err6)
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
profile_raw := dbmapping.Profile{}
|
||||
profile_raw.Player_id = player_raw.Id
|
||||
profile_raw.Nickname = nickname
|
||||
profile_raw.TelegramNickname = telegram_nickname
|
||||
profile_raw.Level_id = level_int
|
||||
profile_raw.Pokeballs = pokeballs_int
|
||||
profile_raw.Wealth = wealth_int
|
||||
profile_raw.Exp = exp_int
|
||||
profile_raw.Egg_exp = egg_exp_int
|
||||
profile_raw.Power = power_int
|
||||
profile_raw.Weapon_id = weapon_raw.Id
|
||||
profile_raw.Crystalls = crystalls_int
|
||||
profile_raw.Created_at = time.Now().UTC()
|
||||
profileRaw := dbmapping.Profile{}
|
||||
profileRaw.PlayerID = playerRaw.ID
|
||||
profileRaw.Nickname = nickname
|
||||
profileRaw.TelegramNickname = telegramNickname
|
||||
profileRaw.LevelID = levelInt
|
||||
profileRaw.Pokeballs = pokeballsInt
|
||||
profileRaw.Wealth = wealthInt
|
||||
profileRaw.Exp = expInt
|
||||
profileRaw.EggExp = eggexpInt
|
||||
profileRaw.Power = powerInt
|
||||
profileRaw.WeaponID = weaponRaw.ID
|
||||
profileRaw.Crystalls = crystallsInt
|
||||
profileRaw.CreatedAt = 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)", &profileRaw)
|
||||
if err3 != nil {
|
||||
log.Println(err3)
|
||||
return "fail"
|
||||
}
|
||||
|
||||
err8 := c.Db.Get(&profile_raw, c.Db.Rebind("SELECT * FROM profiles WHERE player_id=? AND created_at=?"), profile_raw.Player_id, profile_raw.Created_at)
|
||||
err8 := c.Db.Get(&profileRaw, c.Db.Rebind("SELECT * FROM profiles WHERE player_id=? AND created_at=?"), profileRaw.PlayerID, profileRaw.CreatedAt)
|
||||
if err8 != nil {
|
||||
log.Println(err8)
|
||||
log.Printf("Profile isn't added!")
|
||||
return "fail"
|
||||
}
|
||||
|
||||
player_raw.Updated_at = time.Now().UTC()
|
||||
_, err7 := c.Db.NamedExec("UPDATE `players` SET updated_at=:updated_at WHERE id=:id", &player_raw)
|
||||
playerRaw.UpdatedAt = time.Now().UTC()
|
||||
_, err7 := c.Db.NamedExec("UPDATE `players` SET updated_at=:updated_at WHERE id=:id", &playerRaw)
|
||||
if err7 != nil {
|
||||
log.Println(err7)
|
||||
return "fail"
|
||||
@@ -274,7 +275,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, player_raw dbmapping.Play
|
||||
rarity = "rare"
|
||||
meme = strings.Replace(meme, "🔸", "", 1)
|
||||
}
|
||||
p.fillProfilePokememe(profile_raw.Id, meme, attack, rarity)
|
||||
p.fillProfilePokememe(profileRaw.ID, meme, attack, rarity)
|
||||
}
|
||||
|
||||
return "ok"
|
||||
|
Reference in New Issue
Block a user