优化,减少由于京东数据异常导致脚本出错

This commit is contained in:
lxk0301
2021-03-30 09:12:56 +08:00
parent f27c1d141e
commit 2efd691ae9

View File

@ -1,6 +1,6 @@
/*
种豆得豆 脚本更新地址https://gitee.com/lxk0301/jd_scripts/raw/master/jd_plantBean.js
更新时间2021-2-27
更新时间2021-3-30
活动入口京东APP我的-更多工具-种豆得豆
已支持IOS京东双账号,云端N个京东账号
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
@ -90,7 +90,7 @@ async function jdPlantBean() {
console.log(`获取任务及基本信息`)
await plantBeanIndex();
// console.log(plantBeanIndexResult.data.taskList);
if ($.plantBeanIndexResult.code === '0') {
if ($.plantBeanIndexResult && $.plantBeanIndexResult.code === '0') {
const shareUrl = $.plantBeanIndexResult.data.jwordShareInfo.shareUrl
$.myPlantUuid = getParam(shareUrl, 'plantUuid')
console.log(`\n【京东账号${$.index}${$.UserName})的${$.name}好友互助码】${$.myPlantUuid}\n`);
@ -130,7 +130,7 @@ async function doGetReward() {
//收获
await getReward();
console.log('开始领取京豆');
if ($.getReward.code === '0') {
if ($.getReward && $.getReward.code === '0') {
console.log('京豆领取成功');
message += `【上期兑换京豆】${$.getReward.data.awardBean}\n`;
$.msg($.name, subTitle, message);
@ -138,6 +138,8 @@ async function doGetReward() {
// if ($.isNode()) {
// await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName || $.UserName}`, `京东账号${$.index} ${$.nickName}\n${message}`);
// }
} else {
console.log(`$.getReward 异常:${JSON.stringify($.getReward)}`)
}
} else if (awardState === '6') {
//京豆已领取
@ -151,7 +153,7 @@ async function doGetReward() {
}
async function doCultureBean() {
await plantBeanIndex();
if ($.plantBeanIndexResult.code === '0') {
if ($.plantBeanIndexResult && $.plantBeanIndexResult.code === '0') {
const plantBeanRound = $.plantBeanIndexResult.data.roundList[1]
if (plantBeanRound.roundState === '2') {
//收取营养液
@ -168,7 +170,7 @@ async function doCultureBean() {
}
async function stealFriendWater() {
await stealFriendList();
if ($.stealFriendList.code === '0') {
if ($.stealFriendList && $.stealFriendList.code === '0') {
if ($.stealFriendList.data.tips) {
console.log('偷取好友营养液今日已达上限');
return
@ -182,7 +184,7 @@ async function stealFriendWater() {
console.log(`可以偷的好友的信息paradiseUuid::${JSON.stringify(item.paradiseUuid)}`);
await collectUserNutr(item.paradiseUuid);
console.log(`偷取好友营养液情况:${JSON.stringify($.stealFriendRes)}`)
if ($.stealFriendRes.code === '0') {
if ($.stealFriendRes && $.stealFriendRes.code === '0') {
console.log(`偷取好友营养液成功`)
}
}
@ -192,18 +194,20 @@ async function stealFriendWater() {
console.log(`可以偷的好友的信息paradiseUuid::${JSON.stringify(item.paradiseUuid)}`);
await collectUserNutr(item.paradiseUuid);
console.log(`偷取好友营养液情况:${JSON.stringify($.stealFriendRes)}`)
if ($.stealFriendRes.code === '0') {
if ($.stealFriendRes && $.stealFriendRes.code === '0') {
console.log(`偷取好友营养液成功`)
}
}
}
}
}
} else {
console.log(`$.stealFriendList 异常: ${JSON.stringify($.stealFriendList)}`)
}
}
async function doEgg() {
await egg();
if ($.plantEggLotteryRes.code === '0') {
if ($.plantEggLotteryRes && $.plantEggLotteryRes.code === '0') {
if ($.plantEggLotteryRes.data.restLotteryNum > 0) {
const eggL = new Array($.plantEggLotteryRes.data.restLotteryNum).fill('');
console.log(`目前共有${eggL.length}次扭蛋的机会`)
@ -216,7 +220,7 @@ async function doEgg() {
console.log('暂无扭蛋机会')
}
} else {
console.log('查询天天扭蛋的机会失败')
console.log('查询天天扭蛋的机会失败' + JSON.stringify($.plantEggLotteryRes))
}
}
async function doTask() {
@ -269,7 +273,7 @@ async function doTask() {
}
const shopRes = await requestGet('shopNutrientsTask', body);
console.log(`shopRes结果:${JSON.stringify(shopRes)}`);
if (shopRes.code === '0') {
if (shopRes && shopRes.code === '0') {
if (shopRes.data && shopRes.data.nutrState && shopRes.data.nutrState === '1') {
unFinishedShopNum --;
}
@ -310,7 +314,7 @@ async function doTask() {
"skuId": skuId
}
const productRes = await requestGet('productNutrientsTask', body);
if (productRes.code === '0') {
if (productRes && productRes.code === '0') {
// console.log('nutrState', productRes)
//这里添加多重判断,有时候会出现活动太火爆的问题,导致nutrState没有
if (productRes.data && productRes.data.nutrState && productRes.data.nutrState === '1') {
@ -355,7 +359,7 @@ async function doTask() {
}
const channelRes = await requestGet('plantChannelNutrientsTask', body);
console.log(`channelRes结果:${JSON.stringify(channelRes)}`);
if (channelRes.code === '0') {
if (channelRes && channelRes.code === '0') {
if (channelRes.data && channelRes.data.nutrState && channelRes.data.nutrState === '1') {
unFinishedChannelNum --;
}
@ -392,7 +396,7 @@ async function doHelp() {
continue
}
await helpShare(plantUuid);
if ($.helpResult.code === '0') {
if ($.helpResult && $.helpResult.code === '0') {
// console.log(`助力好友结果: ${JSON.stringify($.helpResult.data.helpShareRes)}`);
if ($.helpResult.data.helpShareRes) {
if ($.helpResult.data.helpShareRes.state === '1') {