From b57cacb4d4e8b4f197e8471f5ad3c5d05a58aa74 Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Sun, 26 Nov 2017 19:38:25 +0400 Subject: [PATCH] Latest game update reflections --- lib/dbmapping/orders_completion.go | 16 +++++++++ lib/migrations/26_create_orders_competions.go | 36 +++++++++++++++++++ lib/migrations/27_add_new_weapon.go | 24 +++++++++++++ lib/migrations/migrations.go | 2 ++ lib/users/parsers.go | 2 +- 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 lib/dbmapping/orders_completion.go create mode 100644 lib/migrations/26_create_orders_competions.go create mode 100644 lib/migrations/27_add_new_weapon.go diff --git a/lib/dbmapping/orders_completion.go b/lib/dbmapping/orders_completion.go new file mode 100644 index 0000000..bb5a641 --- /dev/null +++ b/lib/dbmapping/orders_completion.go @@ -0,0 +1,16 @@ +// i2_bot – Instinct PokememBro Bot +// Copyright (c) 2017 Vladimir "fat0troll" Hodakov + +package dbmapping + +import ( + "time" +) + +// OrderCompletion is a struct, which represents `orders_completions` table item in databse. +type OrderCompletion struct { + ID int `db:"id"` + OrderID int `db:"order_id"` + ExecutorID int `db:"executor_id"` + CreatedAt time.Time `db:"created_at"` +} diff --git a/lib/migrations/26_create_orders_competions.go b/lib/migrations/26_create_orders_competions.go new file mode 100644 index 0000000..9cb860a --- /dev/null +++ b/lib/migrations/26_create_orders_competions.go @@ -0,0 +1,36 @@ +// i2_bot – Instinct PokememBro Bot +// Copyright (c) 2017 Vladimir "fat0troll" Hodakov + +package migrations + +import ( + "database/sql" +) + +// CreateOrdersCompletionsUp creates `orders_completions` table +func CreateOrdersCompletionsUp(tx *sql.Tx) error { + request := "CREATE TABLE `orders_completions` (" + request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID приказа'," + request += "`order_id` int(11) NOT NULL COMMENT 'Выполненный приказ'," + request += "`executor_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 `orders_completions_created_at` (`created_at`)" + request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Исполнение приказов'" + _, err := tx.Exec(request) + if err != nil { + return err + } + + return nil +} + +// CreateOrdersCompletionsDown drops `orders_completions` table +func CreateOrdersCompletionsDown(tx *sql.Tx) error { + _, err := tx.Exec("DROP TABLE `orders_completions`") + if err != nil { + return err + } + return nil +} diff --git a/lib/migrations/27_add_new_weapon.go b/lib/migrations/27_add_new_weapon.go new file mode 100644 index 0000000..c87bda5 --- /dev/null +++ b/lib/migrations/27_add_new_weapon.go @@ -0,0 +1,24 @@ +// i2_bot – Instinct PokememBro Bot +// Copyright (c) 2017 Vladimir "fat0troll" Hodakov + +package migrations + +import ( + // stdlib + "database/sql" +) + +// AddNewWeaponUp adds new weapon, presented on 26.11.2017 +func AddNewWeaponUp(tx *sql.Tx) error { + _, err := tx.Exec("INSERT INTO `weapons` VALUES(NULL, 'Буханка из пятёры', 1000000, 5000000, NOW())") + if err != nil { + return err + } + + return nil +} + +// AddNewWeaponDown does nothing +func AddNewWeaponDown(tx *sql.Tx) error { + return nil +} diff --git a/lib/migrations/migrations.go b/lib/migrations/migrations.go index 2d1710d..1facadf 100644 --- a/lib/migrations/migrations.go +++ b/lib/migrations/migrations.go @@ -36,6 +36,8 @@ func (m *Migrations) Init() { goose.AddNamedMigration("23_add_user_type.go", AddUserTypeUp, AddUserTypeDown) goose.AddNamedMigration("24_create_orders.go", CreateOrdersUp, CreateOrdersDown) goose.AddNamedMigration("25_remove_reusable.go", RemoveReusableUp, RemoveReusableDown) + goose.AddNamedMigration("26_create_orders_completions.go", CreateOrdersCompletionsUp, CreateOrdersCompletionsDown) + goose.AddNamedMigration("27_add_new_weapon.go", AddNewWeaponUp, AddNewWeaponDown) } // Migrate migrates database to current version diff --git a/lib/users/parsers.go b/lib/users/parsers.go index 3acf049..805c01e 100644 --- a/lib/users/parsers.go +++ b/lib/users/parsers.go @@ -150,7 +150,7 @@ func (u *Users) ParseProfile(update *tgbotapi.Update, playerRaw *dbmapping.Playe if strings.HasPrefix(currentString, "🔫") { // We need NEXT string! weaponType := strings.Replace(currentString, "🔫 ", "", 1) - wnRx := regexp.MustCompile("(.+)(ита)") + wnRx := regexp.MustCompile("(.+)(ита|ёры)") weapon = wnRx.FindString(weaponType) }