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; ...@@ -9,7 +9,7 @@ let config: Config;
async function createTournament(oldTournamentData: any) { async function createTournament(oldTournamentData: any) {
const oldData = _.clone(oldTournamentData); const oldData = _.clone(oldTournamentData);
delete oldData.url; delete oldData.url;
oldData.name += " Imported"; oldData.name = config.targetTournamentName;
const {data} = await axios.post(" https://api.challonge.com/v1/tournaments.json", { const {data} = await axios.post(" https://api.challonge.com/v1/tournaments.json", {
api_key: config.apiKey, api_key: config.apiKey,
tournament: oldData, tournament: oldData,
...@@ -54,4 +54,4 @@ async function main() { ...@@ -54,4 +54,4 @@ async function main() {
}, axiosPostConfig); }, axiosPostConfig);
console.log(`Finished.`); console.log(`Finished.`);
} }
main(); main();
\ No newline at end of file
...@@ -56,12 +56,16 @@ async function checkQuit(round: number, oldPlayerId: number) { ...@@ -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)); const nextRoundMatch = oldMatches.find(m => m.round === round + 1 && (m.player1_id === oldPlayerId || m.player2_id === oldPlayerId));
if(!nextRoundMatch) { if(!nextRoundMatch) {
console.log(`Player ${oldPlayer.name} quitted in round ${round}.`);
const newPlayerId = newParticipantNameMap.get(oldPlayer.name).id; const newPlayerId = newParticipantNameMap.get(oldPlayer.name).id;
await axios.post(`https://api.challonge.com/v1/tournaments/${config.targetTournament}/participants/${newPlayerId}.json`, { console.log(`Player ${oldPlayer.name}: ${oldPlayerId}/${newPlayerId} quitted in round ${round}.`);
api_key: config.apiKey, try {
_method: "delete" await axios.delete(`https://api.challonge.com/v1/tournaments/${config.targetTournament}/participants/${newPlayerId}.json?api_key=${encodeURIComponent(config.apiKey)}`, {
}, axiosPostConfig); 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) { ...@@ -91,14 +95,20 @@ async function migrateMatch(match: Match) {
} }
const oldPlayerIds = [oldMatch.player1_id, oldMatch.player2_id] const oldPlayerIds = [oldMatch.player1_id, oldMatch.player2_id]
await Promise.all(oldPlayerIds.map(pid => checkQuit(match.round, pid))); 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`, { try {
api_key: config.apiKey, await axios.put(`https://api.challonge.com/v1/tournaments/${config.targetTournament}/matches/${match.id}.json`, {
match: { api_key: config.apiKey,
scores_csv: oldMatch.scores_csv, match: {
winner_id scores_csv: oldMatch.scores_csv,
} winner_id
}, axiosPostConfig); }
console.log(`Migrated match ${currentMatchPlayer1Name} vs ${currentMatchPlayer2Name}.`); }, 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() { ...@@ -118,4 +128,4 @@ async function main() {
} }
console.log(`Finished.`); console.log(`Finished.`);
} }
main(); main();
\ No newline at end of file
...@@ -6,6 +6,7 @@ export interface Config { ...@@ -6,6 +6,7 @@ export interface Config {
apiKey: string; apiKey: string;
sourceTournament: string; sourceTournament: string;
targetTournament: string; targetTournament: string;
targetTournamentName: string;
maxRounds: number; maxRounds: number;
} }
...@@ -47,4 +48,4 @@ export async function loadConfig(): Promise<Config> { ...@@ -47,4 +48,4 @@ export async function loadConfig(): Promise<Config> {
export async function writeConfig(config: Config) { export async function writeConfig(config: Config) {
await fs.promises.writeFile("./config.yaml", yaml.stringify(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