Enha: filter out some words
This commit is contained in:
		
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,13 +1,9 @@ | |||||||
| {{define "main"}} | {{define "main"}} | ||||||
| 	Start of main temp |  | ||||||
| 	{{ if not . }} | 	{{ if not . }} | ||||||
| 		login temp |  | ||||||
| 		{{template "login"}} | 		{{template "login"}} | ||||||
| 	{{ else if ne .LinkLogin "" }} | 	{{ else if ne .LinkLogin "" }} | ||||||
| 		got to linklogin |  | ||||||
| 		{{template "linklogin" .LinkLogin}} | 		{{template "linklogin" .LinkLogin}} | ||||||
| 	{{ else if eq .State.RoomID "" }} | 	{{ else if eq .State.RoomID "" }} | ||||||
| 		empty state roomid |  | ||||||
| 		<div id="hello-user"> | 		<div id="hello-user"> | ||||||
| 			<p>Hello {{.State.Username}}</p> | 			<p>Hello {{.State.Username}}</p> | ||||||
| 		</div> | 		</div> | ||||||
| @@ -18,7 +14,6 @@ | |||||||
| 		{{template "roomlist" .List}} | 		{{template "roomlist" .List}} | ||||||
| 		</div> | 		</div> | ||||||
| 	{{else}} | 	{{else}} | ||||||
| 		else |  | ||||||
| 		<div id="room"> | 		<div id="room"> | ||||||
| 		{{template "room" .}} | 		{{template "room" .}} | ||||||
| 		</div> | 		</div> | ||||||
|   | |||||||
| @@ -3,7 +3,8 @@ | |||||||
|   <div id="meta"> |   <div id="meta"> | ||||||
|     <p>Hello {{.State.Username}};</p> |     <p>Hello {{.State.Username}};</p> | ||||||
|     <p>Room created by {{.Room.CreatorName}};</p> |     <p>Room created by {{.Room.CreatorName}};</p> | ||||||
|     <p>Room link:</p><p><input id="roomlink" readonly="" onclick="copyText()" value="{{.Room.RoomLink}}"></input></p> |     <p>Room link:</p> | ||||||
|  |     <p><input id="roomlink" readonly="" onclick="copyText()" value="{{.Room.RoomLink}}" class="bg-amber-100 text-black px-1 py-1 rounded"></input></p> | ||||||
|     <p>Game is running: {{.Room.IsRunning}}</p> |     <p>Game is running: {{.Room.IsRunning}}</p> | ||||||
|     <p> |     <p> | ||||||
|       {{if and (eq .State.Username .Room.CreatorName) (not .Room.IsRunning)}} |       {{if and (eq .State.Username .Room.CreatorName) (not .Room.IsRunning)}} | ||||||
| @@ -12,13 +13,6 @@ | |||||||
|     </p> |     </p> | ||||||
|     {{if .Room.IsOver}} |     {{if .Room.IsOver}} | ||||||
|     <p>GAME OVER; team <span class="text-{{.Room.TeamWon}}-500">{{.Room.TeamWon}}</span> won! 🧚</p> |     <p>GAME OVER; team <span class="text-{{.Room.TeamWon}}-500">{{.Room.TeamWon}}</span> won! 🧚</p> | ||||||
|     {{else}} |  | ||||||
|     <p>Turn of the <span class="text-{{.Room.TeamTurn}}-500">{{.Room.TeamTurn}}</span> team</p> |  | ||||||
|       {{if .Room.MimeDone}} |  | ||||||
|       <p class="text-{{.Room.TeamTurn}}-500">Waiting for guessers</p> |  | ||||||
|       {{else}} |  | ||||||
|       <p class="text-{{.Room.TeamTurn}}-500">Waiting for mime</p> |  | ||||||
|       {{end}} |  | ||||||
|     {{end}} |     {{end}} | ||||||
|     <p> |     <p> | ||||||
|       {{if eq .State.Team ""}} |       {{if eq .State.Team ""}} | ||||||
| @@ -30,6 +24,12 @@ | |||||||
|   </div> |   </div> | ||||||
|   <hr /> |   <hr /> | ||||||
|   {{if .Room.IsRunning}} |   {{if .Room.IsRunning}} | ||||||
|  |     <p>Turn of the <span class="text-{{.Room.TeamTurn}}-500">{{.Room.TeamTurn}}</span> team</p> | ||||||
|  |     {{if .Room.MimeDone}} | ||||||
|  |     <p class="text-{{.Room.TeamTurn}}-500">Waiting for guessers</p> | ||||||
|  |     {{else}} | ||||||
|  |     <p class="text-{{.Room.TeamTurn}}-500">Waiting for mime</p> | ||||||
|  |     {{end}} | ||||||
|     {{template "cardcounter" .Room}} |     {{template "cardcounter" .Room}} | ||||||
|   {{end}} |   {{end}} | ||||||
|   <div id="addbot"> |   <div id="addbot"> | ||||||
| @@ -62,7 +62,7 @@ | |||||||
|   </div> |   </div> | ||||||
|   <div> |   <div> | ||||||
|     {{if and (eq .State.Username .Room.CreatorName) (.Room.IsRunning)}} |     {{if and (eq .State.Username .Room.CreatorName) (.Room.IsRunning)}} | ||||||
|       <button hx-get="/renotify-bot" class="bg-amber-100 text-black px-4 py-2 rounded">Btn in case llm call failed</button> |       <button hx-get="/renotify-bot" hx-swap="none" class="bg-gray-100 text-black px-1 py-1 rounded">Btn in case llm call failed</button> | ||||||
|     {{end}} |     {{end}} | ||||||
|   </div> |   </div> | ||||||
|   <div hx-get="/actionhistory" hx-trigger="sse:backlog_{{.Room.ID}}"> |   <div hx-get="/actionhistory" hx-trigger="sse:backlog_{{.Room.ID}}"> | ||||||
|   | |||||||
| @@ -4,9 +4,9 @@ | |||||||
| <p> | <p> | ||||||
|     {{.ID}} |     {{.ID}} | ||||||
| </p> | </p> | ||||||
| <div class="room-item mb-3 p-4 border rounded-lg hover:bg-gray-50 transition-colors"> | <div hx-get="/room-join?id={{.ID}}" hx-target="#ancestor" class="room-item mb-3 p-4 border rounded-lg hover:bg-gray-50 transition-colors"> | ||||||
|     <div class="flex justify-between items-center"> |     <div class="flex justify-between items-center"> | ||||||
|         <div hx-get="/room-join?id={{.ID}}" hx-target="#ancestor" class="room-info"> |         <div class="room-info"> | ||||||
|             <div class="text-sm text-gray-500"> |             <div class="text-sm text-gray-500"> | ||||||
|                 Created {{.CreatedAt.Format "2 Jan 2006 15:04"}} by  |                 Created {{.CreatedAt.Format "2 Jan 2006 15:04"}} by  | ||||||
|                 <span class="font-medium text-gray-700">{{.CreatorName}}</span> |                 <span class="font-medium text-gray-700">{{.CreatorName}}</span> | ||||||
|   | |||||||
| @@ -301,7 +301,10 @@ func recoverBots() { | |||||||
| } | } | ||||||
|  |  | ||||||
| func recoverBot(bm map[string]string) error { | func recoverBot(bm map[string]string) error { | ||||||
| 	// TODO: check if room still exists | 	// check if room still exists | ||||||
|  | 	if _, err := getRoomByID(bm["room_id"]); err != nil { | ||||||
|  | 		return fmt.Errorf("no such room: %s; err: %w", bm["room_id"], err) | ||||||
|  | 	} | ||||||
| 	log.Debug("recovering bot", "bot", bm) | 	log.Debug("recovering bot", "bot", bm) | ||||||
| 	_, err := llmapi.NewBot(bm["role"], bm["team"], bm["bot_name"], bm["room_id"], cfg) | 	_, err := llmapi.NewBot(bm["role"], bm["team"], bm["bot_name"], bm["room_id"], cfg) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
| @@ -151,7 +151,7 @@ func makeCookie(username string, remote string) (*http.Cookie, error) { | |||||||
| 	log.Info("check remote addr for cookie set", | 	log.Info("check remote addr for cookie set", | ||||||
| 		"remote", remote, "session", session) | 		"remote", remote, "session", session) | ||||||
| 	if strings.Contains(remote, "192.168.0") { | 	if strings.Contains(remote, "192.168.0") { | ||||||
| 		cookie.Domain = "192.168.0.106" | 		cookie.Domain = "192.168.0.100" | ||||||
| 		cookie.SameSite = http.SameSiteLaxMode | 		cookie.SameSite = http.SameSiteLaxMode | ||||||
| 		cookie.Secure = false | 		cookie.Secure = false | ||||||
| 		log.Info("changing cookie domain", "domain", cookie.Domain) | 		log.Info("changing cookie domain", "domain", cookie.Domain) | ||||||
|   | |||||||
| @@ -85,12 +85,14 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { | |||||||
| 	// if opened card is of color of opp team, change turn | 	// if opened card is of color of opp team, change turn | ||||||
| 	oppositeColor := fi.Room.GetOppositeTeamColor() | 	oppositeColor := fi.Room.GetOppositeTeamColor() | ||||||
| 	fi.Room.OpenedThisTurn++ | 	fi.Room.OpenedThisTurn++ | ||||||
| 	if fi.Room.ThisTurnLimit >= fi.Room.OpenedThisTurn { | 	if fi.Room.ThisTurnLimit > 0 { | ||||||
| 		// end turn | 		if fi.Room.ThisTurnLimit >= fi.Room.OpenedThisTurn { | ||||||
| 		fi.Room.TeamTurn = oppositeColor | 			// end turn | ||||||
| 		fi.Room.MimeDone = false | 			fi.Room.TeamTurn = oppositeColor | ||||||
| 		fi.Room.OpenedThisTurn = 0 | 			fi.Room.MimeDone = false | ||||||
| 		fi.Room.ThisTurnLimit = 0 | 			fi.Room.OpenedThisTurn = 0 | ||||||
|  | 			fi.Room.ThisTurnLimit = 0 | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 	switch string(color) { | 	switch string(color) { | ||||||
| 	case "black": | 	case "black": | ||||||
|   | |||||||
| @@ -262,6 +262,7 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) { | |||||||
| 	fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) | 	fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) | ||||||
| 	fi.Room.MimeDone = true | 	fi.Room.MimeDone = true | ||||||
| 	fi.Room.ThisTurnLimit = uint8(guessLimitU64) + 1 | 	fi.Room.ThisTurnLimit = uint8(guessLimitU64) + 1 | ||||||
|  | 	log.Debug("given clue", "clue", clue, "limit", guessLimitU64) | ||||||
| 	notify(models.NotifyBacklogPrefix+fi.Room.ID, clue+num) | 	notify(models.NotifyBacklogPrefix+fi.Room.ID, clue+num) | ||||||
| 	notifyBotIfNeeded(fi) | 	notifyBotIfNeeded(fi) | ||||||
| 	if err := saveFullInfo(fi); err != nil { | 	if err := saveFullInfo(fi); err != nil { | ||||||
|   | |||||||
| @@ -12,6 +12,7 @@ import ( | |||||||
| 	"log/slog" | 	"log/slog" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"os" | 	"os" | ||||||
|  | 	"strconv" | ||||||
| 	"strings" | 	"strings" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -93,6 +94,27 @@ type Bot struct { | |||||||
| 	// DoneCh    chan bool | 	// DoneCh    chan bool | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func convertToSliceOfStrings(value any) ([]string, error) { | ||||||
|  | 	switch v := value.(type) { | ||||||
|  | 	case []string: | ||||||
|  | 		// Directly return if it's already []string | ||||||
|  | 		return v, nil | ||||||
|  | 	case []interface{}: | ||||||
|  | 		// Convert each element to string | ||||||
|  | 		result := make([]string, len(v)) | ||||||
|  | 		for i, item := range v { | ||||||
|  | 			str, ok := item.(string) | ||||||
|  | 			if !ok { | ||||||
|  | 				return nil, fmt.Errorf("element at index %d is not a string (got %T)", i, item) | ||||||
|  | 			} | ||||||
|  | 			result[i] = str | ||||||
|  | 		} | ||||||
|  | 		return result, nil | ||||||
|  | 	default: | ||||||
|  | 		return nil, fmt.Errorf("unsupported type: %T", value) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| // StartBot | // StartBot | ||||||
| func (b *Bot) StartBot() { | func (b *Bot) StartBot() { | ||||||
| 	for { | 	for { | ||||||
| @@ -138,8 +160,18 @@ func (b *Bot) StartBot() { | |||||||
| 				room.ActionHistory = append(room.ActionHistory, action) | 				room.ActionHistory = append(room.ActionHistory, action) | ||||||
| 				room.MimeDone = true | 				room.MimeDone = true | ||||||
| 				eventPayload = mimeResp.Clue + mimeResp.Number | 				eventPayload = mimeResp.Clue + mimeResp.Number | ||||||
|  | 				guessLimitU64, err := strconv.ParseUint(mimeResp.Number, 10, 8) | ||||||
|  | 				if err != nil { | ||||||
|  | 					b.log.Warn("failed to parse bot given limit", "mimeResp", mimeResp, "bot_name", b.BotName) | ||||||
|  | 				} | ||||||
|  | 				room.ThisTurnLimit = uint8(guessLimitU64) | ||||||
| 			case models.UserRoleGuesser: | 			case models.UserRoleGuesser: | ||||||
| 				for _, word := range tempMap["guesses"].([]string) { | 				guesses, err := convertToSliceOfStrings(tempMap["guesses"]) | ||||||
|  | 				if err != nil { | ||||||
|  | 					b.log.Warn("failed to parse bot given guesses", "mimeResp", tempMap, "bot_name", b.BotName) | ||||||
|  | 					continue | ||||||
|  | 				} | ||||||
|  | 				for _, word := range guesses { | ||||||
| 					color, exists := room.WCMap[word] | 					color, exists := room.WCMap[word] | ||||||
| 					b.log.Debug("bot trying to open card", "word", word, "color", | 					b.log.Debug("bot trying to open card", "word", word, "color", | ||||||
| 						color, "exists", exists) | 						color, "exists", exists) | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								todos.md
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								todos.md
									
									
									
									
									
								
							| @@ -5,7 +5,6 @@ | |||||||
| - mark cards (instead of opening them (right click?); | - mark cards (instead of opening them (right click?); | ||||||
| - invite link; + | - invite link; + | ||||||
| - login with invite link; + | - login with invite link; + | ||||||
| - add html icons of whos turn it is (like an image of big ? when mime is thinking); |  | ||||||
| - there three places for bot to check if its its move: start-game; end-turn, after mime gave clue; + | - there three places for bot to check if its its move: start-game; end-turn, after mime gave clue; + | ||||||
| - remove bot button (if game is not running, or bot already added); + | - remove bot button (if game is not running, or bot already added); + | ||||||
| - show in backlog (and with that in prompt to llm) how many cards are left to open, also additional comment: if guess was right; | - show in backlog (and with that in prompt to llm) how many cards are left to open, also additional comment: if guess was right; | ||||||
| @@ -16,6 +15,7 @@ | |||||||
| - autoscroll down backlog on update; | - autoscroll down backlog on update; | ||||||
| - gameover to backlog; | - gameover to backlog; | ||||||
| - ended turn action to backlog; | - ended turn action to backlog; | ||||||
|  | - clear indication that model (llm) is thinking / answered; | ||||||
|  |  | ||||||
| #### sse points | #### sse points | ||||||
| - clue sse update; | - clue sse update; | ||||||
| @@ -38,4 +38,5 @@ | |||||||
| - invite link gets cutoff; | - invite link gets cutoff; | ||||||
| - mime rejoined the room: does not see colors; state save in store.json has empty role and team + | - mime rejoined the room: does not see colors; state save in store.json has empty role and team + | ||||||
| - restart bot routines after server restart; + | - restart bot routines after server restart; + | ||||||
| - guesser did not have same number of guesses (move ended after 1 guess); show how much guesses left on the page; | - guesser did not have same number of guesses (move ended after 1 guess); show how much guesses left on the page (red after blue); | ||||||
|  | - guesser bot no request after game restart; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder