Fix: notify bot

This commit is contained in:
Grail Finder
2025-05-22 16:47:49 +03:00
parent 31f721cd43
commit c155654d5f
7 changed files with 84 additions and 90 deletions

View File

@ -92,6 +92,7 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
case "white", string(oppositeColor):
// end turn
fi.Room.TeamTurn = oppositeColor
fi.Room.MimeDone = false
}
// check if no cards left => game over
if fi.Room.BlueCounter == 0 {
@ -110,6 +111,8 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) {
abortWithError(w, err.Error())
return
}
// get mime bot for opp team and notify it
notifyBotIfNeeded(fi)
notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "")
if err := tmpl.ExecuteTemplate(w, "cardword", cardword); err != nil {
log.Error("failed to execute cardword template", "error", err)
@ -136,16 +139,19 @@ func HandleAddBot(w http.ResponseWriter, r *http.Request) {
// get team; // get role; make up a name
team := r.URL.Query().Get("team")
role := r.URL.Query().Get("role")
log.Debug("got add-bot request", "team", team, "role", role)
fi, err := getFullInfoByCtx(r.Context())
if err != nil {
abortWithError(w, err.Error())
return
}
// TODO: what if bot exists already?
// control number and names of bots
bot, err := llmapi.NewBot(role, team, "bot1", fi.Room.ID, cfg)
if err != nil {
abortWithError(w, err.Error())
return
}
bot.StartBot()
go bot.StartBot()
notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "")
}