mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-10 01:06:17 +00:00
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import { Page } from 'rebrowser-playwright'
|
|
|
|
import { TIMEOUTS } from '../../constants'
|
|
import { waitForElementSmart } from '../../util/browser/SmartWait'
|
|
import { Workers } from '../Workers'
|
|
|
|
|
|
export class Poll extends Workers {
|
|
|
|
async doPoll(page: Page) {
|
|
this.bot.log(this.bot.isMobile, 'POLL', 'Trying to complete poll')
|
|
|
|
try {
|
|
const buttonId = `#btoption${Math.floor(this.bot.utils.randomNumber(0, 1))}`
|
|
|
|
// IMPROVED: Smart wait replaces fixed 10s timeout with adaptive 2s+5s detection
|
|
const buttonResult = await waitForElementSmart(page, buttonId, {
|
|
initialTimeoutMs: 2000,
|
|
extendedTimeoutMs: TIMEOUTS.DASHBOARD_WAIT - 2000,
|
|
state: 'visible',
|
|
logFn: (msg) => this.bot.log(this.bot.isMobile, 'POLL', msg)
|
|
})
|
|
|
|
if (!buttonResult.found) {
|
|
this.bot.log(this.bot.isMobile, 'POLL', `Could not find poll button: ${buttonId}`, 'warn')
|
|
await page.close()
|
|
return
|
|
}
|
|
|
|
await this.bot.utils.wait(TIMEOUTS.MEDIUM_LONG)
|
|
await page.click(buttonId)
|
|
|
|
await this.bot.utils.wait(TIMEOUTS.LONG + 1000)
|
|
await page.close()
|
|
|
|
this.bot.log(this.bot.isMobile, 'POLL', 'Completed the poll successfully')
|
|
} catch (error) {
|
|
await page.close()
|
|
this.bot.log(this.bot.isMobile, 'POLL', 'An error occurred:' + error, 'error')
|
|
}
|
|
}
|
|
|
|
} |