From bded7ddcf6bd5d31352a1dfe9b0e986da32c9a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=90=E7=92=90=E9=A3=9E?= Date: Wed, 5 Jul 2023 17:15:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat=20=E5=A2=9E=E5=8A=A0=20LCK=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/index.js b/index.js index 22d4ee48c7..b29a485fe7 100644 --- a/index.js +++ b/index.js @@ -133,6 +133,112 @@ function buildFolders(games) { }); } +async function dealLCKGames() { + // 请求数据 + let games = [] + let yearStr = "" + page = 1 + // 请先设置环境变量,Github Actions 需要在仓库 Settings - Security - Secrets and variables - Actions - Variables 设置 TOKEN + const TOKEN = process.env.TOKEN; + console.log(TOKEN); + while (true) { + // API 文档及 Token 申请地址:https://pandascore.co + let body = (await request.get(`https://api.pandascore.co/lol/matches?filter[league_id]=293&sort=&per_page=100&page=${page}`).set("Authorization", `Bearer ${TOKEN}`).set("Content-Type", "application/json")).body; + // 仅处理当年的 + if (yearStr.length == 0) { + yearStr = body[0].begin_at.split("-")[0] + } + let filtered = body.filter(function(item) { + return item.serie.full_name.endsWith(yearStr); + }); + games.push(...filtered); + let lastOne = body[body.length - 1]; + let serieName = lastOne.serie.full_name; + if (!serieName.endsWith(yearStr)) { + break; + } else { + page++; + } + } + games.reverse(); + + // 移除之前的文件 + if (fs.existsSync(`./${yearStr}_lck`)) fs.rmdirSync(`./${yearStr}_lck`, { recursive: true }); + if (!fs.existsSync(`./${yearStr}_lck`)) fs.mkdirSync(`./${yearStr}_lck`); + if (!fs.existsSync(`./${yearStr}_lck/team`)) fs.mkdirSync(`./${yearStr}_lck/team`); + + // 处理并生成没有提醒的全文件 + let gameObjsWithNoAlarms = games.map(function(game) { + return lckGamesToICSObjs(game, false, yearStr); + }); + let noAlarmFileName = `./${yearStr}_lck/${yearStr}_lck.ics`; + generateLCKICSAndWrite(gameObjsWithNoAlarms, noAlarmFileName); + + // 处理并生成有提醒的全文件 + let gameObjsWithAlarms = games.map(function(game) { + return lckGamesToICSObjs(game, true, yearStr); + }); + let alarmFileName = `./${yearStr}_lck/${yearStr}_lck-alarm.ics`; + generateLCKICSAndWrite(gameObjsWithAlarms, alarmFileName); + + // 生成各队伍有提醒和无提醒的文件 + let teams = games.map(function(item) { + return [item.opponents[0].opponent.acronym, item.opponents[1].opponent.acronym] + }); + let teamNames = [...new Set(teams.flat())]; + for (let teamName of teamNames) { + let teamGameObjsWithNoAlarms = gameObjsWithNoAlarms.filter(function(game) { + return game.title.split(" ").includes(teamName); + }); + let noAlarmFileName = `./${yearStr}_lck/team/${teamName}.ics` + generateLCKICSAndWrite(teamGameObjsWithNoAlarms, noAlarmFileName) + let teamGameObjsWithAlarms = gameObjsWithAlarms.filter(function(game) { + return game.title.split(" ").includes(teamName); + }); + let alarmFileName = `./${yearStr}_lck/team/${teamName}-alarm.ics` + generateLCKICSAndWrite(teamGameObjsWithAlarms, alarmFileName); + } +} + +function generateLCKICSAndWrite(games, fileName) { + const result = icsTool.createEvents(games); + if (result.error) { + console.error(result.error); + } else { + fs.writeFileSync(fileName, result.value); + } +} + +function lckGamesToICSObjs(game, hasAlarm, yearStr) { + const gameDate = new Date(new Date(game.original_scheduled_at).getTime() - 8 * 60 * 60 * 1000); + const gameEndDate = new Date(gameDate.getTime() + 2 * 60 * 60 * 1000); + let slug = game.slug; + let gameName = game.name; + if (game.status != "not_started") { + scoreA = game.results[0].score + scoreB = game.results[1].score + gameName += ` - ${scoreA} : ${scoreB}` + } + return { + title: gameName, + description: slug, + 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: slug + }, + url: "https://www.twitch.tv/lck", + status: "TENTATIVE", + calName: `${yearStr}_lck`, + startInputType: "utc", + startOutputType: "utc", + endInputType: "utc", + endOutputType: "utc", + // 提醒应该不用区分是否比赛结束 + alarms: hasAlarm ? [{ action: "audio", trigger: { minutes: 30, before: true, repeat: 1, attachType: "VALUE=URI", attach: "Glass" } }] : null, + } +} + async function main() { const buffer = (await request.get(API_URL)).body; const gameBundle = JSON.parse(buffer); @@ -143,6 +249,7 @@ async function main() { generateICS(gameBundle, false, game); generateICS(gameBundle, true, game); }); + dealLCKGames(); } main(); From 0b0dca2b65e32cdfab49e8f53b48d75df5ecc35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=90=E7=92=90=E9=A3=9E?= Date: Wed, 5 Jul 2023 17:34:46 +0800 Subject: [PATCH 2/4] =?UTF-8?q?chore=20lck=20=E6=97=A5=E5=8E=86=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=20organizer=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.js b/index.js index b29a485fe7..96ea36414b 100644 --- a/index.js +++ b/index.js @@ -224,9 +224,6 @@ function lckGamesToICSObjs(game, hasAlarm, yearStr) { description: slug, 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: slug - }, url: "https://www.twitch.tv/lck", status: "TENTATIVE", calName: `${yearStr}_lck`, From d7b7714ea26777c7e496f2bef572d8070b24a3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=90=E7=92=90=E9=A3=9E?= Date: Mon, 17 Jul 2023 11:16:23 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E6=9C=AA=E7=A1=AE?= =?UTF-8?q?=E5=AE=9A=E7=9A=84=E6=AF=94=E8=B5=9B=E5=8F=8C=E6=96=B9=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E9=98=9F=E4=BC=8D=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 96ea36414b..4f371fcde8 100644 --- a/index.js +++ b/index.js @@ -183,6 +183,9 @@ async function dealLCKGames() { // 生成各队伍有提醒和无提醒的文件 let teams = games.map(function(item) { + if (item.opponents.length <= 0) { + return [] + } return [item.opponents[0].opponent.acronym, item.opponents[1].opponent.acronym] }); let teamNames = [...new Set(teams.flat())]; From b0f31c56e68564a861c58c7b85b52abe673d77b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=90=E7=92=90=E9=A3=9E?= Date: Mon, 28 Aug 2023 15:24:32 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E6=AF=94=E8=B5=9B?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E6=97=B6=E9=97=B4=E5=8F=96=E5=80=BC=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4f371fcde8..8187da1723 100644 --- a/index.js +++ b/index.js @@ -213,7 +213,7 @@ function generateLCKICSAndWrite(games, fileName) { } function lckGamesToICSObjs(game, hasAlarm, yearStr) { - const gameDate = new Date(new Date(game.original_scheduled_at).getTime() - 8 * 60 * 60 * 1000); + const gameDate = new Date(new Date(game.scheduled_at).getTime() - 8 * 60 * 60 * 1000); const gameEndDate = new Date(gameDate.getTime() + 2 * 60 * 60 * 1000); let slug = game.slug; let gameName = game.name;