Skip to content

Commit

Permalink
feat: log显示不同服务器用户名隐私打码功能 (enpitsuLin#15)
Browse files Browse the repository at this point in the history
Co-authored-by: Sin <[email protected]>
  • Loading branch information
enpitsuLin and sino1641 authored Nov 28, 2023
1 parent 36371f0 commit 39db83b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
- cron: "0 20 * * *"
workflow_dispatch:


jobs:
attendance:
runs-on: ubuntu-latest
Expand All @@ -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
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
.env

package-lock.json
.vscode
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
<details>
<summary>最终可能有的 secrets 如下</summary>

| Name | Secret |
| ------------------ | ---------------------- |
| SKLAND_TOKEN * | 森空岛 token |
| SERVERCHAN_SENDKEY | Server酱推送密钥,可选 |
| BARK_URL | Bark 推送地址,可选 |

| Name | Secret |
| ------------------ | ---------------------------------------------------------------- |
| SKLAND_TOKEN \* | 森空岛 token <br>多账号使用半角逗号`,`分割 |
| SERVERCHAN_SENDKEY | Server 酱推送密钥,可选 |
| BARK_URL | Bark 推送地址,可选 |
</details>

### 启动 Github Action
Expand Down
21 changes: 11 additions & 10 deletions main.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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()
}

Expand Down
6 changes: 6 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ export function generateSignature<T extends Record<string, string>>(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('')
}

0 comments on commit 39db83b

Please sign in to comment.