diff --git a/src/commands/generate_schedule.ts b/src/commands/generate_schedule.ts index 7020e88..b3f1ff7 100644 --- a/src/commands/generate_schedule.ts +++ b/src/commands/generate_schedule.ts @@ -75,6 +75,8 @@ export const execute = async (interaction: ChatInputCommandInteraction) => { String(rounds), quality, "-q", + "-a", + String(process.env.TEAMS_PER_ALLIANCE), ]); // Pipe the output of MatchMaker to a file diff --git a/src/lib/googleSheet.ts b/src/lib/googleSheet.ts index 0f63e35..abb1d14 100644 --- a/src/lib/googleSheet.ts +++ b/src/lib/googleSheet.ts @@ -185,12 +185,14 @@ export async function getMatchPlayers( const row = await getMatch(scheduleSheet, matchNumber); return [ - row["Red 1"], - row["Red 2"], - row["Red 3"], - row["Blue 1"], - row["Blue 2"], - row["Blue 3"], + ...Array.from( + { length: process.env.TEAMS_PER_ALLIANCE }, + (_, i) => row[`Red ${i + 1}`] + ), + ...Array.from( + { length: process.env.TEAMS_PER_ALLIANCE }, + (_, i) => row[`Blue ${i + 1}`] + ), ]; } @@ -219,20 +221,20 @@ export async function copyScheduleToMatchesSheet( if (!matchRow) { await matchesSheet.addRow([ matchNumber, - players.get(row["Red 1"]), - players.get(row["Red 2"]), - players.get(row["Red 3"]), - players.get(row["Blue 1"]), - players.get(row["Blue 2"]), - players.get(row["Blue 3"]), + players.get(row["Red 1"]) ?? "", + players.get(row["Red 2"]) ?? "", + players.get(row["Red 3"]) ?? "", + players.get(row["Blue 1"]) ?? "", + players.get(row["Blue 2"]) ?? "", + players.get(row["Blue 3"]) ?? "", ]); } else { - matchRow["Red 1"] = players.get(row["Red 1"]); - matchRow["Red 2"] = players.get(row["Red 2"]); - matchRow["Red 3"] = players.get(row["Red 3"]); - matchRow["Blue 1"] = players.get(row["Blue 1"]); - matchRow["Blue 2"] = players.get(row["Blue 2"]); - matchRow["Blue 3"] = players.get(row["Blue 3"]); + matchRow["Red 1"] = players.get(row["Red 1"]) ?? ""; + matchRow["Red 2"] = players.get(row["Red 2"]) ?? ""; + matchRow["Red 3"] = players.get(row["Red 3"]) ?? ""; + matchRow["Blue 1"] = players.get(row["Blue 1"]) ?? ""; + matchRow["Blue 2"] = players.get(row["Blue 2"]) ?? ""; + matchRow["Blue 3"] = players.get(row["Blue 3"]) ?? ""; await matchRow.save(); } } @@ -250,12 +252,10 @@ export async function postSchedule( for (const match of schedule) { const row = rows.find((r) => r["Match Number"] == match.number); if (row) { - row["Red 1"] = match.teams[0]; - row["Red 2"] = match.teams[1]; - row["Red 3"] = match.teams[2]; - row["Blue 1"] = match.teams[3]; - row["Blue 2"] = match.teams[4]; - row["Blue 3"] = match.teams[5]; + for (let i = 0; i < process.env.TEAMS_PER_ALLIANCE; i++) { + row[`Red ${i + 1}`] = match.teams[i]; + row[`Blue ${i + 1}`] = match.teams[i + process.env.TEAMS_PER_ALLIANCE]; + } row["Discord Ids"] = playerIds[i]; row["Display Names"] = playerNames[i]; @@ -263,12 +263,10 @@ export async function postSchedule( } else { await scheduleSheet.addRow([ match.number, - match.teams[0], - match.teams[1], - match.teams[2], - match.teams[3], - match.teams[4], - match.teams[5], + ...match.teams.slice(0, process.env.TEAMS_PER_ALLIANCE), + ...Array.from({ length: 3 - process.env.TEAMS_PER_ALLIANCE }, () => ""), + ...match.teams.slice(process.env.TEAMS_PER_ALLIANCE), + ...Array.from({ length: 3 - process.env.TEAMS_PER_ALLIANCE }, () => ""), "", playerIds[i], playerNames[i],