Merge pull request #242 from FanchangWang/master

[集鞭炮赢京豆] 跳过黑号任务 & 增加兑换 x 京豆通知(通过环境变量控制)
This commit is contained in:
LXK9301
2021-01-25 16:29:03 +08:00
committed by GitHub
2 changed files with 43 additions and 15 deletions

View File

@ -86,6 +86,7 @@
| `JD_WECHAT_USER_AGENT` | 京东炸年兽<br>小程序<br>自定义UA | 非必须 | 强烈推荐使用自定义的小程序UA防止黑号UA示例<br>Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15A148 MicroMessenger/7.0.20(0x17001320) NetType/WIFI Language/zh_CN |
| `DREAMFACTORY_FORBID_ACCOUNT`| 京喜工厂<br>控制哪个京东账号不运行此脚本 | 非必须 | 输入`1`代表第一个京东账号不运行,多个使用`&`连接,例:`1&3`代表账号1和账号3不运行京喜工厂脚本输入`0`,代表全部账号不运行京喜工厂脚本 |
| `JDFACTORY_FORBID_ACCOUNT`| 东东工厂<br>控制哪个京东账号不运行此脚本 | 非必须 | 输入`1`代表第一个京东账号不运行,多个使用`&`连接,例:`1&3`代表账号1和账号3不运行东东工厂脚本输入`0`,代表全部账号不运行东东工厂脚本 |
| `FIRECRACKERS_NOTITY_BEAN`| 集鞭炮赢京豆<br>满足兑换 X 个京豆通知开关 | 非必须 | 默认 0 不通知,输入 120 表示满足兑换 120 个京豆时通知 |
##### 互助码的填写规则

View File

@ -26,6 +26,7 @@ cron "10 8,21 * * *" script-path=https://raw.githubusercontent.com/LXK9301/jd_sc
*/
const $ = new Env('集鞭炮赢京豆');
const notify = $.isNode() ? require('./sendNotify') : '';
let notifyBean = $.isNode() ? process.env.FIRECRACKERS_NOTITY_BEAN || 0 : 0; // 账号满足兑换多少京豆时提示 默认 0 不提示格式120 表示能兑换 120 豆子发出通知;
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
//Node.js用户请在jdCookie.js处填写京东ck;
//IOS等用户直接用NobyDa的jd cookie
@ -92,9 +93,25 @@ async function jdFamily() {
}
function showMsg() {
return new Promise(resolve => {
message += `本次运行获得鞭炮${$.earn},共计${$.total}🧨`
$.log($.name, '', `京东账号${$.index}${$.nickName}\n${message}`);
return new Promise(async resolve => {
subTitle = `【京东账号${$.index}${$.nickName}`;
message += `【鞭炮🧨】本次获得 ${$.earn},共计${$.total}\n`
if ($.total && notifyBean) {
for (let item of $.prize) {
if (notifyBean >= item.beansPerNum) { // 符合预定的京豆档位
if ($.total >= item.prizerank) { // 当前鞭炮满足兑换
message += `【京豆】请手动兑换 ${item.beansPerNum} 个京豆,需消耗花费🧨 ${item.prizerank}`
$.msg($.name, subTitle, message);
if ($.isNode()) {
await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName}`, `${subTitle}\n${message}`);
resolve();
return;
}
}
}
}
}
$.log(`${$.name}\n\n账号${$.index} - ${$.nickName}\n${subTitle}\n${message}`);
resolve()
})
}
@ -130,17 +147,22 @@ function getUserInfo(info = false) {
$.userInfo = JSON.parse(data.match(/query\((.*)\n/)[1])
if (info) {
$.earn = $.userInfo.tatalprofits - $.total
} else for (let task of $.info.config.tasks) {
let vo = $.userInfo.tasklist.filter(vo => vo.taskid === task['_id'])
if (vo.length > 0) {
vo = vo[0]
if (vo['isdo'] === 1) {
if (vo['times'] === 0) {
console.log(`去做任务${task['_id']}`)
await doTask(task['_id'])
await $.wait(3000)
} else {
console.log(`${Math.trunc(vo['times'] / 60)}分钟可后做任务${task['_id']}`)
} else {
for (let task of $.info.config.tasks) {
let vo = $.userInfo.tasklist.filter(vo => vo.taskid === task['_id'])
if (vo.length > 0) {
vo = vo[0]
if (vo['isdo'] === 1) {
if (vo['times'] === 0) {
console.log(`去做任务${task['_id']}`)
let res = await doTask(task['_id'])
if (!res) { // 黑号,不再继续执行任务
break;
}
await $.wait(3000)
} else {
console.log(`${Math.trunc(vo['times'] / 60)}分钟可后做任务${task['_id']}`)
}
}
}
}
@ -165,9 +187,14 @@ function doTask(taskId) {
console.log(`${err},${jsonParse(resp.body)['message']}`)
console.log(`${$.name} API请求失败请检查网路重试`)
} else {
data = JSON.parse(data.match(/query\((.*)\n/)[1])
let res = data.match(/query\((.*)\n/)[1];
data = JSON.parse(res);
if (data.ret === 0) {
console.log(`任务完成成功`)
} else if (data.ret === 1001) {
console.log(`任务完成失败,原因:这个账号黑号了!!!`)
resolve(false);
return;
} else {
console.log(`任务完成失败,原因未知`)
}