Skip to content

Commit

Permalink
fix: 未绑定 token 的用户使用鸣潮抽卡分析报错
Browse files Browse the repository at this point in the history
  • Loading branch information
TomyJan committed Jun 4, 2024
1 parent 2ab50fc commit 4cd56b7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.2.8-rel](https://github.com/TomyJan/Yunzai-Kuro-Plugin/compare/v0.2.7-rel...v0.2.8-rel) (2024-06-04)



## [0.2.7-rel](https://github.com/TomyJan/Yunzai-Kuro-Plugin/compare/v0.2.6-rel...v0.2.7-rel) (2024-06-04)


Expand Down
4 changes: 2 additions & 2 deletions model/kuroApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export default class kuroApi {
let rsp = ''

// 特殊 API 的调用处理
if (ApiName == 'sdkLogin') {
if (ApiName == 'sdkLogin' || ApiName == 'mcGachaRecord') {
rsp = await this.kuroApiHandler.getApiRsp(ApiName, null, null, data)
} else if (ApiName == 'checkToken_mineV2') {
ApiName == 'mineV2'
rsp = await this.kuroApiHandler.getApiRsp(
'mineV2',
ApiName,
kuroUid,
data.token,
data
Expand Down
2 changes: 1 addition & 1 deletion model/kuroApiHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class kuroApiHandler {
* 取库洛接口返回
* 调用其他接口前请先校验 token 有效性
* @param {string} ApiName 接口名称
* @param {string|boolean} kuroUid 库洛 ID, sdkLogin 时传入 false
* @param {string|boolean} kuroUid 库洛 ID, sdkLogin 和 mcGachaRecord 传入 false
* @param {string} token 库洛 ID 的 token
* @param {object} data 传入数据
* @returns {JSON|string} 接口返回的 原始 json 或者报错信息
Expand Down
3 changes: 2 additions & 1 deletion model/kuroBBSTokenHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function saveToken(uin, kuro_uid, kuro_token, kuro_refreshToken) {
/**
* 从文件获取用户的 token 数据
* @param {number} uin QQ 号
* @returns {object} 多账号的原始 token 数据
* @returns {object|null} 多账号的原始 token 数据, 用户没有 token 时返回 null
*/
export async function getToken(uin) {
const filePath = dataPath + `/token/${uin}.json`
Expand All @@ -77,6 +77,7 @@ export async function getToken(uin) {
} catch (error) {
if (error.code === 'ENOENT') {
kuroLogger.info(`Token 文件不存在: ${filePath}`)
return null
} else {
kuroLogger.warn(`读取 Token 文件时出错: ${error.message}`)
}
Expand Down
33 changes: 19 additions & 14 deletions model/userConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,28 @@ export default class userConfig {
kuroLogger.debug(`库洛 uid 为 0, 尝试通过 api 遍历找出 uid...`)
let tokenData = await getToken(qq)
let kuroUidIndex = 0
let kuroUidToFetch = Object.keys(tokenData)[kuroUidIndex]
let kuroapi = new kuroApi(qq)
do {
let rsp_roleList = await kuroapi.roleList(kuroUidToFetch, { gameId })
if (typeof rsp_roleList !== 'string') {
if (rsp_roleList.data.length > 0) {
for (const role of rsp_roleList.data) {
if (role.roleId === uid) {
kuro_uid = kuroUidToFetch
kuroLogger.debug(`找到 uid: ${uid} 所在的库洛 uid: ${kuro_uid}`)
break
if(tokenData){
let kuroUidToFetch = Object.keys(tokenData)[kuroUidIndex]
let kuroapi = new kuroApi(qq)
do {
let rsp_roleList = await kuroapi.roleList(kuroUidToFetch, { gameId })
if (typeof rsp_roleList !== 'string') {
if (rsp_roleList.data.length > 0) {
for (const role of rsp_roleList.data) {
if (role.roleId === uid) {
kuro_uid = kuroUidToFetch
kuroLogger.debug(`找到 uid: ${uid} 所在的库洛 uid: ${kuro_uid}`)
break
}
}
}
}
}
kuroUidToFetch = Object.keys(tokenData)[++kuroUidIndex]
} while (kuroUidIndex < Object.keys(tokenData).length)
kuroUidToFetch = Object.keys(tokenData)[++kuroUidIndex]
} while (kuroUidIndex < Object.keys(tokenData).length)
} else {
kuroLogger.info(`用户 ${qq} 没有绑定 token, 无法通过 api 遍历找出 uid`)
}

}
try {
const qqData = { gameUid: uid, inKuroUid: kuro_uid }
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Yunzai-Kuro-Plugin",
"version": "0.2.7-rel",
"version": "0.2.8-rel",
"author": "TomyJan",
"description": "Yunzai-Bot plugin for kuro games.",
"type": "module",
Expand Down

0 comments on commit 4cd56b7

Please sign in to comment.