From 41d9dd28ff512067bc2cb2bf76b589f719aa0698 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 11 Oct 2024 08:35:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=84=E7=90=86=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E7=AD=BE=E5=88=B0=E8=BF=87=E7=9A=84=E6=8A=A5=E9=94=99=20(#56)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3e9c1a0..499fa27 100644 --- a/src/index.ts +++ b/src/index.ts @@ -58,27 +58,34 @@ export async function doAttendanceForAccount(token: string, options: Options) { const characterList = list.map(i => i.bindingList).flat() await Promise.all(characterList.map(async (character) => { console.log(`将签到第${successAttendance + 1}个角色`) - const data = await attendance(cred, signToken, { - uid: character.uid, - gameId: character.channelMasterId, - }) - if (data) { - if (data.code === 0 && data.message === 'OK') { - 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 { + try { + const data = await attendance(cred, signToken, { + uid: character.uid, + gameId: character.channelMasterId, + }) + if (data) { + if (data.code === 0 && data.message === 'OK') { + 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 = `${(Number(character.channelMasterId) - 1) ? 'B 服' : '官服'}角色 ${getPrivacyName(character.nickName)} 签到失败${`, 错误消息: ${data.message}\n\n\`\`\`json\n${JSON.stringify(data, null, 2)}\n\`\`\``}` combineMessage(msg, true) - } - - // 多个角色之间的延时 - await setTimeout(3000) - } - else { + } + } else { combineMessage(`${(Number(character.channelMasterId) - 1) ? 'B 服' : '官服'}角色 ${getPrivacyName(character.nickName)} 今天已经签到过了`) + } + } catch (error: any) { + if (error.response && error.response.status === 403) { + combineMessage(`${(Number(character.channelMasterId) - 1) ? 'B 服' : '官服'}角色 ${getPrivacyName(character.nickName)} 今天已经签到过了`) + } else { + combineMessage(`签到过程中出现未知错误: ${error.message}`, true) + console.error("发生未知错误,工作流终止。") + process.exit(1) + } } + // 多个角色之间的延时 + await setTimeout(3000) })) if (successAttendance !== 0) combineMessage(`成功签到${successAttendance}个角色`)