Skip to content

Commit

Permalink
多账号支持
Browse files Browse the repository at this point in the history
  • Loading branch information
enpitsuLin committed Oct 30, 2023
1 parent a958071 commit 669da1b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
.env

.vscode
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

回到项目页面,依次点击 Settings--> Secrets -->New secret

建立名为 `SKLAND_TOKEN` 的 secret,值为上一步获取 content,最后点击 Add secret
建立名为 `SKLAND_TOKEN` 的 secret,值为上一步获取 content,最后点击 Add secret,如果需要多账号支持,请使用半角逗号`,`分割

### 启动 Github Action

Expand All @@ -25,3 +25,5 @@
返回项目主页面,点击上方的`Actions`,再点击左侧的`attendance`,再点击`Run workflow`

至此,部署完毕。

> 注意:github actions 会对60天没有活动的仓库自动禁用,你可能要主动关注一下 github actions 的运行情况(一般会发邮件通知 actions 执行失败)
77 changes: 42 additions & 35 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'assert'
import 'dotenv/config'

const SKLAND_AUTH_URL = 'https://as.hypergryph.com/user/oauth2/v2/grant',
Expand Down Expand Up @@ -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
})
})
Expand Down Expand Up @@ -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)))

0 comments on commit 669da1b

Please sign in to comment.