mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-18 20:53:57 +00:00
Refactor: Enhance error handling and logging in Browser and MicrosoftRewardsBot classes; remove unused luxon declarations
This commit is contained in:
@@ -19,13 +19,19 @@ export class Humanizer {
|
||||
if (Math.random() < moveProb) {
|
||||
const x = Math.floor(Math.random() * 40) + 5
|
||||
const y = Math.floor(Math.random() * 30) + 5
|
||||
await page.mouse.move(x, y, { steps: 2 }).catch(() => {})
|
||||
await page.mouse.move(x, y, { steps: 2 }).catch(() => {
|
||||
// Mouse move failed - page may be closed or unavailable
|
||||
})
|
||||
}
|
||||
if (Math.random() < scrollProb) {
|
||||
const dy = (Math.random() < 0.5 ? 1 : -1) * (Math.floor(Math.random() * 150) + 50)
|
||||
await page.mouse.wheel(0, dy).catch(() => {})
|
||||
await page.mouse.wheel(0, dy).catch(() => {
|
||||
// Mouse wheel failed - page may be closed or unavailable
|
||||
})
|
||||
}
|
||||
} catch {/* noop */}
|
||||
} catch {
|
||||
// Gesture execution failed - not critical for operation
|
||||
}
|
||||
}
|
||||
|
||||
async actionPause(): Promise<void> {
|
||||
@@ -40,7 +46,10 @@ export class Humanizer {
|
||||
try {
|
||||
const n = this.util.stringToMs(String(v))
|
||||
return Math.max(0, Math.min(n, 10_000))
|
||||
} catch { return defMin }
|
||||
} catch (e) {
|
||||
// Parse failed - use default minimum
|
||||
return defMin
|
||||
}
|
||||
}
|
||||
min = parse(this.cfg.actionDelay.min)
|
||||
max = parse(this.cfg.actionDelay.max)
|
||||
|
||||
@@ -260,7 +260,15 @@ export function loadAccounts(): Account[] {
|
||||
]
|
||||
let chosen: string | null = null
|
||||
for (const p of candidates) {
|
||||
try { if (fs.existsSync(p)) { chosen = p; break } } catch { /* ignore */ }
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
chosen = p
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
// Filesystem check failed for this path, try next
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (!chosen) throw new Error(`accounts file not found in: ${candidates.join(' | ')}`)
|
||||
raw = fs.readFileSync(chosen, 'utf-8')
|
||||
@@ -349,7 +357,15 @@ export function loadConfig(): Config {
|
||||
|
||||
let cfgPath: string | null = null
|
||||
for (const p of candidates) {
|
||||
try { if (fs.existsSync(p)) { cfgPath = p; break } } catch { /* ignore */ }
|
||||
try {
|
||||
if (fs.existsSync(p)) {
|
||||
cfgPath = p
|
||||
break
|
||||
}
|
||||
} catch (e) {
|
||||
// Filesystem check failed for this path, try next
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (!cfgPath) throw new Error(`config.json not found in: ${candidates.join(' | ')}`)
|
||||
const config = fs.readFileSync(cfgPath, 'utf-8')
|
||||
@@ -377,6 +393,8 @@ export async function loadSessionData(sessionPath: string, email: string, isMobi
|
||||
}
|
||||
|
||||
// Fetch fingerprint file (support both legacy typo "fingerpint" and corrected "fingerprint")
|
||||
// NOTE: "fingerpint" is a historical typo that must be maintained for backwards compatibility
|
||||
// with existing session files. We check for the corrected name first, then fall back to the typo.
|
||||
const baseDir = path.join(__dirname, '../browser/', sessionPath, email)
|
||||
const legacyFile = path.join(baseDir, `${isMobile ? 'mobile_fingerpint' : 'desktop_fingerpint'}.json`)
|
||||
const correctFile = path.join(baseDir, `${isMobile ? 'mobile_fingerprint' : 'desktop_fingerprint'}.json`)
|
||||
@@ -436,11 +454,18 @@ export async function saveFingerprintData(sessionPath: string, email: string, is
|
||||
}
|
||||
|
||||
// Save fingerprint to files (write both legacy and corrected names for compatibility)
|
||||
// NOTE: Writing to both "fingerpint" (typo) and "fingerprint" (correct) ensures backwards
|
||||
// compatibility with older bot versions that expect the typo filename.
|
||||
const legacy = path.join(sessionDir, `${isMobile ? 'mobile_fingerpint' : 'desktop_fingerpint'}.json`)
|
||||
const correct = path.join(sessionDir, `${isMobile ? 'mobile_fingerprint' : 'desktop_fingerprint'}.json`)
|
||||
const payload = JSON.stringify(fingerprint)
|
||||
await fs.promises.writeFile(correct, payload)
|
||||
try { await fs.promises.writeFile(legacy, payload) } catch { /* ignore */ }
|
||||
try {
|
||||
await fs.promises.writeFile(legacy, payload)
|
||||
} catch (e) {
|
||||
// Legacy file write failed - not critical since correct file was written
|
||||
// Silently continue to maintain compatibility
|
||||
}
|
||||
|
||||
return sessionDir
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user