Enha: bot names avoid collision

This commit is contained in:
Grail Finder
2025-07-09 13:47:02 +03:00
parent 502317507b
commit 2180f14850
2 changed files with 18 additions and 1 deletions

View File

@ -19,6 +19,7 @@ type PlayersRepo interface {
PlayerList(ctx context.Context, isBot bool) ([]models.Player, error)
PlayerListAll(ctx context.Context) ([]models.Player, error)
PlayerListByRoom(ctx context.Context, roomID string) ([]models.Player, error)
PlayerGetMaxID(ctx context.Context) (uint32, error)
}
func (p *RepoProvider) PlayerListNames(ctx context.Context) ([]string, error) {
@ -96,6 +97,15 @@ func (p *RepoProvider) PlayerList(ctx context.Context, isBot bool) ([]models.Pla
return players, nil
}
func (p *RepoProvider) PlayerGetMaxID(ctx context.Context) (uint32, error) {
var maxID uint32
err := sqlx.GetContext(ctx, p.DB, &maxID, "SELECT COALESCE(MAX(id), 0) FROM players")
if err != nil {
return 0, err
}
return maxID, nil
}
func (p *RepoProvider) PlayerListAll(ctx context.Context) ([]models.Player, error) {
var players []models.Player
query := "SELECT id, room_id, username, team, role, is_bot FROM players;"