Fix: timer update [WIP]
This commit is contained in:
@ -1,19 +1,21 @@
|
|||||||
{{define "login"}}
|
{{define "login"}}
|
||||||
<div id="logindiv">
|
<div id="logindiv">
|
||||||
<form class="space-y-4" hx-post="/login" hx-target="#main-content">
|
<form hx-post="/login" hx-target="#main-content" class="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label For="username" class="block text-sm text-center font-medium leading-6 text-white-900">tell us your username (signup|login)</label>
|
<label For="username" class="text-sm text-center font-medium leading-6 text-white-900">tell us your username (signup|login)</label>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<input id="username" name="username" hx-target="#login_notice" hx-swap="outerHTML" hx-post="/check/name" hx-trigger="input changed delay:400ms" autocomplete="username" required class="block w-full rounded-md border-0 bg-white py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 text-center"/>
|
<input id="username" name="username" hx-target="#login_notice" hx-swap="outerHTML" hx-post="/check/name" hx-trigger="input changed delay:400ms" autocomplete="username" required class="text-center rounded-md border-0 bg-white py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 text-center"/>
|
||||||
</div>
|
</div>
|
||||||
<div id="login_notice">this name looks available</div>
|
<div id="login_notice">this name looks available</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label For="password" class="block text-sm font-medium text-center leading-6 text-white-900">password</label>
|
<label For="password" class="text-sm font-medium text-center leading-6 text-white-900">password</label>
|
||||||
<input id="password" name="password" type="password" class="block w-full rounded-md border-0 bg-white py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 text-center"/>
|
<div class="mt-2">
|
||||||
|
<input id="password" name="password" type="password" class="rounded-md border-0 bg-white py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 text-center"/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button type="submit" class="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Sign in</button>
|
<button type="submit" class="justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Sign in</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,7 +23,7 @@ func StartTurnTimer(roomID string, timeLeft uint32) {
|
|||||||
if err := repo.RoomUpdate(context.Background(), room); err != nil {
|
if err := repo.RoomUpdate(context.Background(), room); err != nil {
|
||||||
logger.Error("failed to save room", "error", err)
|
logger.Error("failed to save room", "error", err)
|
||||||
}
|
}
|
||||||
notify(models.NotifyTurnTimerPrefix+room.ID, strconv.FormatUint(uint64(room.Settings.RoundTime), 10))
|
// notify(models.NotifyTurnTimerPrefix+room.ID, strconv.FormatUint(uint64(room.Settings.RoundTime), 10))
|
||||||
notifyBotIfNeeded(room)
|
notifyBotIfNeeded(room)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ func StartTurnTimer(roomID string, timeLeft uint32) {
|
|||||||
notify(models.NotifyTurnTimerPrefix+roomID, strconv.FormatUint(uint64(currentLeft), 10))
|
notify(models.NotifyTurnTimerPrefix+roomID, strconv.FormatUint(uint64(currentLeft), 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
timer.StartTurnTimer(context.Background(), roomID, timeLeft, onTurnEnd, onTick, logger)
|
timer.StartTurnTimer(context.Background(), roomID, int32(timeLeft), onTurnEnd, onTick, logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
func StopTurnTimer(roomID string) {
|
func StopTurnTimer(roomID string) {
|
||||||
|
@ -173,6 +173,7 @@ func (p *openRouterParser) MakePayload(prompt string) io.Reader {
|
|||||||
model := models[int(p.modelIndex)%len(models)]
|
model := models[int(p.modelIndex)%len(models)]
|
||||||
strPayload := fmt.Sprintf(`{
|
strPayload := fmt.Sprintf(`{
|
||||||
"model": "%s",
|
"model": "%s",
|
||||||
|
"max_tokens": 300,
|
||||||
"messages": [
|
"messages": [
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
|
@ -24,10 +24,10 @@ func (b *Bot) StartTurnTimer(timeLeft uint32) {
|
|||||||
if err := repos.RP.RoomUpdate(context.Background(), room); err != nil {
|
if err := repos.RP.RoomUpdate(context.Background(), room); err != nil {
|
||||||
logger.Error("failed to save room", "error", err)
|
logger.Error("failed to save room", "error", err)
|
||||||
}
|
}
|
||||||
broker.Notifier.Notifier <- broker.NotificationEvent{
|
// broker.Notifier.Notifier <- broker.NotificationEvent{
|
||||||
EventName: models.NotifyTurnTimerPrefix + room.ID,
|
// EventName: models.NotifyTurnTimerPrefix + room.ID,
|
||||||
Payload: strconv.FormatUint(uint64(room.Settings.RoundTime), 10),
|
// Payload: strconv.FormatUint(uint64(room.Settings.RoundTime), 10),
|
||||||
}
|
// }
|
||||||
// notifyBotIfNeeded(room)
|
// notifyBotIfNeeded(room)
|
||||||
if botName := room.WhichBotToMove(); botName != "" {
|
if botName := room.WhichBotToMove(); botName != "" {
|
||||||
SignalChanMap[botName] <- true
|
SignalChanMap[botName] <- true
|
||||||
@ -41,7 +41,7 @@ func (b *Bot) StartTurnTimer(timeLeft uint32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timer.StartTurnTimer(context.Background(), b.RoomID, timeLeft, onTurnEnd, onTick, logger)
|
timer.StartTurnTimer(context.Background(), b.RoomID, int32(timeLeft), onTurnEnd, onTick, logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bot) StopTurnTimer() {
|
func (b *Bot) StopTurnTimer() {
|
||||||
|
@ -14,12 +14,12 @@ type TurnEndCallback func(ctx context.Context, roomID string)
|
|||||||
type TickCallback func(ctx context.Context, roomID string, timeLeft uint32)
|
type TickCallback func(ctx context.Context, roomID string, timeLeft uint32)
|
||||||
|
|
||||||
type RoomTimer struct {
|
type RoomTimer struct {
|
||||||
ticker *time.Ticker
|
ticker *time.Ticker
|
||||||
done chan bool
|
done chan bool
|
||||||
roomID string
|
roomID string
|
||||||
onTurnEnd TurnEndCallback
|
onTurnEnd TurnEndCallback
|
||||||
onTick TickCallback
|
onTick TickCallback
|
||||||
log *slog.Logger
|
log *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -28,7 +28,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// StartTurnTimer initializes and starts a new turn timer for a given room.
|
// StartTurnTimer initializes and starts a new turn timer for a given room.
|
||||||
func StartTurnTimer(ctx context.Context, roomID string, timeLeft uint32, onTurnEnd TurnEndCallback, onTick TickCallback, logger *slog.Logger) {
|
func StartTurnTimer(ctx context.Context, roomID string, timeLeft int32, onTurnEnd TurnEndCallback, onTick TickCallback, logger *slog.Logger) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
|
||||||
@ -41,12 +41,12 @@ func StartTurnTimer(ctx context.Context, roomID string, timeLeft uint32, onTurnE
|
|||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
|
|
||||||
rt := &RoomTimer{
|
rt := &RoomTimer{
|
||||||
ticker: ticker,
|
ticker: ticker,
|
||||||
done: done,
|
done: done,
|
||||||
roomID: roomID,
|
roomID: roomID,
|
||||||
onTurnEnd: onTurnEnd,
|
onTurnEnd: onTurnEnd,
|
||||||
onTick: onTick,
|
onTick: onTick,
|
||||||
log: logger,
|
log: logger,
|
||||||
}
|
}
|
||||||
timers[roomID] = rt
|
timers[roomID] = rt
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ func StartTurnTimer(ctx context.Context, roomID string, timeLeft uint32, onTurnE
|
|||||||
StopTurnTimer(roomID)
|
StopTurnTimer(roomID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rt.onTick(ctx, roomID, currentLeft)
|
rt.onTick(ctx, roomID, uint32(currentLeft))
|
||||||
currentLeft--
|
currentLeft--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
todos.md
4
todos.md
@ -94,3 +94,7 @@
|
|||||||
- lose/win game; then exit room (while being the creator), then press to stats -> cannot find session in db, although cookie in place and session in db; +
|
- lose/win game; then exit room (while being the creator), then press to stats -> cannot find session in db, although cookie in place and session in db; +
|
||||||
- exit endpoints delets player from db; +
|
- exit endpoints delets player from db; +
|
||||||
- timer end did not update the page;
|
- timer end did not update the page;
|
||||||
|
|
||||||
|
- timers conflict; stop timers;
|
||||||
|
- clue snatching;
|
||||||
|
- llm resp token amount limit;
|
||||||
|
Reference in New Issue
Block a user