Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

避免多次调用init() #375

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions B站直播间挂机助手.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,26 +513,37 @@
return window.toast(`直播间礼物数据获取失败 ${response.message}\n使用默认数据`, 'warning');
}
});
await BAPI.getuserinfo().then((re) => {
MYDEBUG('InitData: API.getuserinfo', re);
if (re.code === 'REPONSE_OK') {
Live_info.uname = re.data.uname;
Live_info.user_level = re.data.user_level;
} else {
window.toast(`API.getuserinfo 获取用户信息失败 ${re.message}`, 'error');
return delayCall(() => loadInfo());
}
});
await BAPI.x.getAccInfo(Live_info.uid).then((re) => {
MYDEBUG('InitData: API.x.getAccInfo', re);
if (re.code === 0) {
Live_info.level = re.data.level;
Live_info.vipStatus = re.data.vip.status;
} else {
window.toast(`API.x.getAccInfo 获取账号信息失败 ${re.message}`, 'error');
return delayCall(() => loadInfo());
}
});
while (true) {
let successed = await BAPI.getuserinfo().then((re) => {
MYDEBUG('InitData: API.getuserinfo', re);
if (re.code === 'REPONSE_OK') {
Live_info.uname = re.data.uname;
Live_info.user_level = re.data.user_level;
return true
} else {
window.toast(`API.getuserinfo 获取用户信息失败 ${re.message}`, 'error');
return false;
}
});
if (successed) break;
await sleep(Math.round(Math.random() * 115 + 5) * 1000); // 5~120秒随机重试时间
}
await sleep(5000); // {"code":-509,"message":"请求过于频繁,请稍后再试","ttl":1}
while (true) {
let successed = await BAPI.x.getAccInfo(Live_info.uid).then((re) => {
MYDEBUG('InitData: API.x.getAccInfo', re);
if (re.code === 0) {
Live_info.level = re.data.level;
Live_info.vipStatus = re.data.vip.status;
return true;
} else {
window.toast(`API.x.getAccInfo 获取账号信息失败 ${re.message}`, 'error');
return false;
}
});
if (successed) break;
await sleep(Math.round(Math.random() * 115 + 5) * 1000); // 5~120秒随机重试时间
}
Live_info.bili_jct = BAPI.getCookie('bili_jct');
Live_info.ruid = W.BilibiliLive.ANCHOR_UID;
Live_info.rnd = W.BilibiliLive.RND;
Expand Down