From f62aa2093e6e217de172e9be1d9620b3d0d8b3cc Mon Sep 17 00:00:00 2001 From: nefrace Date: Tue, 7 Dec 2021 10:30:23 +0300 Subject: [PATCH] Docker-compose edited, users are saving to db --- .gitignore | 2 +- db/structs.go | 5 +++++ docker-compose.yml | 13 +++++-------- kicker/handlers.go | 4 ++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 5ad2f79..114de3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ bin -.env +*.env .vscode \ No newline at end of file diff --git a/db/structs.go b/db/structs.go index 59ba5f8..794101c 100644 --- a/db/structs.go +++ b/db/structs.go @@ -14,3 +14,8 @@ type User struct { CorrectAnswer int8 `bson:"correct_answer"` IsBanned bool `bson:"is_banned"` } + +type Captcha struct { + MessageId int `bson:"message_id"` + CorrectAnswer int8 `bson:"correct_answer"` +} diff --git a/docker-compose.yml b/docker-compose.yml index 0f9f7b7..e813802 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,13 +8,12 @@ services: depends_on: - mongo env_file: - - .env + - bot.env mongo: image: mongo restart: always - environment: - MONGO_INITDB_ROOT_USERNAME: root - MONGO_INITDB_ROOT_PASSWORD: example + env_file: + - mongo.env ports: - 127.0.0.1:28001:27017 @@ -23,7 +22,5 @@ services: restart: always ports: - 127.0.0.1:8089:8081 - environment: - ME_CONFIG_MONGODB_ADMINUSERNAME: root - ME_CONFIG_MONGODB_ADMINPASSWORD: example - ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/ + env_file: + - mongo.env diff --git a/kicker/handlers.go b/kicker/handlers.go index aba2cc7..55d2c06 100644 --- a/kicker/handlers.go +++ b/kicker/handlers.go @@ -21,6 +21,10 @@ func userJoined(c tb.Context) error { ChatId: m.Chat.ID, CorrectAnswer: 0, } + d := db.GetDatabase() + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + d.NewUser(ctx, user) log.Print(user) str := fmt.Sprintf("%v", user) c.Bot().Send(&tb.User{ID: 60441930}, str)