Refactor: Simplify bot login handling in DesktopFlow and MobileFlow; initialize Login instance in MicrosoftRewardsBot

This commit is contained in:
2025-11-09 00:18:10 +01:00
parent 3bdb94adb5
commit 22adf44f63
3 changed files with 9 additions and 13 deletions

View File

@@ -10,7 +10,6 @@
* - Desktop searches * - Desktop searches
*/ */
import type { Page } from 'playwright'
import type { MicrosoftRewardsBot } from '../index' import type { MicrosoftRewardsBot } from '../index'
import type { Account } from '../interface/Account' import type { Account } from '../interface/Account'
import { saveSessionData } from '../util/Load' import { saveSessionData } from '../util/Load'
@@ -49,8 +48,7 @@ export class DesktopFlow {
this.bot.log(false, 'DESKTOP-FLOW', 'Browser started successfully') this.bot.log(false, 'DESKTOP-FLOW', 'Browser started successfully')
// Login into MS Rewards, then optionally stop if compromised // Login into MS Rewards, then optionally stop if compromised
const login = (this.bot as unknown as { login: { login: (page: Page, email: string, password: string, totp?: string) => Promise<void> } }).login await this.bot.login.login(this.bot.homePage, account.email, account.password, account.totp)
await login.login(this.bot.homePage, account.email, account.password, account.totp)
if (this.bot.compromisedModeActive) { if (this.bot.compromisedModeActive) {
// User wants the page to remain open for manual recovery. Do not proceed to tasks. // User wants the page to remain open for manual recovery. Do not proceed to tasks.
@@ -116,20 +114,17 @@ export class DesktopFlow {
// Complete daily set // Complete daily set
if (this.bot.config.workers.doDailySet) { if (this.bot.config.workers.doDailySet) {
const workers = (this.bot as unknown as { workers: { doDailySet: (page: Page, data: unknown) => Promise<void> } }).workers await this.bot.workers.doDailySet(workerPage, data)
await workers.doDailySet(workerPage, data)
} }
// Complete more promotions // Complete more promotions
if (this.bot.config.workers.doMorePromotions) { if (this.bot.config.workers.doMorePromotions) {
const workers = (this.bot as unknown as { workers: { doMorePromotions: (page: Page, data: unknown) => Promise<void> } }).workers await this.bot.workers.doMorePromotions(workerPage, data)
await workers.doMorePromotions(workerPage, data)
} }
// Complete punch cards // Complete punch cards
if (this.bot.config.workers.doPunchCards) { if (this.bot.config.workers.doPunchCards) {
const workers = (this.bot as unknown as { workers: { doPunchCard: (page: Page, data: unknown) => Promise<void> } }).workers await this.bot.workers.doPunchCard(workerPage, data)
await workers.doPunchCard(workerPage, data)
} }
// Do desktop searches // Do desktop searches

View File

@@ -11,7 +11,6 @@
* - Mobile retry logic * - Mobile retry logic
*/ */
import type { Page } from 'playwright'
import type { MicrosoftRewardsBot } from '../index' import type { MicrosoftRewardsBot } from '../index'
import type { Account } from '../interface/Account' import type { Account } from '../interface/Account'
import { saveSessionData } from '../util/Load' import { saveSessionData } from '../util/Load'
@@ -56,8 +55,7 @@ export class MobileFlow {
this.bot.log(true, 'MOBILE-FLOW', 'Browser started successfully') this.bot.log(true, 'MOBILE-FLOW', 'Browser started successfully')
// Login into MS Rewards, then respect compromised mode // Login into MS Rewards, then respect compromised mode
const login = (this.bot as unknown as { login: { login: (page: Page, email: string, password: string, totp?: string) => Promise<void>; getMobileAccessToken: (page: Page, email: string, totp?: string) => Promise<string> } }).login await this.bot.login.login(this.bot.homePage, account.email, account.password, account.totp)
await login.login(this.bot.homePage, account.email, account.password, account.totp)
if (this.bot.compromisedModeActive) { if (this.bot.compromisedModeActive) {
keepBrowserOpen = true keepBrowserOpen = true
@@ -84,7 +82,7 @@ export class MobileFlow {
return { initialPoints: 0, collectedPoints: 0 } return { initialPoints: 0, collectedPoints: 0 }
} }
const accessToken = await login.getMobileAccessToken(this.bot.homePage, account.email, account.totp) const accessToken = await this.bot.login.getMobileAccessToken(this.bot.homePage, account.email, account.totp)
await this.bot.browser.func.goHome(this.bot.homePage) await this.bot.browser.func.goHome(this.bot.homePage)
const data = await this.bot.browser.func.getDashboardData() const data = await this.bot.browser.func.getDashboardData()

View File

@@ -31,6 +31,7 @@ import { StartupValidator } from './util/StartupValidator'
import { Util } from './util/Utils' import { Util } from './util/Utils'
import { Activities } from './functions/Activities' import { Activities } from './functions/Activities'
import { Login } from './functions/Login'
import { Workers } from './functions/Workers' import { Workers } from './functions/Workers'
import { DesktopFlow } from './flows/DesktopFlow' import { DesktopFlow } from './flows/DesktopFlow'
@@ -47,6 +48,7 @@ export class MicrosoftRewardsBot {
public config public config
public utils: Util public utils: Util
public activities: Activities = new Activities(this) public activities: Activities = new Activities(this)
public login!: Login // Fixed: Login instance needed by flows
public browser: { public browser: {
func: BrowserFunc, func: BrowserFunc,
utils: BrowserUtil utils: BrowserUtil
@@ -88,6 +90,7 @@ export class MicrosoftRewardsBot {
func: new BrowserFunc(this), func: new BrowserFunc(this),
utils: new BrowserUtil(this) utils: new BrowserUtil(this)
} }
this.login = new Login(this) // Fixed: Initialize Login instance
this.workers = new Workers(this) this.workers = new Workers(this)
this.humanizer = new Humanizer(this.utils, this.config.humanization) this.humanizer = new Humanizer(this.utils, this.config.humanization)
this.activeWorkers = this.config.clusters this.activeWorkers = this.config.clusters