Fix: recover bot
This commit is contained in:
		| @@ -293,6 +293,11 @@ func RemoveBot(botName string, room *models.Room) error { | |||||||
| 	delete(SignalChanMap, botName) | 	delete(SignalChanMap, botName) | ||||||
| 	// remove role from room | 	// remove role from room | ||||||
| 	room.RemovePlayer(botName) | 	room.RemovePlayer(botName) | ||||||
|  | 	slog.Debug("removing bot player", "name", botName, "room_id", room.ID, "room", room) | ||||||
|  | 	if err := repo.PlayerDelete(context.Background(), room.ID, botName); err != nil { | ||||||
|  | 		slog.Error("failed to remove bot player", "name", botName, "room_id", room.ID) | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
| 	return saveRoom(room) | 	return saveRoom(room) | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -363,9 +368,11 @@ func NewBot(role, team, name, roomID string, cfg *config.Config, recovery bool) | |||||||
| 	if err := saveRoom(room); err != nil { | 	if err := saveRoom(room); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  | 	if !recovery { | ||||||
| 		if err := saveBot(bot); err != nil { | 		if err := saveBot(bot); err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
| 	// buffered channel to send to it in the same goroutine | 	// buffered channel to send to it in the same goroutine | ||||||
| 	SignalChanMap[bot.BotName] = make(chan bool, 1) | 	SignalChanMap[bot.BotName] = make(chan bool, 1) | ||||||
| 	DoneChanMap[bot.BotName] = make(chan bool, 1) | 	DoneChanMap[bot.BotName] = make(chan bool, 1) | ||||||
| @@ -384,18 +391,6 @@ func saveBot(bot *Bot) error { | |||||||
| 	return repo.PlayerAdd(context.Background(), botPlayer) | 	return repo.PlayerAdd(context.Background(), botPlayer) | ||||||
| } | } | ||||||
|  |  | ||||||
| // func getRoomByID(roomID string) (*models.Room, error) { |  | ||||||
| // 	roomBytes, err := cache.MemCache.Get(models.CacheRoomPrefix + roomID) |  | ||||||
| // 	if err != nil { |  | ||||||
| // 		return nil, err |  | ||||||
| // 	} |  | ||||||
| // 	resp := &models.Room{} |  | ||||||
| // 	if err := json.Unmarshal(roomBytes, &resp); err != nil { |  | ||||||
| // 		return nil, err |  | ||||||
| // 	} |  | ||||||
| // 	return resp, nil |  | ||||||
| // } |  | ||||||
|  |  | ||||||
| func saveRoom(room *models.Room) error { | func saveRoom(room *models.Room) error { | ||||||
| 	// key := models.CacheRoomPrefix + room.ID | 	// key := models.CacheRoomPrefix + room.ID | ||||||
| 	// data, err := json.Marshal(room) | 	// data, err := json.Marshal(room) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder