diff --git a/lib/config/config.go b/lib/config/config.go index ea4f1aa..6e69e0a 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -12,7 +12,7 @@ import ( "gopkg.in/yaml.v2" ) -const VERSION = "0.295" +const VERSION = "0.297" // DatabaseConnection handles database connection settings in config.yaml type DatabaseConnection struct { diff --git a/lib/dbmapping/profiles.go b/lib/dbmapping/profiles.go index 1bdb074..51c1133 100644 --- a/lib/dbmapping/profiles.go +++ b/lib/dbmapping/profiles.go @@ -17,6 +17,7 @@ type Profile struct { LevelID int `db:"level_id"` Pokeballs int `db:"pokeballs"` Wealth int `db:"wealth"` + PokememesWealth int `db:"pokememes_wealth"` Exp int `db:"exp"` EggExp int `db:"egg_exp"` Power int `db:"power"` diff --git a/lib/dbmapping/profiles_pokememes.go b/lib/dbmapping/profiles_pokememes.go index 71806ce..d18b0bb 100644 --- a/lib/dbmapping/profiles_pokememes.go +++ b/lib/dbmapping/profiles_pokememes.go @@ -13,7 +13,7 @@ type ProfilePokememe struct { ID int `db:"id"` ProfileID int `db:"profile_id"` PokememeID int `db:"pokememe_id"` - PokememeLevel int `db:"pokememe_lvl"` + PokememeAttack int `db:"pokememe_attack"` PokememeRarity string `db:"pokememe_rarity"` CreatedAt time.Time `db:"created_at"` } diff --git a/lib/migrations/17_change_profile_pokememes_columns.go b/lib/migrations/17_change_profile_pokememes_columns.go new file mode 100644 index 0000000..947ebe1 --- /dev/null +++ b/lib/migrations/17_change_profile_pokememes_columns.go @@ -0,0 +1,37 @@ +// i2_bot – Instinct PokememBro Bot +// Copyright (c) 2017 Vladimir "fat0troll" Hodakov + +package migrations + +import ( + // stdlib + "database/sql" +) + +func ChangeProfilePokememesColumnsUp(tx *sql.Tx) error { + _, err := tx.Exec("ALTER TABLE `profiles_pokememes` ADD COLUMN `pokememe_attack` INT(11) NOT NULL DEFAULT 0 COMMENT 'Атака покемема' AFTER `pokememe_id`;;") + if err != nil { + return err + } + + _, err = tx.Exec("ALTER TABLE `profiles_pokememes` DROP COLUMN `pokememe_lvl`;") + if err != nil { + return err + } + + return nil +} + +func ChangeProfilePokememesColumnsDown(tx *sql.Tx) error { + _, err := tx.Exec("ALTER TABLE `profiles_pokememes` ADD COLUMN `pokememe_lvl` INT(11) NOT NULL DEFAULT 0 COMMENT 'Уровень покемема' AFTER `pokememe_id`;;") + if err != nil { + return err + } + + _, err = tx.Exec("ALTER TABLE `profiles_pokememes` DROP COLUMN `pokememe_attack`;") + if err != nil { + return err + } + + return nil +} diff --git a/lib/migrations/18_add_pokememes_wealth.go b/lib/migrations/18_add_pokememes_wealth.go new file mode 100644 index 0000000..836b475 --- /dev/null +++ b/lib/migrations/18_add_pokememes_wealth.go @@ -0,0 +1,27 @@ +// i2_bot – Instinct PokememBro Bot +// Copyright (c) 2017 Vladimir "fat0troll" Hodakov + +package migrations + +import ( + // stdlib + "database/sql" +) + +func AddPokememesWealthUp(tx *sql.Tx) error { + _, err := tx.Exec("ALTER TABLE `profiles` ADD COLUMN `pokememes_wealth` INT(11) NOT NULL DEFAULT 0 COMMENT 'Стоимость покемонов на руках' AFTER `wealth`;") + if err != nil { + return err + } + + return nil +} + +func AddPokememesWealthDown(tx *sql.Tx) error { + _, err := tx.Exec("ALTER TABLE `profiles` DROP COLUMN `pokememes_wealth`;") + if err != nil { + return err + } + + return nil +} diff --git a/lib/migrations/migrations.go b/lib/migrations/migrations.go index 46c97af..0006f85 100644 --- a/lib/migrations/migrations.go +++ b/lib/migrations/migrations.go @@ -31,6 +31,8 @@ func (m *Migrations) Init() { goose.AddNamedMigration("14_fix_time_element.go", FixTimeElementUp, FixTimeElementDown) goose.AddNamedMigration("15_create_chats.go", CreateChatsUp, CreateChatsDown) goose.AddNamedMigration("16_change_chat_type_column.go", ChangeChatTypeColumnUp, ChangeChatTypeColumnDown) + goose.AddNamedMigration("17_change_profile_pokememes_columns.go", ChangeProfilePokememesColumnsUp, ChangeProfilePokememesColumnsDown) + goose.AddNamedMigration("18_add_pokememes_wealth.go", AddPokememesWealthUp, AddPokememesWealthDown) } func (m *Migrations) Migrate() error { diff --git a/lib/parsers/profile.go b/lib/parsers/profile.go index 0298c00..13765fd 100644 --- a/lib/parsers/profile.go +++ b/lib/parsers/profile.go @@ -25,20 +25,13 @@ func (p *Parsers) fillProfilePokememe(profileID int, meme string, attack string, log.Println(err) } else { attackInt := p.getPoints(attack) - // Improve it. Game's precision is unstable - origAttack := float64(spkRaw.Attack) - if rarity == "rare" { - origAttack = origAttack * 1.1 - } - level := int(float64(attackInt) / origAttack) - ppk := dbmapping.ProfilePokememe{} ppk.ProfileID = profileID ppk.PokememeID = spkRaw.ID - ppk.PokememeLevel = level + ppk.PokememeAttack = attackInt 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) + _, err2 := c.Db.NamedExec("INSERT INTO `profiles_pokememes` VALUES(NULL, :profile_id, :pokememe_id, :pokememe_attack, :pokememe_rarity, :created_at)", &ppk) if err2 != nil { log.Println(err2) } @@ -72,6 +65,8 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe pokeballsInt := 0 wealth := "" wealthInt := 0 + pokememesWealth := "" + pokememesWealthInt := 0 crystalls := "" crystallsInt := 0 weapon := "" @@ -151,13 +146,15 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe } if strings.HasPrefix(currentString, "🐱Покемемы: ") { - pkmnumRx := regexp.MustCompile("\\d+") + pkmnumRx := regexp.MustCompile(`(\d+)(\d|K|M|)`) pkNumArray := pkmnumRx.FindAllString(currentString, -1) - if len(pkNumArray) < 2 { + if len(pkNumArray) < 3 { log.Println("Pokememes count broken") return "fail" } pokememesCount, _ := strconv.Atoi(pkNumArray[0]) + pokememesWealth = pkNumArray[2] + pokememesWealthInt = p.getPoints(pokememesWealth) if pokememesCount > 0 { for pi := 0; pi < pokememesCount; pi++ { pokememeString := string(profileRunesArray[i+1+pi]) @@ -192,6 +189,8 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe log.Println(crystallsInt) log.Printf("Weapon: " + weapon) if len(pokememes) > 0 { + log.Printf("Hand cost: " + pokememesWealth) + log.Println(pokememesWealthInt) for meme, attack := range pokememes { log.Printf(meme + ": " + attack) } @@ -242,6 +241,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe profileRaw.LevelID = levelInt profileRaw.Pokeballs = pokeballsInt profileRaw.Wealth = wealthInt + profileRaw.PokememesWealth = pokememesWealthInt profileRaw.Exp = expInt profileRaw.EggExp = eggexpInt profileRaw.Power = powerInt @@ -249,7 +249,7 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe 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)", &profileRaw) + _, err3 := c.Db.NamedExec("INSERT INTO `profiles` VALUES(NULL, :player_id, :nickname, :telegram_nickname, :level_id, :pokeballs, :wealth, :pokememes_wealth, :exp, :egg_exp, :power, :weapon_id, :crystalls, :created_at)", &profileRaw) if err3 != nil { log.Println(err3) return "fail" @@ -275,6 +275,18 @@ func (p *Parsers) ParseProfile(update tgbotapi.Update, playerRaw dbmapping.Playe rarity = "rare" meme = strings.Replace(meme, "🔸", "", 1) } + if strings.HasPrefix(meme, "🔶") { + rarity = "super rare" + meme = strings.Replace(meme, "🔶", "", 1) + } + if strings.HasPrefix(meme, "🔹") { + rarity = "liber" + meme = strings.Replace(meme, "🔹", "", 1) + } + if strings.HasPrefix(meme, "🔷") { + rarity = "super liber" + meme = strings.Replace(meme, "🔷", "", 1) + } p.fillProfilePokememe(profileRaw.ID, meme, attack, rarity) } diff --git a/lib/talkers/pokedex.go b/lib/talkers/pokedex.go index 113b047..d965bed 100644 --- a/lib/talkers/pokedex.go +++ b/lib/talkers/pokedex.go @@ -18,7 +18,7 @@ import ( func (t *Talkers) pokememesListing(update tgbotapi.Update, page int, pokememesArray []dbmapping.PokememeFull) { message := "*Известные боту покемемы*\n" message += "Список отсортирован по грейду и алфавиту.\n" - message += "Покедекс: " + strconv.Itoa(len(pokememesArray)) + " / 206\n" + message += "Покедекс: " + strconv.Itoa(len(pokememesArray)) + " / 219\n" message += "Отображаем покемемов с " + strconv.Itoa(((page-1)*50)+1) + " по " + strconv.Itoa(page*50) + "\n" if len(pokememesArray) > page*50 { message += "Переход на следующую страницу: /pokedeks" + strconv.Itoa(page+1) diff --git a/lib/talkers/profile.go b/lib/talkers/profile.go index 421c306..8e35f19 100644 --- a/lib/talkers/profile.go +++ b/lib/talkers/profile.go @@ -52,12 +52,8 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, playerRaw dbmapping.Pla for i := range profilePokememes { for j := range pokememes { if profilePokememes[i].PokememeID == pokememes[j].ID { - singleAttack := float64(pokememes[j].Attack) - singleAttack = singleAttack * float64(profilePokememes[i].PokememeLevel) - if profilePokememes[i].PokememeRarity == "rare" { - singleAttack = singleAttack * 1.15 - } - attackPokememes += int(singleAttack) + singleAttack := profilePokememes[i].PokememeAttack + attackPokememes += singleAttack } } } @@ -81,18 +77,13 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, playerRaw dbmapping.Pla for i := range profilePokememes { for j := range pokememes { if profilePokememes[i].PokememeID == pokememes[j].ID { - singleAttack := float64(pokememes[j].Attack) - singleAttack = singleAttack * float64(profilePokememes[i].PokememeLevel) - if profilePokememes[i].PokememeRarity == "rare" { - singleAttack = singleAttack * 1.15 - } - message += "\n" + strconv.Itoa(pokememes[j].Grade) message += "⃣ " + pokememes[j].Name - message += " +" + c.Parsers.ReturnPoints(int(singleAttack)) + "⚔" + message += " +" + c.Parsers.ReturnPoints(profilePokememes[i].PokememeAttack) + "⚔" } } } + message += "\nСтоимость покемемов на руках: " + c.Parsers.ReturnPoints(profileRaw.PokememesWealth) + "$" message += "\n\n💳" + strconv.Itoa(playerRaw.TelegramID) message += "\n⏰Последнее обновление профиля: " + profileRaw.CreatedAt.Format("02.01.2006 15:04:05") message += "\n\nНе забывай обновляться, это важно для получения актуальной информации.\n\n"