-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (63 loc) · 2.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const request = require("superagent");
const icsTool = require("ics");
const fs = require("fs");
const API_URL = "https://val.native.game.qq.com/esports/v1/data/VAL_Match_1000021.json";
/**
*
* @param {{}[]} games
*/
function packageGames(games, hasAlarm, calName) {
return games.map((game) => {
const gameDate = new Date(game.matchDate);
const durationMinutes = 2 * 60;
const gameEndDate = new Date(gameDate.getTime() + durationMinutes * 60 * 1000);
let gameName = "";
// gameName = game.secondLevelGameName;
// gameName += ` ${game.bMatchName}`
gameName += `${game.teamA?.teamSpName || "TBD"} vs ${game.teamB?.teamSpName || "TBD"}`
const hasResult = parseInt(game.scoreA) || parseInt(game.scoreB);
if (hasResult) {
gameName += ` - ${game.scoreA} : ${game.scoreB}`;
}
return {
title: gameName,
description: `${game.secondLevelGameName} ${game.bMatchName} ${game.matchFormat}`,
start: [gameDate.getFullYear(), gameDate.getMonth() + 1, gameDate.getDate(), gameDate.getHours(), gameDate.getMinutes()],
end: [gameEndDate.getFullYear(), gameEndDate.getMonth() + 1, gameEndDate.getDate(), gameEndDate.getHours(), gameEndDate.getMinutes()],
organizer: {
name: `无畏契约${game.secondLevelGameName}`,
email: "vct@qq.com",
},
url: "https://vct.qq.com",
status: "TENTATIVE",
calName: calName ? calName : "VCT-CN",
geo: { lat: 30.0095, lon: 120.2669 },
startInputType: "utc",
startOutputType: "utc",
endInputType: "utc",
endOutputType: "utc",
alarms: hasAlarm && !hasResult ? [{ action: "audio", trigger: { minutes: 30, before: true, repeat: 1, attachType: "VALUE=URI", attach: "Glass" } }] : [],
};
});
}
/**
*
* @param {{}} gameBundle
* @param {boolean} hasAlarm
* @param {string} gameName
*/
function generateICS(gameBundle, hasAlarm) {
const gameInfo = gameBundle.msg;
const games = packageGames(gameInfo, hasAlarm);
const result = icsTool.createEvents(games);
if (result.error) {
console.error(result.error);
} else {
fs.writeFileSync(`./vct-cn${hasAlarm ? "-alarm" : ""}.ics`, result.value);
}
}
async function main() {
const buffer = (await request.get(API_URL)).body;
generateICS(buffer, true);
}
main();