Add karma field to players
Karma will be used for inactive users filtering
This commit is contained in:
parent
b8af1740fb
commit
0a5361ee09
@ -38,7 +38,7 @@ func (dc *DataCache) loadPlayers() {
|
||||
// AddPlayer creates new player in database
|
||||
func (dc *DataCache) AddPlayer(player *dbmapping.Player) (int, error) {
|
||||
c.Log.Info("DataCache: Creating new user...")
|
||||
_, err := c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :status, :created_at, :updated_at)", &player)
|
||||
_, err := c.Db.NamedExec("INSERT INTO players VALUES(NULL, :telegram_id, :league_id, :status, :karma, :created_at, :updated_at)", &player)
|
||||
if err != nil {
|
||||
c.Log.Error(err.Error())
|
||||
return 0, err
|
||||
@ -76,6 +76,7 @@ func (dc *DataCache) GetOrCreatePlayerByTelegramID(telegramID int) (*dbmapping.P
|
||||
newPlayer := dbmapping.Player{}
|
||||
newPlayer.TelegramID = telegramID
|
||||
newPlayer.LeagueID = 0
|
||||
newPlayer.Karma = 250
|
||||
newPlayer.Status = "nobody"
|
||||
newPlayer.CreatedAt = time.Now().UTC()
|
||||
newPlayer.UpdatedAt = time.Now().UTC()
|
||||
@ -125,7 +126,7 @@ func (dc *DataCache) GetPlayerByTelegramID(telegramID int) (*dbmapping.Player, e
|
||||
// UpdatePlayerFields writes new fields to player
|
||||
func (dc *DataCache) UpdatePlayerFields(player *dbmapping.Player) (*dbmapping.Player, error) {
|
||||
if dc.players[player.ID] != nil {
|
||||
_, err := c.Db.NamedExec("UPDATE `players` SET league_id=:league_id, status=:status WHERE id=:id", player)
|
||||
_, err := c.Db.NamedExec("UPDATE `players` SET league_id=:league_id, status=:status, karma=:karma WHERE id=:id", player)
|
||||
if err != nil {
|
||||
c.Log.Error(err.Error())
|
||||
return dc.players[player.ID], err
|
||||
|
@ -15,6 +15,7 @@ type Player struct {
|
||||
TelegramID int `db:"telegram_id"`
|
||||
LeagueID int `db:"league_id"`
|
||||
Status string `db:"status"`
|
||||
Karma int `db:"karma"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
29
lib/migrations/35_add_karma_to_players.go
Normal file
29
lib/migrations/35_add_karma_to_players.go
Normal file
@ -0,0 +1,29 @@
|
||||
// i2_bot – Instinct PokememBro Bot
|
||||
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
// AddKarmaToPlayersUp creates `karma` column in `players` table
|
||||
func AddKarmaToPlayersUp(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE `players` ADD COLUMN `karma` INT(11) NOT NULL DEFAULT 250 COMMENT 'Карма игрока' AFTER `status`")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddKarmaToPlayersDown destroys `karma` column
|
||||
func AddKarmaToPlayersDown(tx *sql.Tx) error {
|
||||
_, err := tx.Exec("ALTER TABLE `players` DROP COLUMN `karma`")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -45,6 +45,7 @@ func (m *Migrations) Init() {
|
||||
goose.AddNamedMigration("32_add_is_active_to_pokememes.go", AddIsActiveToPokememesUp, AddIsActiveToPokememesDown)
|
||||
goose.AddNamedMigration("33_delete_datamapped_tables.go", DeleteDataMappedTablesUp, DeleteDataMappedTablesDown)
|
||||
goose.AddNamedMigration("34_delete_pokememes_tables.go", DeletePokememesTablesUp, DeletePokememesTablesDown)
|
||||
goose.AddNamedMigration("35_add_karma_to_players.go", AddKarmaToPlayersUp, AddKarmaToPlayersDown)
|
||||
}
|
||||
|
||||
// Migrate migrates database to current version
|
||||
|
@ -192,6 +192,8 @@ func (u *Users) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Pla
|
||||
}
|
||||
}
|
||||
|
||||
message += "\nКарма: " + strconv.Itoa(playerRaw.Karma)
|
||||
|
||||
message += "\n\n⏰Последнее обновление профиля: " + profileRaw.CreatedAt.Format("02.01.2006 15:04:05")
|
||||
message += "\nНе забывай обновляться, это важно для получения актуальной информации.\n\n"
|
||||
message += "/best – посмотреть лучших покемемов для поимки\n"
|
||||
|
Reference in New Issue
Block a user