优化京喜工厂脚本商品可兑换时的通知频率
比如兑换(超时)截止时间是2020/12/8 09:20:04,现在时间是2020/12/6 一:在兑换超时这一天(2020/12/8 09:20:04)的前2小时内通知 二:在兑换超时日期前的时间每天仅仅通知三次(2020/12/6 9,10,11点,以及在2020/12/7 9,10,11点各通知一次)
This commit is contained in:
@@ -32,7 +32,7 @@ const notify = $.isNode() ? require('./sendNotify') : '';
|
||||
let jdNotify = true;//是否关闭通知,false打开通知推送,true关闭通知推送
|
||||
const randomCount = $.isNode() ? 20 : 5;
|
||||
const tuanActiveId = `jfkcidGQavswLOBcAWljrw==`;
|
||||
|
||||
const jxOpenUrl = `openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%20%22des%22:%20%22m%22,%20%22url%22:%20%22https://wqsd.jd.com/pingou/dream_factory/index.html%22%20%7D`;
|
||||
let cookiesArr = [], cookie = '', message = '';
|
||||
const inviteCodes = ['V5LkjP4WRyjeCKR9VRwcRX0bBuTz7MEK0-E99EJ7u0k=', 'PDPM257r_KuQhil2Y7koNw==', "gB99tYLjvPcEFloDgamoBw=="];
|
||||
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
|
||||
@@ -101,6 +101,7 @@ async function jdDreamFactory() {
|
||||
await stealFriend();
|
||||
await tuanActivity();
|
||||
await QueryAllTuan();
|
||||
await exchangeProNotify();
|
||||
await showMsg();
|
||||
}
|
||||
|
||||
@@ -425,7 +426,7 @@ function QueryFriendList() {
|
||||
$.log(`【今日招工进度】${hireListToday.length}/${hireNumMax}`);
|
||||
message += `【招工进度】${hireListToday.length}/${hireNumMax}\n`;
|
||||
} else {
|
||||
console.log(`异常:${JSON.stringify(data)}`)
|
||||
console.log(`QueryFriendList异常:${JSON.stringify(data)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -493,7 +494,7 @@ function doTask(taskId) {
|
||||
if (data['ret'] === 0) {
|
||||
console.log("做任务完成!")
|
||||
} else {
|
||||
console.log(`异常:${JSON.stringify(data)}`)
|
||||
console.log(`DoTask异常:${JSON.stringify(data)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -521,6 +522,7 @@ function userInfo() {
|
||||
data = data['data'];
|
||||
$.unActive = true;//标记是否开启了京喜活动或者选购了商品进行生产
|
||||
$.encryptPin = '';
|
||||
$.shelvesList = [];
|
||||
if (data.factoryList && data.productionList) {
|
||||
const production = data.productionList[0];
|
||||
const factory = data.factoryList[0];
|
||||
@@ -546,8 +548,8 @@ function userInfo() {
|
||||
message += `【当前等级】${data.user.userIdentity} ${data.user.currentLevel}\n`;
|
||||
message += `【生产进度】${((production.investedElectric / production.needElectric) * 100).toFixed(2)}%\n`;
|
||||
if (production.investedElectric >= production.needElectric) {
|
||||
$.msg($.name, ``, `【京东账号${$.index}】${$.nickName}\n【生产商品】${$.productName}\n已生产完,请速去京喜APP->首页->好物0元造进行兑换`, {'open-url': 'openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%20%22des%22:%20%22m%22,%20%22url%22:%20%22https://wqsd.jd.com/pingou/dream_factory/index.html%22%20%7D'})
|
||||
await notify.sendNotify(`${$.name} - 京东账号${$.index} - ${$.nickName}`, `【京东账号${$.index}】${$.nickName}\n【生产商品】${$.productName}\n已生产完,请速去京喜APP->首页->好物0元造进行兑换`)
|
||||
$.log(`可以对方商品了`)
|
||||
// await exchangeProNotify()
|
||||
}
|
||||
} else {
|
||||
$.unActive = false;//标记是否开启了京喜活动或者选购了商品进行生产
|
||||
@@ -560,7 +562,7 @@ function userInfo() {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log(`异常:${JSON.stringify(data)}`)
|
||||
console.log(`GetUserInfo异常:${JSON.stringify(data)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -588,7 +590,39 @@ function GetCommodityDetails() {
|
||||
data = data['data'];
|
||||
$.productName = data['commodityList'][0].name;
|
||||
} else {
|
||||
console.log(`异常:${JSON.stringify(data)}`)
|
||||
console.log(`GetCommodityDetails异常:${JSON.stringify(data)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
$.logErr(e, resp)
|
||||
} finally {
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
// 查询已完成商品
|
||||
function GetShelvesList(pageNo = 1) {
|
||||
return new Promise(async resolve => {
|
||||
$.get(taskurl('userinfo/GetShelvesList', `pageNo=${pageNo}&pageSize=12`), (err, resp, data) => {
|
||||
try {
|
||||
if (err) {
|
||||
console.log(`${JSON.stringify(err)}`)
|
||||
console.log(`${$.name} API请求失败,请检查网路重试`)
|
||||
} else {
|
||||
if (safeGet(data)) {
|
||||
data = JSON.parse(data);
|
||||
if (data['ret'] === 0) {
|
||||
data = data['data'];
|
||||
const { shelvesList } = data;
|
||||
if (shelvesList) {
|
||||
$.shelvesList = [...$.shelvesList, ...shelvesList];
|
||||
pageNo ++
|
||||
GetShelvesList(pageNo);
|
||||
}
|
||||
} else {
|
||||
console.log(`GetShelvesList异常:${JSON.stringify(data)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1164,6 +1198,50 @@ function updateTuanIdsCDN(url = 'https://raw.fastgit.org/lxk0301/updateTeam/mast
|
||||
})
|
||||
})
|
||||
}
|
||||
function checkExchange() {
|
||||
|
||||
}
|
||||
//商品可兑换时的通知
|
||||
async function exchangeProNotify() {
|
||||
await GetShelvesList();
|
||||
let exchangeEndTime, exchangeEndHours, nowHours;
|
||||
//脚本运行的UTC+8时区的时间戳
|
||||
let nowTimes = new Date(new Date().getTime() + new Date().getTimezoneOffset()*60*1000 + 8*60*60*1000);
|
||||
if ($.shelvesList && $.shelvesList.length > 0) console.log(`\n 商品名 兑换状态`)
|
||||
for (let shel of $.shelvesList) {
|
||||
console.log(`${shel['name']} ${shel['exchangeStatus'] === 1 ? '未兑换' : shel['exchangeStatus'] === 2 ? '已兑换' : '兑换超时'}`)
|
||||
if (shel['exchangeStatus'] === 1) {
|
||||
exchangeEndTime = shel['exchangeEndTime'] * 1000;
|
||||
$.picture = shel['picture'];
|
||||
// 兑换截止时间点
|
||||
exchangeEndHours = new Date(exchangeEndTime + new Date().getTimezoneOffset()*60*1000 + 8*60*60*1000).getHours();
|
||||
//兑换截止时间(年月日 时分秒)
|
||||
$.exchangeEndTime = new Date(exchangeEndTime + new Date().getTimezoneOffset()*60*1000 + 8*60*60*1000).toLocaleString('zh', {hour12: false});
|
||||
//脚本运行此时的时间点
|
||||
nowHours = nowTimes.getHours();
|
||||
}
|
||||
}
|
||||
if (exchangeEndTime) {
|
||||
//比如兑换(超时)截止时间是2020/12/8 09:20:04,现在时间是2020/12/6
|
||||
if (nowTimes < exchangeEndTime) {
|
||||
//还可以兑换
|
||||
// 一:在兑换超时这一天(2020/12/8 09:20:04)的前2小时内通知
|
||||
if ((exchangeEndTime - nowTimes) <= 3600000 * 2) {
|
||||
$.msg($.name, ``, `【京东账号${$.index}】${$.nickName}\n【生产商品】${$.productName}${(exchangeEndTime - nowTimes) / 60*60*1000}分钟后兑换超时\n【兑换截止时间】${$.exchangeEndTime}\n请速去京喜APP->首页->好物0元造进行兑换`, {'open-url': jxOpenUrl, 'media-url': $.picture})
|
||||
await notify.sendNotify(`${$.name} - 京东账号${$.index} - ${$.nickName}`, `【京东账号${$.index}】${$.nickName}\n【生产商品】${$.productName}${(exchangeEndTime - nowTimes) / 60*60*1000}分钟后兑换超时\n【兑换截止时间】${$.exchangeEndTime}\n请速去京喜APP->首页->好物0元造进行兑换`, { url: jxOpenUrl })
|
||||
}
|
||||
//二:在兑换超时日期前的时间一天通知三次(2020/12/6 9,10,11点,以及在2020/12/7 9,10,11点各通知一次)
|
||||
if (nowHours === exchangeEndHours || nowHours === (exchangeEndHours + 1) || nowHours === (exchangeEndHours + 2)) {
|
||||
$.msg($.name, ``, `【京东账号${$.index}】${$.nickName}\n【生产商品】${$.productName}已可兑换\n【兑换截止时间】${$.exchangeEndTime}\n请速去京喜APP->首页->好物0元造进行兑换`, {'open-url': jxOpenUrl, 'media-url': $.picture})
|
||||
await notify.sendNotify(`${$.name} - 京东账号${$.index} - ${$.nickName}`, `【京东账号${$.index}】${$.nickName}\n【生产商品】${$.productName}已可兑换\n【兑换截止时间】${$.exchangeEndTime}\n请速去京喜APP->首页->好物0元造进行兑换`, { url: jxOpenUrl })
|
||||
}
|
||||
} else {
|
||||
//兑换已超时
|
||||
$.msg($.name, ``, `【京东账号${$.index}】${$.nickName}\n【生产商品】${$.productName}兑换已超时,请重新选择商品生产\n【兑换截止时间】${$.exchangeEndTime}`, {'open-url': jxOpenUrl})
|
||||
await notify.sendNotify(`${$.name} - 京东账号${$.index} - ${$.nickName}`, `【京东账号${$.index}】${$.nickName}\n【生产商品】${$.productName}兑换已超时,请重新选择商品生产\n【兑换截止时间】${$.exchangeEndTime}`, { url: jxOpenUrl })
|
||||
}
|
||||
}
|
||||
}
|
||||
async function showMsg() {
|
||||
return new Promise(async resolve => {
|
||||
message += `【收取自己零件】${$.pickUpMyselfComponent ? `获得${$.pickEle}电力` : `今日已达上限`}\n`;
|
||||
|
Reference in New Issue
Block a user