Skip to content

Commit

Permalink
Refactor code to use environment variable for number of teams per all…
Browse files Browse the repository at this point in the history
…iance
  • Loading branch information
NicholasBottone committed Jun 9, 2024
1 parent 8f93f29 commit 2f63963
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/commands/generate_schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 28 additions & 30 deletions src/lib/googleSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]
),
];
}

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -250,25 +252,21 @@ 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];

await row.save();
} 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],
Expand Down

0 comments on commit 2f63963

Please sign in to comment.