diff --git a/src/functions/Activities.ts b/src/functions/Activities.ts index 371459e..b50ccd0 100644 --- a/src/functions/Activities.ts +++ b/src/functions/Activities.ts @@ -57,16 +57,16 @@ export default class Activities { await new BrowserSearchOnBing(this.bot).doSearchOnBing(promotion, page) } - doDailySet = async (data: DashboardData): Promise => { - await new DailySet(this.bot).run(data) + doDailySet = async (data: DashboardData): Promise => { + return await new DailySet(this.bot).run(data) } - doMorePromotions = async (data: DashboardData): Promise => { - await new MorePromotions(this.bot).run(data) + doMorePromotions = async (data: DashboardData): Promise => { + return await new MorePromotions(this.bot).run(data) } - doPunchCardsMobile = async (data: DashboardData): Promise => { - await new PunchCards(this.bot).runMobile(data) + doPunchCardsMobile = async (data: DashboardData): Promise => { + return await new PunchCards(this.bot).runMobile(data) } doPunchCardsDesktop = async (): Promise => { @@ -93,9 +93,9 @@ export default class Activities { await claimReward.claimReward(child, parentId) } - doActivateSearchPerk = async (data: DashboardData): Promise => { + doActivateSearchPerk = async (data: DashboardData): Promise => { const activateSearchPerk = new ActivateSearchPerk(this.bot) - await activateSearchPerk.activate(data) + return await activateSearchPerk.activate(data) } doVisualSearch = async (data: DashboardData): Promise => { @@ -108,18 +108,18 @@ export default class Activities { await urlReward.doAppReward(promotion) } - doReadToEarn = async (): Promise => { + doReadToEarn = async (): Promise => { const readToEarn = new ReadToEarn(this.bot) - await readToEarn.doReadToEarn() + return await readToEarn.doReadToEarn() } - doDailyCheckIn = async (): Promise => { + doDailyCheckIn = async (): Promise => { const dailyCheckIn = new DailyCheckIn(this.bot) - await dailyCheckIn.doDailyCheckIn() + return await dailyCheckIn.doDailyCheckIn() } - doAppPromotions = async (data: AppDashboardData): Promise => { - await new AppPromotions(this.bot).run(data) + doAppPromotions = async (data: AppDashboardData): Promise => { + return await new AppPromotions(this.bot).run(data) } doEdgeBrowsing = async (data: DashboardData, signal?: AbortSignal): Promise => { diff --git a/src/functions/activities/api/ActivateSearchPerk.ts b/src/functions/activities/api/ActivateSearchPerk.ts index cc1ef87..0489b43 100644 --- a/src/functions/activities/api/ActivateSearchPerk.ts +++ b/src/functions/activities/api/ActivateSearchPerk.ts @@ -46,7 +46,7 @@ export function detectSearchMultiplierPerk(dashboard: Dashboard): SearchMultipli } export class ActivateSearchPerk extends BaseActivity { - public async activate(data: DashboardData) { + public async activate(data: DashboardData): Promise { const perk = detectSearchMultiplierPerk(data.dashboard) if (!perk) { this.bot.logger.debug( @@ -54,7 +54,7 @@ export class ActivateSearchPerk extends BaseActivity { 'ACTIVATE-SEARCH-PERK', 'dashboard 上没有搜索倍数加成' ) - return + return false } const live = await this.bot.browser.func.ensureOffer(perk.offerId) @@ -64,7 +64,7 @@ export class ActivateSearchPerk extends BaseActivity { 'ACTIVATE-SEARCH-PERK', `dashboard 上存在 ${perk.multiplier}x 搜索加成但页面快照中缺失 - 无法激活 | offerId=${perk.offerId}` ) - return + return false } if (!live.reportable) { @@ -74,7 +74,7 @@ export class ActivateSearchPerk extends BaseActivity { `${perk.multiplier}x 搜索加成已激活(或不可激活) | offerId=${perk.offerId}`, 'green' ) - return + return false } const actionId = this.bot.nextActions.reportActivity @@ -84,7 +84,7 @@ export class ActivateSearchPerk extends BaseActivity { 'ACTIVATE-SEARCH-PERK', '跳过:bundle 中未发现 "reportActivity" action id' ) - return + return false } const activityType = live.activityType ?? 11 @@ -135,5 +135,7 @@ export class ActivateSearchPerk extends BaseActivity { `激活搜索加成出错 | offerId=${perk.offerId} | message=${error instanceof Error ? error.message : String(error)}` ) } + + return true } } diff --git a/src/functions/activities/app/AppPromotions.ts b/src/functions/activities/app/AppPromotions.ts index 43ff8f6..a58c31d 100644 --- a/src/functions/activities/app/AppPromotions.ts +++ b/src/functions/activities/app/AppPromotions.ts @@ -2,7 +2,7 @@ import { BaseActivity } from '../BaseActivity' import type { AppDashboardData } from '../../../interface/AppDashBoardData' export class AppPromotions extends BaseActivity { - public async run(data: AppDashboardData): Promise { + public async run(data: AppDashboardData): Promise { const pending = data.response.promotions.filter(promotion => { const attributes = promotion.attributes return ( @@ -18,7 +18,7 @@ export class AppPromotions extends BaseActivity { 'APP-PROMOTIONS', '所有"应用推广"项目已完成' ) - return + return false } this.bot.logger.info( @@ -33,5 +33,6 @@ export class AppPromotions extends BaseActivity { } } this.bot.logger.info(this.bot.isMobile, 'APP-PROMOTIONS', '"应用推广"项目处理完毕') + return true } } diff --git a/src/functions/activities/app/DailyCheckIn.ts b/src/functions/activities/app/DailyCheckIn.ts index 3157034..5177dc0 100644 --- a/src/functions/activities/app/DailyCheckIn.ts +++ b/src/functions/activities/app/DailyCheckIn.ts @@ -8,14 +8,14 @@ export class DailyCheckIn extends BaseActivity { private oldBalance: number = this.bot.userData.currentPoints - public async doDailyCheckIn() { + public async doDailyCheckIn(): Promise { if (!this.bot.accessToken) { this.bot.logger.warn( this.bot.isMobile, 'DAILY-CHECK-IN', '跳过:应用访问令牌不可用,此活动需要它!' ) - return + return false } this.oldBalance = Number(this.bot.userData.currentPoints ?? 0) @@ -68,6 +68,8 @@ export class DailyCheckIn extends BaseActivity { `每日签到出错 | message=${error instanceof Error ? error.message : String(error)}` ) } + + return true } private async submitDaily() { diff --git a/src/functions/activities/app/ReadToEarn.ts b/src/functions/activities/app/ReadToEarn.ts index 7762fe3..e42181c 100644 --- a/src/functions/activities/app/ReadToEarn.ts +++ b/src/functions/activities/app/ReadToEarn.ts @@ -6,14 +6,14 @@ import { randomBytes } from 'crypto' import { BaseActivity } from '../BaseActivity' export class ReadToEarn extends BaseActivity { - public async doReadToEarn() { + public async doReadToEarn(): Promise { if (!this.bot.accessToken) { this.bot.logger.warn( this.bot.isMobile, 'READ-TO-EARN', '跳过:应用访问令牌不可用,此活动需要它!' ) - return + return false } const delayMin = this.bot.config.searchSettings.readDelay.min @@ -129,5 +129,7 @@ export class ReadToEarn extends BaseActivity { `读文赚积分出错 | message=${error instanceof Error ? error.message : String(error)}` ) } + + return true } } diff --git a/src/functions/activities/rewards/DailySet.ts b/src/functions/activities/rewards/DailySet.ts index e55a435..2ca91f3 100644 --- a/src/functions/activities/rewards/DailySet.ts +++ b/src/functions/activities/rewards/DailySet.ts @@ -3,14 +3,14 @@ import type { DashboardData } from '../../../interface/DashboardData' import { PromotionActivityRunner } from './PromotionActivityRunner' export class DailySet extends BaseActivity { - public async run(data: DashboardData): Promise { + public async run(data: DashboardData): Promise { const today = this.bot.utils.getFormattedDate() const pending = data.dashboard.dailySetPromotions[today]?.filter(item => !item.complete && item.pointProgressMax > 0) ?? [] if (!pending.length) { this.bot.logger.info(this.bot.isMobile, 'DAILY-SET', '所有"每日任务"项目已完成') - return + return false } this.bot.logger.info( @@ -20,5 +20,6 @@ export class DailySet extends BaseActivity { ) await new PromotionActivityRunner(this.bot).run(pending) this.bot.logger.info(this.bot.isMobile, 'DAILY-SET', '"每日任务"项目处理完毕') + return true } } diff --git a/src/functions/activities/rewards/MorePromotions.ts b/src/functions/activities/rewards/MorePromotions.ts index 907d731..2ff7949 100644 --- a/src/functions/activities/rewards/MorePromotions.ts +++ b/src/functions/activities/rewards/MorePromotions.ts @@ -3,7 +3,7 @@ import type { BasePromotion, DashboardData } from '../../../interface/DashboardD import { PromotionActivityRunner } from './PromotionActivityRunner' export class MorePromotions extends BaseActivity { - public async run(data: DashboardData): Promise { + public async run(data: DashboardData): Promise { const promotions = [ ...new Map( [ @@ -22,7 +22,7 @@ export class MorePromotions extends BaseActivity { 'MORE-PROMOTIONS', '所有"更多推广"项目已完成' ) - return + return false } this.bot.logger.info( @@ -32,6 +32,7 @@ export class MorePromotions extends BaseActivity { ) await new PromotionActivityRunner(this.bot).run(pending) this.bot.logger.info(this.bot.isMobile, 'MORE-PROMOTIONS', '"更多推广"项目处理完毕') + return true } private isActionable(promotion: BasePromotion): boolean { diff --git a/src/functions/activities/rewards/PunchCards.ts b/src/functions/activities/rewards/PunchCards.ts index 92152db..acc1d4d 100644 --- a/src/functions/activities/rewards/PunchCards.ts +++ b/src/functions/activities/rewards/PunchCards.ts @@ -4,15 +4,16 @@ import type { ParentQuest, QuestChild } from '../../../browser/ReactFunc' import type { BasePromotion, DashboardData, PunchCard } from '../../../interface/DashboardData' export class PunchCards extends BaseActivity { - public async runMobile(data: DashboardData): Promise { + public async runMobile(data: DashboardData): Promise { try { - await this.run(data) + return await this.run(data) } catch (error) { this.bot.logger.error( 'main', 'PUNCHCARD', `移动端打卡任务失败 | ${error instanceof Error ? error.message : String(error)}` ) + return true } } @@ -42,9 +43,9 @@ export class PunchCards extends BaseActivity { } } - private async run(data: DashboardData): Promise { + private async run(data: DashboardData): Promise { const parents = await this.getParentQuests() - if (!parents) return + if (!parents) return false const apiById = new Map( (data.dashboard.punchCards ?? []) @@ -60,7 +61,7 @@ export class PunchCards extends BaseActivity { if (!pending.length) { this.bot.logger.info(this.bot.isMobile, 'PUNCHCARD', '没有可执行的任务') - return + return false } this.bot.logger.info( @@ -84,6 +85,7 @@ export class PunchCards extends BaseActivity { } this.bot.logger.info(this.bot.isMobile, 'PUNCHCARD', '任务处理完毕') + return true } private async getParentQuests(): Promise { diff --git a/src/index.ts b/src/index.ts index 494496e..a276e4a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -773,6 +773,7 @@ export class MicrosoftRewardsBot { // 桌面会话预热:登录完立即保存并关闭,把需要人工批准的桌面登录 // 挪到运行开头(紧跟移动端批准之后);后续桌面阶段从 SQLite 恢复会话,不再触发批准 + // 预热失败(如批准超时无人处理)时置位,后续桌面阶段整体跳过,移动端任务照常跑完 const prewarmDesktop = this.config.prewarmDesktopLogin && (this.config.workers.doPunchCards || @@ -941,18 +942,19 @@ export class MicrosoftRewardsBot { await this.activities.doEnsureStreakProtection() } if (this.config.workers.doPunchCards) { - await this.activities.doPunchCardsMobile(data) - await this.gapBetweenWorkers() + const didWork = await this.activities.doPunchCardsMobile(data) + if (didWork) await this.gapBetweenWorkers() } if (this.config.workers.doActivateSearchPerk) { - await this.activities.doActivateSearchPerk(data) - await this.gapBetweenWorkers() + const didWork = await this.activities.doActivateSearchPerk(data) + if (didWork) await this.gapBetweenWorkers() } const plan = await this.searchManager.getSearchPoints() const doMobileSearch = plan.doMobile const doDesktopSearch = plan.doDesktop - const desktopBrowserNeeded = this.config.workers.doPunchCards || doVisualSearch + const desktopBrowserNeeded = + (this.config.workers.doPunchCards || doVisualSearch) if (doDesktopSearch && !desktopBrowserNeeded) { this.cookies.desktop = [...this.cookies.mobile] @@ -969,24 +971,24 @@ export class MicrosoftRewardsBot { } if (this.config.workers.doDailySet) { - await this.activities.doDailySet(data) - await this.gapBetweenWorkers() + const didWork = await this.activities.doDailySet(data) + if (didWork) await this.gapBetweenWorkers() } if (this.config.workers.doMorePromotions) { - await this.activities.doMorePromotions(data) - await this.gapBetweenWorkers() + const didWork = await this.activities.doMorePromotions(data) + if (didWork) await this.gapBetweenWorkers() } if (appAvailable && this.config.workers.doDailyCheckIn) { - await this.activities.doDailyCheckIn() - await this.gapBetweenWorkers() + const didWork = await this.activities.doDailyCheckIn() + if (didWork) await this.gapBetweenWorkers() } if (appAvailable && this.config.workers.doAppPromotions && appData) { - await this.activities.doAppPromotions(appData) - await this.gapBetweenWorkers() + const didWork = await this.activities.doAppPromotions(appData) + if (didWork) await this.gapBetweenWorkers() } if (appAvailable && this.config.workers.doReadToEarn) { - await this.activities.doReadToEarn() - await this.gapBetweenWorkers() + const didWork = await this.activities.doReadToEarn() + if (didWork) await this.gapBetweenWorkers() } if (doMobileSearch) mobilePoints = await this.searchManager.searchMobile(account) @@ -997,32 +999,32 @@ export class MicrosoftRewardsBot { await this.activities.doEnsureStreakProtection() } if (this.config.workers.doDailySet) { - await this.activities.doDailySet(data) - await this.gapBetweenWorkers() + const didWork = await this.activities.doDailySet(data) + if (didWork) await this.gapBetweenWorkers() } if (this.config.workers.doActivateSearchPerk) { - await this.activities.doActivateSearchPerk(data) - await this.gapBetweenWorkers() + const didWork = await this.activities.doActivateSearchPerk(data) + if (didWork) await this.gapBetweenWorkers() } if (this.config.workers.doMorePromotions) { - await this.activities.doMorePromotions(data) - await this.gapBetweenWorkers() + const didWork = await this.activities.doMorePromotions(data) + if (didWork) await this.gapBetweenWorkers() } if (appAvailable && this.config.workers.doDailyCheckIn) { - await this.activities.doDailyCheckIn() - await this.gapBetweenWorkers() + const didWork = await this.activities.doDailyCheckIn() + if (didWork) await this.gapBetweenWorkers() } if (appAvailable && this.config.workers.doAppPromotions && appData) { - await this.activities.doAppPromotions(appData) - await this.gapBetweenWorkers() + const didWork = await this.activities.doAppPromotions(appData) + if (didWork) await this.gapBetweenWorkers() } if (appAvailable && this.config.workers.doReadToEarn) { - await this.activities.doReadToEarn() - await this.gapBetweenWorkers() + const didWork = await this.activities.doReadToEarn() + if (didWork) await this.gapBetweenWorkers() } if (this.config.workers.doPunchCards) { - await this.activities.doPunchCardsMobile(data) - await this.gapBetweenWorkers() + const didWork = await this.activities.doPunchCardsMobile(data) + if (didWork) await this.gapBetweenWorkers() } const plan = await this.searchManager.getSearchPoints() @@ -1030,7 +1032,7 @@ export class MicrosoftRewardsBot { const doDesktopSearch = plan.doDesktop const desktopBrowserNeeded = - this.config.workers.doPunchCards || doVisualSearch || (doDesktopSearch && !apiSearch) + (this.config.workers.doPunchCards || doVisualSearch || (doDesktopSearch && !apiSearch)) if (apiSearch && doDesktopSearch && !desktopBrowserNeeded) { this.cookies.desktop = [...this.cookies.mobile]