mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-10 17:26:17 +00:00
Refactor: Remove legacy code and improve import statements across multiple files
This commit is contained in:
@@ -7,14 +7,6 @@ import { loadSessionData, saveFingerprintData } from '../util/Load'
|
||||
import { updateFingerprintUserAgent } from '../util/UserAgent'
|
||||
import { AccountProxy } from '../interface/Account'
|
||||
|
||||
/* Test Stuff
|
||||
https://abrahamjuliot.github.io/creepjs/
|
||||
https://botcheck.luminati.io/
|
||||
https://fv.pro/
|
||||
https://pixelscan.net/
|
||||
https://www.browserscan.net/
|
||||
*/
|
||||
|
||||
class Browser {
|
||||
private bot: MicrosoftRewardsBot
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ type ActivityKind =
|
||||
| { type: 'unsupported' }
|
||||
|
||||
|
||||
export default class Activities {
|
||||
export class Activities {
|
||||
private bot: MicrosoftRewardsBot
|
||||
private handlers: ActivityHandler[] = []
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { DashboardData, MorePromotion, PromotionalItem, PunchCard } from '../int
|
||||
|
||||
import { MicrosoftRewardsBot } from '../index'
|
||||
import JobState from '../util/JobState'
|
||||
import Retry from '../util/Retry'
|
||||
import { Retry } from '../util/Retry'
|
||||
import { AdaptiveThrottler } from '../util/AdaptiveThrottler'
|
||||
|
||||
export class Workers {
|
||||
|
||||
15
src/index.ts
15
src/index.ts
@@ -10,7 +10,7 @@ import BrowserFunc from './browser/BrowserFunc'
|
||||
import BrowserUtil from './browser/BrowserUtil'
|
||||
|
||||
import { log } from './util/Logger'
|
||||
import Util from './util/Utils'
|
||||
import { Util } from './util/Utils'
|
||||
import { loadAccounts, loadConfig, saveSessionData } from './util/Load'
|
||||
import Axios from './util/Axios'
|
||||
import Humanizer from './util/Humanizer'
|
||||
@@ -24,7 +24,7 @@ import { MobileRetryTracker } from './util/MobileRetryTracker'
|
||||
|
||||
import { Login } from './functions/Login'
|
||||
import { Workers } from './functions/Workers'
|
||||
import Activities from './functions/Activities'
|
||||
import { Activities } from './functions/Activities'
|
||||
|
||||
import { Account } from './interface/Account'
|
||||
import { DISCORD } from './constants'
|
||||
@@ -48,7 +48,6 @@ export class MicrosoftRewardsBot {
|
||||
public queryEngine?: QueryDiversityEngine
|
||||
public compromisedModeActive: boolean = false
|
||||
public compromisedReason?: string
|
||||
public compromisedEmail?: string
|
||||
// Mutex-like flag to prevent parallel execution when config.parallel is accidentally misconfigured
|
||||
private isDesktopRunning: boolean = false
|
||||
private isMobileRunning: boolean = false
|
||||
@@ -58,7 +57,6 @@ export class MicrosoftRewardsBot {
|
||||
private accounts: Account[]
|
||||
private workers: Workers
|
||||
private login = new Login(this)
|
||||
private accessToken: string = ''
|
||||
// Buy mode (manual spending) tracking
|
||||
private buyMode: { enabled: boolean; email?: string } = { enabled: false }
|
||||
|
||||
@@ -547,7 +545,6 @@ export class MicrosoftRewardsBot {
|
||||
// Reset compromised state per account
|
||||
this.compromisedModeActive = false
|
||||
this.compromisedReason = undefined
|
||||
this.compromisedEmail = undefined
|
||||
this.resetRiskTracking()
|
||||
|
||||
// If humanization allowed windows are configured, wait until within a window
|
||||
@@ -1004,14 +1001,14 @@ export class MicrosoftRewardsBot {
|
||||
}
|
||||
return { initialPoints: 0, collectedPoints: 0 }
|
||||
}
|
||||
this.accessToken = await this.login.getMobileAccessToken(this.homePage, account.email, account.totp)
|
||||
const accessToken = await this.login.getMobileAccessToken(this.homePage, account.email, account.totp)
|
||||
await this.browser.func.goHome(this.homePage)
|
||||
|
||||
const data = await this.browser.func.getDashboardData()
|
||||
const initialPoints = data.userStatus.availablePoints || 0
|
||||
|
||||
const browserEnarablePoints = await this.browser.func.getBrowserEarnablePoints()
|
||||
const appEarnablePoints = await this.browser.func.getAppEarnablePoints(this.accessToken)
|
||||
const appEarnablePoints = await this.browser.func.getAppEarnablePoints(accessToken)
|
||||
|
||||
const pointsCanCollect = browserEnarablePoints.mobileSearchPoints + appEarnablePoints.totalEarnablePoints
|
||||
|
||||
@@ -1035,12 +1032,12 @@ export class MicrosoftRewardsBot {
|
||||
}
|
||||
// Do daily check in
|
||||
if (this.config.workers.doDailyCheckIn) {
|
||||
await this.activities.doDailyCheckIn(this.accessToken, data)
|
||||
await this.activities.doDailyCheckIn(accessToken, data)
|
||||
}
|
||||
|
||||
// Do read to earn
|
||||
if (this.config.workers.doReadToEarn) {
|
||||
await this.activities.doReadToEarn(this.accessToken, data)
|
||||
await this.activities.doReadToEarn(accessToken, data)
|
||||
}
|
||||
|
||||
// Do mobile searches
|
||||
|
||||
@@ -30,7 +30,6 @@ export interface Config {
|
||||
riskManagement?: ConfigRiskManagement; // NEW: Risk-aware throttling and ban prediction
|
||||
dryRun?: boolean; // NEW: Dry-run mode (simulate without executing)
|
||||
queryDiversity?: ConfigQueryDiversity; // NEW: Multi-source query generation
|
||||
legacy?: ConfigLegacyFlags; // Track legacy config usage for warnings
|
||||
}
|
||||
|
||||
export interface ConfigSaveFingerprint {
|
||||
@@ -186,10 +185,4 @@ export interface ConfigQueryDiversity {
|
||||
sources?: Array<'google-trends' | 'reddit' | 'news' | 'wikipedia' | 'local-fallback'>; // which sources to use
|
||||
maxQueriesPerSource?: number; // limit per source
|
||||
cacheMinutes?: number; // cache duration
|
||||
}
|
||||
|
||||
export interface ConfigLegacyFlags {
|
||||
diagnosticsConfigured?: boolean;
|
||||
analyticsConfigured?: boolean;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
// Placeholder kept for backward compatibility with older imports.
|
||||
// New code should implement its own reporting or use webhooks.
|
||||
export {}
|
||||
@@ -207,24 +207,6 @@ export class ConfigValidator {
|
||||
})
|
||||
}
|
||||
|
||||
if (config.legacy?.diagnosticsConfigured) {
|
||||
issues.push({
|
||||
severity: 'warning',
|
||||
field: 'diagnostics',
|
||||
message: 'Unrecognized diagnostics.* block in config.jsonc.',
|
||||
suggestion: 'Delete the diagnostics section; logs and webhooks now cover troubleshooting.'
|
||||
})
|
||||
}
|
||||
|
||||
if (config.legacy?.analyticsConfigured) {
|
||||
issues.push({
|
||||
severity: 'warning',
|
||||
field: 'analytics',
|
||||
message: 'Unrecognized analytics.* block in config.jsonc.',
|
||||
suggestion: 'Delete the analytics section because those values are ignored.'
|
||||
})
|
||||
}
|
||||
|
||||
// Check workers
|
||||
if (config.workers) {
|
||||
const allDisabled = !config.workers.doDailySet &&
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// Placeholder kept for backward compatibility with older imports.
|
||||
// New code should handle troubleshooting through logging and webhooks instead.
|
||||
export {}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Page } from 'rebrowser-playwright'
|
||||
import Util from './Utils'
|
||||
import { Util } from './Utils'
|
||||
import type { ConfigHumanization } from '../interface/Config'
|
||||
|
||||
export class Humanizer {
|
||||
|
||||
@@ -3,9 +3,8 @@ import { BrowserFingerprintWithHeaders } from 'fingerprint-generator'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
|
||||
import { Account } from '../interface/Account'
|
||||
import { Config, ConfigLegacyFlags, ConfigSaveFingerprint } from '../interface/Config'
|
||||
import { Config, ConfigSaveFingerprint } from '../interface/Config'
|
||||
|
||||
let configCache: Config
|
||||
let configSourcePath = ''
|
||||
@@ -188,15 +187,6 @@ function normalizeConfig(raw: unknown): Config {
|
||||
skipCompletedAccounts: jobStateRaw.skipCompletedAccounts !== false
|
||||
}
|
||||
|
||||
const legacy: ConfigLegacyFlags = {}
|
||||
if (typeof n.diagnostics !== 'undefined') {
|
||||
legacy.diagnosticsConfigured = true
|
||||
}
|
||||
if (typeof n.analytics !== 'undefined') {
|
||||
legacy.analyticsConfigured = true
|
||||
}
|
||||
const hasLegacyFlags = legacy.diagnosticsConfigured === true || legacy.analyticsConfigured === true
|
||||
|
||||
const cfg: Config = {
|
||||
baseURL: n.baseURL ?? 'https://rewards.bing.com',
|
||||
sessionPath: n.sessionPath ?? 'sessions',
|
||||
@@ -226,8 +216,7 @@ function normalizeConfig(raw: unknown): Config {
|
||||
crashRecovery: n.crashRecovery || {},
|
||||
riskManagement,
|
||||
dryRun,
|
||||
queryDiversity,
|
||||
legacy: hasLegacyFlags ? legacy : undefined
|
||||
queryDiversity
|
||||
}
|
||||
|
||||
return cfg
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import axios from 'axios'
|
||||
import { Util } from './Utils'
|
||||
|
||||
export interface QuerySource {
|
||||
name: string
|
||||
@@ -21,6 +22,7 @@ export interface QueryDiversityConfig {
|
||||
export class QueryDiversityEngine {
|
||||
private config: QueryDiversityConfig
|
||||
private cache: Map<string, { queries: string[]; expires: number }> = new Map()
|
||||
private util: Util = new Util()
|
||||
|
||||
constructor(config?: Partial<QueryDiversityConfig>) {
|
||||
this.config = {
|
||||
@@ -56,7 +58,7 @@ export class QueryDiversityEngine {
|
||||
}
|
||||
|
||||
// Shuffle and limit to requested count
|
||||
final = this.shuffleArray(final).slice(0, count)
|
||||
final = this.util.shuffleArray(final).slice(0, count)
|
||||
|
||||
return final.length > 0 ? final : this.getLocalFallback(count)
|
||||
}
|
||||
@@ -275,7 +277,7 @@ export class QueryDiversityEngine {
|
||||
'education resources'
|
||||
]
|
||||
|
||||
return this.shuffleArray(fallback).slice(0, count)
|
||||
return this.util.shuffleArray(fallback).slice(0, count)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,18 +321,6 @@ export class QueryDiversityEngine {
|
||||
return 'trends'
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffle array (Fisher-Yates)
|
||||
*/
|
||||
private shuffleArray<T>(array: T[]): T[] {
|
||||
const shuffled = [...array]
|
||||
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[shuffled[i], shuffled[j]] = [shuffled[j]!, shuffled[i]!]
|
||||
}
|
||||
return shuffled
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache (call between runs)
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ConfigRetryPolicy } from '../interface/Config'
|
||||
import Util from './Utils'
|
||||
import { Util } from './Utils'
|
||||
|
||||
type NumericPolicy = {
|
||||
maxAttempts: number
|
||||
@@ -60,5 +60,3 @@ export class Retry {
|
||||
throw lastErr instanceof Error ? lastErr : new Error(String(lastErr))
|
||||
}
|
||||
}
|
||||
|
||||
export default Retry
|
||||
|
||||
@@ -338,15 +338,6 @@ export class StartupValidator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.legacy?.diagnosticsConfigured || config.legacy?.analyticsConfigured) {
|
||||
this.addWarning(
|
||||
'filesystem',
|
||||
'Unrecognized diagnostics/analytics block detected in config.jsonc',
|
||||
'Remove those sections to keep the file aligned with the current schema.',
|
||||
'docs/diagnostics.md'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private validateBrowserSettings(config: Config): void {
|
||||
|
||||
@@ -2,7 +2,7 @@ import axios from 'axios'
|
||||
import { BrowserFingerprintWithHeaders } from 'fingerprint-generator'
|
||||
|
||||
import { log } from './Logger'
|
||||
import Retry from './Retry'
|
||||
import { Retry } from './Retry'
|
||||
|
||||
import { ChromeVersion, EdgeVersion, Architecture, Platform } from '../interface/UserAgentUtil'
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ms from 'ms'
|
||||
|
||||
export default class Util {
|
||||
export class Util {
|
||||
|
||||
async wait(ms: number): Promise<void> {
|
||||
// Safety check: prevent extremely long or negative waits
|
||||
|
||||
Reference in New Issue
Block a user