From 39db83b8acaeabc7c43ed34a1915320f4118ce72 Mon Sep 17 00:00:00 2001 From: enpitsulin Date: Tue, 28 Nov 2023 21:39:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20log=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=94=A8=E6=88=B7=E5=90=8D=E9=9A=90?= =?UTF-8?q?=E7=A7=81=E6=89=93=E7=A0=81=E5=8A=9F=E8=83=BD=20(#15)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sin <13870295+sino1641@users.noreply.github.com> --- .github/workflows/schedule.yml | 6 +++--- .gitignore | 2 +- README.md | 11 +++++------ main.ts | 21 +++++++++++---------- utils.ts | 6 ++++++ 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.github/workflows/schedule.yml b/.github/workflows/schedule.yml index 96d15a2..5dd50a6 100644 --- a/.github/workflows/schedule.yml +++ b/.github/workflows/schedule.yml @@ -5,7 +5,6 @@ on: - cron: "0 20 * * *" workflow_dispatch: - jobs: attendance: runs-on: ubuntu-latest @@ -16,7 +15,7 @@ jobs: - name: Install Node.js uses: actions/setup-node@v3 with: - node-version: 'lts/Hydrogen' + node-version: "lts/Hydrogen" - name: Install pnpm uses: pnpm/action-setup@v2 @@ -39,10 +38,11 @@ jobs: - name: Install dependencies run: pnpm install - + - name: Run daily attendance run: pnpm attendance env: SKLAND_TOKEN: ${{ secrets.SKLAND_TOKEN }} SERVERCHAN_SENDKEY: ${{ secrets.SERVERCHAN_SENDKEY }} BARK_URL: ${{ secrets.BARK_URL }} + SELECT_CHANNEL: ${{ secrets.SELECT_CHANNEL }} diff --git a/.gitignore b/.gitignore index 3796a5a..ed91dab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ node_modules .env - +package-lock.json .vscode diff --git a/README.md b/README.md index b0a3f5b..2bffbdd 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,11 @@
最终可能有的 secrets 如下 -| Name | Secret | -| ------------------ | ---------------------- | -| SKLAND_TOKEN * | 森空岛 token | -| SERVERCHAN_SENDKEY | Server酱推送密钥,可选 | -| BARK_URL | Bark 推送地址,可选 | - +| Name | Secret | +| ------------------ | ---------------------------------------------------------------- | +| SKLAND_TOKEN \* | 森空岛 token
多账号使用半角逗号`,`分割 | +| SERVERCHAN_SENDKEY | Server 酱推送密钥,可选 | +| BARK_URL | Bark 推送地址,可选 |
### 启动 Github Action diff --git a/main.ts b/main.ts index 02e8b05..023dea9 100644 --- a/main.ts +++ b/main.ts @@ -1,6 +1,6 @@ import assert from 'assert' import 'dotenv/config' -import { command_header, generateSignature } from './utils' +import { command_header, generateSignature, getPrivacyName } from './utils' import { serverChan, bark } from "./message_send"; import { SKLAND_AUTH_URL, CRED_CODE_URL, BINDING_URL, SKLAND_CHECKIN_URL, SKLAND_ATTENDANCE_URL, SKLAND_BOARD_IDS, SKLAND_BOARD_NAME_MAPPING } from './constant'; import { SklandBoard, AuthResponse, CredResponse, BindingResponse, AttendanceResponse } from './types'; @@ -146,23 +146,24 @@ async function doAttendanceForAccount(token: string, options: Options) { })) addMessage('## 明日方舟签到') - + let successAttendance = 0; const characterList = list.map(i => i.bindingList).flat() await Promise.all(characterList.map(async character => { - console.log('开始签到' + character.nickName); const data = await attendance(cred, signToken, { uid: character.uid, gameId: character.channelMasterId - }) + }); + console.log(`将签到第${successAttendance + 1}个角色`); if (data.code === 0 && data.message === 'OK') { - const msg = `角色${character.nickName}签到成功, 获得了${data.data.awards.map(a => '「' + a.resource.name + '」' + a.count + '个').join(',')}` - combineMessage(msg) + const msg = `${(Number(character.channelMasterId) - 1) ? 'B 服' : '官服'}角色 ${getPrivacyName(character.nickName)} 签到成功${', 获得了' + data.data.awards.map(a => '「' + a.resource.name + '」' + a.count + '个').join(',')}`; + combineMessage(msg); + successAttendance++; } else { - const msg = `角色${character.nickName}签到失败, 错误消息: ${data.message}\n\n\`\`\`json\n${JSON.stringify(data, null, 2)}\n\`\`\` ` - combineMessage(msg, true) + const msg = `${(Number(character.channelMasterId) - 1) ? 'B 服' : '官服'}角色 ${getPrivacyName(character.nickName)} 签到失败${`, 错误消息: ${data.message}\n\n\`\`\`json\n${JSON.stringify(data, null, 2)}\n\`\`\``}`; + combineMessage(msg, true); } - })) - + })); + combineMessage(`成功签到${successAttendance}个角色`) await excutePushMessage() } diff --git a/utils.ts b/utils.ts index 7651fc0..dc0b32e 100644 --- a/utils.ts +++ b/utils.ts @@ -33,3 +33,9 @@ export function generateSignature>(token: strin return [sign.toString(), header as typeof sign_header] as const } + +export function getPrivacyName(name: string) { + return name.split('') + .map((s, i) => (i > 0 && i < name.length - 1) ? '*' : s) + .join('') +}