Enha: filter out some words
This commit is contained in:
		| @@ -12,6 +12,7 @@ import ( | ||||
| 	"log/slog" | ||||
| 	"net/http" | ||||
| 	"os" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| @@ -93,6 +94,27 @@ type Bot struct { | ||||
| 	// 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 | ||||
| func (b *Bot) StartBot() { | ||||
| 	for { | ||||
| @@ -138,8 +160,18 @@ func (b *Bot) StartBot() { | ||||
| 				room.ActionHistory = append(room.ActionHistory, action) | ||||
| 				room.MimeDone = true | ||||
| 				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: | ||||
| 				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] | ||||
| 					b.log.Debug("bot trying to open card", "word", word, "color", | ||||
| 						color, "exists", exists) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder