From 415cb0d81f70f2132636d816e302b0016ed073fc Mon Sep 17 00:00:00 2001 From: Hex Date: Sat, 29 Jul 2023 16:18:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=80=E6=9C=89=E5=BB=B6=E8=BF=9F=E6=94=B9?= =?UTF-8?q?=E6=88=90=E9=9A=8F=E6=9C=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.js | 18 ++++- smzdm_checkin.js | 11 ++- smzdm_lottery.js | 18 ++--- smzdm_task.js | 174 +++++++++++++++++++---------------------------- 4 files changed, 99 insertions(+), 122 deletions(-) diff --git a/bot.js b/bot.js index b5ab388..9950a6e 100644 --- a/bot.js +++ b/bot.js @@ -161,6 +161,21 @@ const getEnvCookies = () => { return cookies[0] ? cookies : false; }; +const randomDecimal = (min, max, decimal) => { + const rand = Math.random() * (max - min + 1) + min; + + return Math.floor(rand * decimal) / decimal; +}; + +const wait = (minSecond, maxSecond) => { + // 生成随机小数秒数 + const randomSecond = randomDecimal(minSecond, maxSecond, 1000); + + console.log(`等候 ${minSecond}-${maxSecond}(${randomSecond}) 秒`); + + return new Promise(resolve => setTimeout(resolve, randomSecond * 1000)); +}; + // ------------------------------------ class SmzdmBot { @@ -215,5 +230,6 @@ module.exports = { requestApi, removeTags, parseJSON, - getEnvCookies + getEnvCookies, + wait }; diff --git a/smzdm_checkin.js b/smzdm_checkin.js index 83dd6fa..102d2cf 100644 --- a/smzdm_checkin.js +++ b/smzdm_checkin.js @@ -6,7 +6,7 @@ cron: 10 8 * * * */ const Env = require('./env'); -const { SmzdmBot, requestApi, removeTags, getEnvCookies } = require('./bot'); +const { SmzdmBot, requestApi, removeTags, getEnvCookies, wait } = require('./bot'); const notify = require('./sendNotify'); // ------------------------------------ @@ -48,8 +48,7 @@ class SmzdmCheckinBot extends SmzdmBot { 🏅碎银: ${data.data.pre_re_silver} 🏅补签卡: ${data.data.cards}`; - $.log('等候 3 秒获取信息\n'); - await $.wait(3000); + await wait(3, 10); const vip = await this.getVipInfo(); @@ -129,8 +128,7 @@ class SmzdmCheckinBot extends SmzdmBot { }; } - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 10); const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/checkin/extra_reward', { method: 'post', @@ -230,8 +228,7 @@ class SmzdmCheckinBot extends SmzdmBot { const sk = sks[i]; if (i > 0) { - $.log('\n延迟 10 秒执行\n'); - await $.wait(10000); + await wait(10, 30); } const sep = `\n****** 账号${i + 1} ******\n`; diff --git a/smzdm_lottery.js b/smzdm_lottery.js index fc3a3ac..17e368c 100644 --- a/smzdm_lottery.js +++ b/smzdm_lottery.js @@ -6,7 +6,7 @@ cron: 20 8 * * * */ const Env = require('./env'); -const { SmzdmBot, requestApi, parseJSON, getEnvCookies } = require('./bot'); +const { SmzdmBot, requestApi, parseJSON, getEnvCookies, wait } = require('./bot'); const notify = require('./sendNotify'); // ------------------------------------ @@ -24,22 +24,21 @@ class SmzdmLotteryBot extends SmzdmBot { const lifeId = await this.getActivityIdFromLife(); if (lifeId) { - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); notifyMsg += `转盘抽奖ID: ${lifeId}\n`; notifyMsg += await this.draw(lifeId); notifyMsg += '\n\n'; } - $.log('\n等候 5 秒\n'); - await $.wait(5000); + $.log(); + await wait(5, 15); + $.log(); const vipId = await this.getActivityIdFromVip(); if (vipId) { - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); notifyMsg += `转盘抽奖ID: ${vipId}\n`; notifyMsg += await this.draw(vipId); @@ -177,8 +176,9 @@ class SmzdmLotteryBot extends SmzdmBot { } if (i > 0) { - $.log('\n延迟 10 秒执行\n'); - await $.wait(10000); + $.log(); + await wait(10, 30); + $.log(); } const sep = `\n****** 账号${i + 1} ******\n`; diff --git a/smzdm_task.js b/smzdm_task.js index a8ef80d..c034ea0 100644 --- a/smzdm_task.js +++ b/smzdm_task.js @@ -6,7 +6,7 @@ cron: 20 14 * * * */ const Env = require('./env'); -const { SmzdmBot, requestApi, removeTags, getEnvCookies } = require('./bot'); +const { SmzdmBot, requestApi, removeTags, getEnvCookies, wait } = require('./bot'); const notify = require('./sendNotify'); // ------------------------------------ @@ -24,8 +24,7 @@ class SmzdmTaskBot extends SmzdmBot { const { tasks } = await this.getTaskList(); - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 10); let notifyMsg = ''; @@ -40,8 +39,7 @@ class SmzdmTaskBot extends SmzdmBot { notifyMsg += `${isSuccess ? '🟢' : '❌'}领取[${task.task_name}]奖励${isSuccess ? '成功' : '失败!请查看日志'}\n`; - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } // 未完成任务 else if (task.task_status == '2') { @@ -51,8 +49,7 @@ class SmzdmTaskBot extends SmzdmBot { notifyMsg += this.getTaskNotifyMessage(isSuccess, task); - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } // 分享任务 else if (task.task_event_type == 'interactive.share') { @@ -60,8 +57,7 @@ class SmzdmTaskBot extends SmzdmBot { notifyMsg += this.getTaskNotifyMessage(isSuccess, task); - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } // 抽奖任务 else if (task.task_event_type == 'guide.crowd') { @@ -71,8 +67,7 @@ class SmzdmTaskBot extends SmzdmBot { notifyMsg += this.getTaskNotifyMessage(isSuccess, task); } - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } // 关注用户任务 else if (task.task_event_type == 'interactive.follow.user') { @@ -80,8 +75,7 @@ class SmzdmTaskBot extends SmzdmBot { notifyMsg += this.getTaskNotifyMessage(isSuccess, task); - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } // 关注栏目任务 else if (task.task_event_type == 'interactive.follow.tag') { @@ -89,8 +83,7 @@ class SmzdmTaskBot extends SmzdmBot { notifyMsg += this.getTaskNotifyMessage(isSuccess, task); - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } // 关注品牌 else if (task.task_event_type == 'interactive.follow.brand') { @@ -98,8 +91,7 @@ class SmzdmTaskBot extends SmzdmBot { notifyMsg += this.getTaskNotifyMessage(isSuccess, task); - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } // 收藏任务 else if (task.task_event_type == 'interactive.favorite') { @@ -107,8 +99,7 @@ class SmzdmTaskBot extends SmzdmBot { notifyMsg += this.getTaskNotifyMessage(isSuccess, task); - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } // 点赞任务 else if (task.task_event_type == 'interactive.rating') { @@ -116,8 +107,7 @@ class SmzdmTaskBot extends SmzdmBot { notifyMsg += this.getTaskNotifyMessage(isSuccess, task); - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } // 评论任务 else if (task.task_event_type == 'interactive.comment') { @@ -126,8 +116,7 @@ class SmzdmTaskBot extends SmzdmBot { notifyMsg += this.getTaskNotifyMessage(isSuccess, task); - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } else { $.log('🟡请设置 SMZDM_COMMENT 环境变量后才能做评论任务!'); @@ -136,15 +125,15 @@ class SmzdmTaskBot extends SmzdmBot { } } - $.log('等候 5 秒查询是否有限时累计活动阶段奖励'); - await $.wait(5000); + $.log('查询是否有限时累计活动阶段奖励'); + await wait(5, 15); // 领取活动奖励 const { detail } = await this.getTaskList(); if (detail.cell_data && detail.cell_data.activity_reward_status == '1') { - $.log('有奖励,等候 3 秒领取奖励'); - await $.wait(5000); + $.log('有奖励,领取奖励'); + await wait(5, 15); const { isSuccess } = await this.receiveActivity(detail.cell_data); @@ -176,8 +165,7 @@ class SmzdmTaskBot extends SmzdmBot { // 随机选一篇文章来评论 const article = articles[Math.floor(Math.random() * articles.length)]; - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); const {isSuccess, data } = await this.submitComment({ articleId: article.article_id, @@ -191,21 +179,21 @@ class SmzdmTaskBot extends SmzdmBot { }; } - $.log('等候 20 秒删除评论'); - await $.wait(20000); + $.log('删除评论'); + await wait(20, 30); const {isSuccess: result } = await this.removeComment(data.data.comment_ID); if (!result) { - $.log('等候 10 秒再试一次'); - await $.wait(10000); + $.log('再试一次'); + await wait(10, 20); // 不成功再执行一次删除 await this.removeComment(data.data.comment_ID); } - $.log('延迟 5 秒领取奖励'); - await $.wait(5000); + $.log('领取奖励'); + await wait(5, 15); return await this.receiveReward(task.task_id); } @@ -248,8 +236,7 @@ class SmzdmTaskBot extends SmzdmBot { }; } - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); if (article.article_price) { // 点值 @@ -260,8 +247,7 @@ class SmzdmTaskBot extends SmzdmBot { channelId: article.article_channel_id }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.rating({ method: 'worth_create', @@ -270,8 +256,7 @@ class SmzdmTaskBot extends SmzdmBot { channelId: article.article_channel_id }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.rating({ method: 'worth_cancel', @@ -288,8 +273,7 @@ class SmzdmTaskBot extends SmzdmBot { channelId: article.article_channel_id }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.rating({ method: 'like_create', @@ -297,8 +281,7 @@ class SmzdmTaskBot extends SmzdmBot { channelId: article.article_channel_id }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.rating({ method: 'like_cancel', @@ -307,8 +290,8 @@ class SmzdmTaskBot extends SmzdmBot { }); } - $.log('延迟 5 秒领取奖励'); - await $.wait(5000); + $.log('领取奖励'); + await wait(5, 15); return await this.receiveReward(task.task_id); } @@ -380,8 +363,7 @@ class SmzdmTaskBot extends SmzdmBot { channelId = articleDetail.channel_id; } - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.favorite({ method: 'destroy', @@ -389,8 +371,7 @@ class SmzdmTaskBot extends SmzdmBot { channelId }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.favorite({ method: 'create', @@ -398,8 +379,7 @@ class SmzdmTaskBot extends SmzdmBot { channelId }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.favorite({ method: 'destroy', @@ -407,8 +387,8 @@ class SmzdmTaskBot extends SmzdmBot { channelId }); - $.log('延迟 5 秒领取奖励'); - await $.wait(5000); + $.log('领取奖励'); + await wait(5, 15); return await this.receiveReward(task.task_id); } @@ -426,8 +406,7 @@ class SmzdmTaskBot extends SmzdmBot { }; } - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); for (let i = 0; i < Number(task.task_even_num - task.task_finished_num); i++) { if (user.is_follow == '1') { @@ -437,8 +416,7 @@ class SmzdmTaskBot extends SmzdmBot { keyword: user.keyword }); - $.log('等候 5 秒'); - await $.wait(3000); + await wait(3, 10); } await this.follow({ @@ -447,8 +425,7 @@ class SmzdmTaskBot extends SmzdmBot { keyword: user.keyword }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); if (user.is_follow == '0') { await this.follow({ @@ -458,12 +435,11 @@ class SmzdmTaskBot extends SmzdmBot { }); } - $.log('等候 5 秒'); - await $.wait(3000); + await wait(3, 10); } - $.log('延迟 5 秒领取奖励'); - await $.wait(5000); + $.log('领取奖励'); + await wait(5, 15); return await this.receiveReward(task.task_id); } @@ -485,8 +461,7 @@ class SmzdmTaskBot extends SmzdmBot { lanmuId = tag.lanmu_id; - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); } else { lanmuId = task.task_redirect_url.link_val; @@ -503,8 +478,7 @@ class SmzdmTaskBot extends SmzdmBot { }; } - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.follow({ method: 'destroy', @@ -513,8 +487,7 @@ class SmzdmTaskBot extends SmzdmBot { keyword: tagDetail.lanmu_info.lanmu_name }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.follow({ method: 'create', @@ -523,8 +496,7 @@ class SmzdmTaskBot extends SmzdmBot { keyword: tagDetail.lanmu_info.lanmu_name }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.follow({ method: 'destroy', @@ -533,8 +505,8 @@ class SmzdmTaskBot extends SmzdmBot { keyword: tagDetail.lanmu_info.lanmu_name }); - $.log('延迟 5 秒领取奖励'); - await $.wait(5000); + $.log('领取奖励'); + await wait(5, 15); return await this.receiveReward(task.task_id); } @@ -552,8 +524,7 @@ class SmzdmTaskBot extends SmzdmBot { }; } - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.followBrand({ method: 'dingyue_lanmu_del', @@ -561,8 +532,7 @@ class SmzdmTaskBot extends SmzdmBot { keyword: brandDetail.title }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.followBrand({ method: 'dingyue_lanmu_add', @@ -570,8 +540,7 @@ class SmzdmTaskBot extends SmzdmBot { keyword: brandDetail.title }); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); await this.followBrand({ method: 'dingyue_lanmu_del', @@ -579,8 +548,8 @@ class SmzdmTaskBot extends SmzdmBot { keyword: brandDetail.title }); - $.log('延迟 5 秒领取奖励'); - await $.wait(5000); + $.log('领取奖励'); + await wait(5, 15); return await this.receiveReward(task.task_id); } @@ -612,8 +581,7 @@ class SmzdmTaskBot extends SmzdmBot { } } - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); const result = await this.joinCrowd(data); @@ -623,8 +591,8 @@ class SmzdmTaskBot extends SmzdmBot { }; } - $.log('延迟 5 秒领取奖励'); - await $.wait(5000); + $.log('领取奖励'); + await wait(5, 15); return await this.receiveReward(task.task_id); } @@ -638,8 +606,7 @@ class SmzdmTaskBot extends SmzdmBot { if (task.article_id == '0') { articles = await this.getArticleList(task.task_even_num - task.task_finished_num); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); } else { articles = [{ @@ -662,20 +629,18 @@ class SmzdmTaskBot extends SmzdmBot { await this.getArticleDetail(article.article_id); } - $.log('等候 8 秒'); - await $.wait(8000); + await wait(8, 20); } await this.shareArticleDone(article.article_id, article.article_channel_id); await this.shareDailyReward(article.article_channel_id); await this.shareCallback(article.article_id, article.article_channel_id); - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } - $.log('延迟 3 秒领取奖励'); - await $.wait(3000); + $.log('领取奖励'); + await wait(3, 10); return await this.receiveReward(task.task_id); } @@ -691,8 +656,7 @@ class SmzdmTaskBot extends SmzdmBot { isRead = true; articles = await this.getArticleList(task.task_even_num - task.task_finished_num); - $.log('等候 3 秒'); - await $.wait(3000); + await wait(3, 10); } else { articles = [{ @@ -718,8 +682,8 @@ class SmzdmTaskBot extends SmzdmBot { } } - $.log('延迟 15 秒模拟阅读文章'); - await $.wait(15000); + $.log('模拟阅读文章'); + await wait(20, 50); const { isSuccess, response } = await requestApi('https://user-api.smzdm.com/task/event_view_article_sync', { method: 'post', @@ -738,12 +702,11 @@ class SmzdmTaskBot extends SmzdmBot { $.log(`完成阅读失败!${response}`); } - $.log('等候 5 秒'); - await $.wait(5000); + await wait(5, 15); } - $.log('延迟 3 秒领取奖励'); - await $.wait(3000); + $.log('领取奖励'); + await wait(3, 10); return await this.receiveReward(task.task_id); } @@ -1602,8 +1565,9 @@ class SmzdmTaskBot extends SmzdmBot { } if (i > 0) { - $.log('\n延迟 10 秒执行\n'); - await $.wait(10000); + $.log(); + await wait(10, 30); + $.log(); } const sep = `\n****** 账号${i + 1} ******\n`;