From c5f04d348f6d3b730fca4ead455f8b551b757328 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Fri, 27 Jun 2025 12:05:55 +0300 Subject: [PATCH] Feat: room expiry --- components/cardword.html | 4 ++-- handlers/actions.go | 4 ++++ models/main.go | 27 ++++++++++++--------------- todos.md | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/components/cardword.html b/components/cardword.html index c94637f..2c55499 100644 --- a/components/cardword.html +++ b/components/cardword.html @@ -5,12 +5,12 @@ style="text-shadow: 0 2px 4px rgba(0,0,0,0.9);"> {{.Word}} {{else}} -
{{.Word}}
{{end}} {{else}} -
{{.Word}} diff --git a/handlers/actions.go b/handlers/actions.go index 6fec1bf..781da4f 100644 --- a/handlers/actions.go +++ b/handlers/actions.go @@ -34,6 +34,10 @@ func saveRoom(room *models.Room) error { return err } memcache.Set(key, data) + // do I need last action here? since room save is kind of an action on itself + // time.Now().Add(time.Hour).Sub(room.LastActionTS) + anHour := int64(216000) // 60 * 60 * 60 + memcache.Expire(key, anHour) return nil } diff --git a/models/main.go b/models/main.go index ed2a552..deb626e 100644 --- a/models/main.go +++ b/models/main.go @@ -64,13 +64,11 @@ type BotPlayer struct { } type Room struct { - ID string `json:"id" db:"id"` - CreatedAt time.Time `json:"created_at" db:"created_at"` - // RoomName string `json:"room_name"` - RoomPass string `json:"room_pass"` - RoomLink string - CreatorName string `json:"creator_name"` - // PlayerList []string `json:"player_list"` + ID string `json:"id" db:"id"` + CreatedAt time.Time `json:"created_at" db:"created_at"` // limit? + RoomPass string `json:"room_pass"` + RoomLink string + CreatorName string `json:"creator_name"` ActionHistory []Action TeamTurn UserTeam RedTeam Team @@ -86,15 +84,14 @@ type Room struct { RedTurn bool // false is blue turn MimeDone bool IsPublic bool - // GameSettings *GameSettings `json:"settings"` - IsRunning bool `json:"is_running"` - Language string `json:"language" example:"en" form:"language"` - RoundTime int32 `json:"round_time"` - // ProgressPct uint32 `json:"progress_pct"` - IsOver bool - TeamWon UserTeam // blue | red + IsRunning bool `json:"is_running"` + Language string `json:"language" example:"en" form:"language"` + RoundTime int32 `json:"round_time"` + IsOver bool + TeamWon UserTeam // blue | red // needed for debug - LogJournal []string + LogJournal []string + LastActionTS time.Time } // FindBotByTeamRole returns bot name if found; otherwise empty string diff --git a/todos.md b/todos.md index 6d0132c..69b514b 100644 --- a/todos.md +++ b/todos.md @@ -1,5 +1,5 @@ ### feats -- auto close room if nothing is going on there (hmm) for ~1h; +- auto close room if nothing is going on there (hmm) for ~1h; + - words database (file) load and form random 25 words; + - different files for each supported lang; - mark cards (instead of opening them (right click?);