Commit 218c06c8 authored by nanahira's avatar nanahira

finish

parent 9a98c5c1
Pipeline #2281 passed with stages
in 49 seconds
......@@ -9,7 +9,7 @@ let config: Config;
async function createTournament(oldTournamentData: any) {
const oldData = _.clone(oldTournamentData);
delete oldData.url;
oldData.name += " Imported";
oldData.name = config.targetTournamentName;
const {data} = await axios.post(" https://api.challonge.com/v1/tournaments.json", {
api_key: config.apiKey,
tournament: oldData,
......@@ -54,4 +54,4 @@ async function main() {
}, axiosPostConfig);
console.log(`Finished.`);
}
main();
\ No newline at end of file
main();
......@@ -56,12 +56,16 @@ async function checkQuit(round: number, oldPlayerId: number) {
}
const nextRoundMatch = oldMatches.find(m => m.round === round + 1 && (m.player1_id === oldPlayerId || m.player2_id === oldPlayerId));
if(!nextRoundMatch) {
console.log(`Player ${oldPlayer.name} quitted in round ${round}.`);
const newPlayerId = newParticipantNameMap.get(oldPlayer.name).id;
await axios.post(`https://api.challonge.com/v1/tournaments/${config.targetTournament}/participants/${newPlayerId}.json`, {
api_key: config.apiKey,
_method: "delete"
}, axiosPostConfig);
console.log(`Player ${oldPlayer.name}: ${oldPlayerId}/${newPlayerId} quitted in round ${round}.`);
try {
await axios.delete(`https://api.challonge.com/v1/tournaments/${config.targetTournament}/participants/${newPlayerId}.json?api_key=${encodeURIComponent(config.apiKey)}`, {
responseType: 'json'
});
console.log(`Successfully quitting player ${oldPlayer.name} in round ${round}.`);
} catch (e) {
console.log(`Failed quitting player ${oldPlayer.name} in round ${round}: ${e.toString()}`);
}
}
}
......@@ -91,14 +95,20 @@ async function migrateMatch(match: Match) {
}
const oldPlayerIds = [oldMatch.player1_id, oldMatch.player2_id]
await Promise.all(oldPlayerIds.map(pid => checkQuit(match.round, pid)));
await axios.put(`https://api.challonge.com/v1/tournaments/${config.targetTournament}/matches/${match.id}.json`, {
api_key: config.apiKey,
match: {
scores_csv: oldMatch.scores_csv,
winner_id
}
}, axiosPostConfig);
console.log(`Migrated match ${currentMatchPlayer1Name} vs ${currentMatchPlayer2Name}.`);
try {
await axios.put(`https://api.challonge.com/v1/tournaments/${config.targetTournament}/matches/${match.id}.json`, {
api_key: config.apiKey,
match: {
scores_csv: oldMatch.scores_csv,
winner_id
}
}, axiosPostConfig);
console.log(`Successfully migrated match ${currentMatchPlayer1Name} vs ${currentMatchPlayer2Name}.`);
} catch (e) {
console.error(`Failed migrating match ${currentMatchPlayer1Name} vs ${currentMatchPlayer2Name}: ${e.toString()}`);
}
}
......@@ -118,4 +128,4 @@ async function main() {
}
console.log(`Finished.`);
}
main();
\ No newline at end of file
main();
......@@ -6,6 +6,7 @@ export interface Config {
apiKey: string;
sourceTournament: string;
targetTournament: string;
targetTournamentName: string;
maxRounds: number;
}
......@@ -47,4 +48,4 @@ export async function loadConfig(): Promise<Config> {
export async function writeConfig(config: Config) {
await fs.promises.writeFile("./config.yaml", yaml.stringify(config));
}
\ No newline at end of file
}
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment