From 669da1b49759c0c30b32456dd72210ad0484c8b0 Mon Sep 17 00:00:00 2001 From: enpitsulin Date: Mon, 30 Oct 2023 19:41:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E8=B4=A6=E5=8F=B7=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ README.md | 4 ++- main.ts | 77 +++++++++++++++++++++++++++++------------------------- 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 37d7e73..3796a5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules .env + +.vscode diff --git a/README.md b/README.md index 28b76e5..e886a38 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ 回到项目页面,依次点击 Settings--> Secrets -->New secret -建立名为 `SKLAND_TOKEN` 的 secret,值为上一步获取 content,最后点击 Add secret +建立名为 `SKLAND_TOKEN` 的 secret,值为上一步获取 content,最后点击 Add secret,如果需要多账号支持,请使用半角逗号`,`分割 ### 启动 Github Action @@ -25,3 +25,5 @@ 返回项目主页面,点击上方的`Actions`,再点击左侧的`attendance`,再点击`Run workflow` 至此,部署完毕。 + +> 注意:github actions 会对60天没有活动的仓库自动禁用,你可能要主动关注一下 github actions 的运行情况(一般会发邮件通知 actions 执行失败) diff --git a/main.ts b/main.ts index f0988dd..1640bcb 100644 --- a/main.ts +++ b/main.ts @@ -1,3 +1,4 @@ +import assert from 'assert' import 'dotenv/config' const SKLAND_AUTH_URL = 'https://as.hypergryph.com/user/oauth2/v2/grant', @@ -61,13 +62,13 @@ const command_header = { 'platform': '1', } -async function auth() { +async function auth(token: string) { const response = await fetch(SKLAND_AUTH_URL, { method: "POST", headers: command_header, body: JSON.stringify({ "appCode": '4ca99fa6b56cc2ba', - "token": process.env.SKLAND_TOKEN, + "token": token, "type": 0 }) }) @@ -111,37 +112,43 @@ async function getBinding(cred: string) { return data.data } -const { code } = await auth() -const { cred } = await signIn(code) -const { list } = await getBinding(cred) - - - -Promise.all( - list.map(i => i.bindingList).flat() - .map(async character => { - - console.log('开始签到' + character.nickName); - const response = await fetch( - SKLAND_ATTENDANCE_URL, - { - method: "POST", - headers: Object.assign({ - cred, - "Content-Type": "application/json; charset=utf-8" - }, command_header), - body: JSON.stringify({ - uid: character.uid, - gameId: character.channelMasterId - }) +async function doAttendanceForAccount(token: string) { + const { code } = await auth(token) + const { cred } = await signIn(code) + const { list } = await getBinding(cred) + + Promise.all( + list.map(i => i.bindingList).flat() + .map(async character => { + + console.log('开始签到' + character.nickName); + const response = await fetch( + SKLAND_ATTENDANCE_URL, + { + method: "POST", + headers: Object.assign({ + cred, + "Content-Type": "application/json; charset=utf-8" + }, command_header), + body: JSON.stringify({ + uid: character.uid, + gameId: character.channelMasterId + }) + } + ) + const data = await response.json() as AttendanceResponse + + if (data.code === 10001) { + console.log(`${character.nickName} ${data.message}`) + } else { + console.log(`${character.nickName}签到成功, 获得了${data.data.awards.map(a => a.resource.name + '' + a.count + '个').join(',')}`); } - ) - const data = await response.json() as AttendanceResponse - - if (data.code === 10001) { - console.log(`${character.nickName} ${data.message}`) - } else { - console.log(`${character.nickName}签到成功, 获得了${data.data.awards.map(a => a.resource.name + '' + a.count + '个').join(',')}`); - } - }) -) + }) + ) +} + +assert(typeof process.env.SKLAND_TOKEN === 'string') + +const accounts = Array.from(process.env.SKLAND_TOKEN.split(',')) + +await Promise.all(accounts.map(token => doAttendanceForAccount(token)))