Fix: recover bot; llama.cpp fix
This commit is contained in:
		| @@ -83,6 +83,7 @@ func saveFullInfo(fi *models.FullInfo) error { | ||||
|  | ||||
| func notifyBotIfNeeded(fi *models.FullInfo) { | ||||
| 	if botName := fi.Room.WhichBotToMove(); botName != "" { | ||||
| 		log.Debug("got botname", "name", botName) | ||||
| 		llmapi.SignalChanMap[botName] <- true | ||||
| 	} | ||||
| 	log.Debug("no bot", "room_id", fi.Room.ID) | ||||
| @@ -231,7 +232,7 @@ func joinTeam(ctx context.Context, role, team string) (*models.FullInfo, error) | ||||
| } | ||||
|  | ||||
| // get all rooms | ||||
| func listPublicRooms() []*models.Room { | ||||
| func listRooms(allRooms bool) []*models.Room { | ||||
| 	cacheMap := memcache.GetAll() | ||||
| 	publicRooms := []*models.Room{} | ||||
| 	// no way to know if room is public until unmarshal -_-; | ||||
| @@ -243,7 +244,7 @@ func listPublicRooms() []*models.Room { | ||||
| 				continue | ||||
| 			} | ||||
| 			log.Debug("consider room for list", "room", room, "key", key) | ||||
| 			if room.IsPublic { | ||||
| 			if room.IsPublic || allRooms { | ||||
| 				publicRooms = append(publicRooms, room) | ||||
| 			} | ||||
| 		} | ||||
| @@ -251,6 +252,24 @@ func listPublicRooms() []*models.Room { | ||||
| 	return publicRooms | ||||
| } | ||||
|  | ||||
| // get bots | ||||
| func listBots() map[string]map[string]string { | ||||
| 	cacheMap := memcache.GetAll() | ||||
| 	resp := make(map[string]map[string]string) | ||||
| 	// no way to know if room is public until unmarshal -_-; | ||||
| 	for key, value := range cacheMap { | ||||
| 		if strings.HasPrefix(key, models.CacheBotPredix) { | ||||
| 			botMap := make(map[string]string) | ||||
| 			if err := json.Unmarshal(value, &botMap); err != nil { | ||||
| 				log.Warn("failed to unmarshal bot", "error", err) | ||||
| 				continue | ||||
| 			} | ||||
| 			resp[botMap["bot_name"]] = botMap | ||||
| 		} | ||||
| 	} | ||||
| 	return resp | ||||
| } | ||||
|  | ||||
| func notify(event, msg string) { | ||||
| 	Notifier.Notifier <- broker.NotificationEvent{ | ||||
| 		EventName: event, | ||||
| @@ -271,3 +290,22 @@ func loadCards(room *models.Room) { | ||||
| 		room.WCMap[card.Word] = card.Color | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func recoverBots() { | ||||
| 	bots := listBots() | ||||
| 	for botName, botMap := range bots { | ||||
| 		if err := recoverBot(botMap); err != nil { | ||||
| 			log.Warn("failed to recover bot", "botName", botName, "error", err) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func recoverBot(bm map[string]string) error { | ||||
| 	// TODO: check if room still exists | ||||
| 	log.Debug("recovering bot", "bot", bm) | ||||
| 	_, err := llmapi.NewBot(bm["role"], bm["team"], bm["bot_name"], bm["room_id"], cfg) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder