Fix: recover bot
This commit is contained in:
@ -293,6 +293,11 @@ func RemoveBot(botName string, room *models.Room) error {
|
||||
delete(SignalChanMap, botName)
|
||||
// remove role from room
|
||||
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)
|
||||
}
|
||||
|
||||
@ -363,8 +368,10 @@ func NewBot(role, team, name, roomID string, cfg *config.Config, recovery bool)
|
||||
if err := saveRoom(room); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := saveBot(bot); err != nil {
|
||||
return nil, err
|
||||
if !recovery {
|
||||
if err := saveBot(bot); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
// buffered channel to send to it in the same goroutine
|
||||
SignalChanMap[bot.BotName] = make(chan bool, 1)
|
||||
@ -384,18 +391,6 @@ func saveBot(bot *Bot) error {
|
||||
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 {
|
||||
// key := models.CacheRoomPrefix + room.ID
|
||||
// data, err := json.Marshal(room)
|
||||
|
Reference in New Issue
Block a user