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 { updateFingerprintUserAgent } from '../util/UserAgent'
|
||||||
import { AccountProxy } from '../interface/Account'
|
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 {
|
class Browser {
|
||||||
private bot: MicrosoftRewardsBot
|
private bot: MicrosoftRewardsBot
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type ActivityKind =
|
|||||||
| { type: 'unsupported' }
|
| { type: 'unsupported' }
|
||||||
|
|
||||||
|
|
||||||
export default class Activities {
|
export class Activities {
|
||||||
private bot: MicrosoftRewardsBot
|
private bot: MicrosoftRewardsBot
|
||||||
private handlers: ActivityHandler[] = []
|
private handlers: ActivityHandler[] = []
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { DashboardData, MorePromotion, PromotionalItem, PunchCard } from '../int
|
|||||||
|
|
||||||
import { MicrosoftRewardsBot } from '../index'
|
import { MicrosoftRewardsBot } from '../index'
|
||||||
import JobState from '../util/JobState'
|
import JobState from '../util/JobState'
|
||||||
import Retry from '../util/Retry'
|
import { Retry } from '../util/Retry'
|
||||||
import { AdaptiveThrottler } from '../util/AdaptiveThrottler'
|
import { AdaptiveThrottler } from '../util/AdaptiveThrottler'
|
||||||
|
|
||||||
export class Workers {
|
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 BrowserUtil from './browser/BrowserUtil'
|
||||||
|
|
||||||
import { log } from './util/Logger'
|
import { log } from './util/Logger'
|
||||||
import Util from './util/Utils'
|
import { Util } from './util/Utils'
|
||||||
import { loadAccounts, loadConfig, saveSessionData } from './util/Load'
|
import { loadAccounts, loadConfig, saveSessionData } from './util/Load'
|
||||||
import Axios from './util/Axios'
|
import Axios from './util/Axios'
|
||||||
import Humanizer from './util/Humanizer'
|
import Humanizer from './util/Humanizer'
|
||||||
@@ -24,7 +24,7 @@ import { MobileRetryTracker } from './util/MobileRetryTracker'
|
|||||||
|
|
||||||
import { Login } from './functions/Login'
|
import { Login } from './functions/Login'
|
||||||
import { Workers } from './functions/Workers'
|
import { Workers } from './functions/Workers'
|
||||||
import Activities from './functions/Activities'
|
import { Activities } from './functions/Activities'
|
||||||
|
|
||||||
import { Account } from './interface/Account'
|
import { Account } from './interface/Account'
|
||||||
import { DISCORD } from './constants'
|
import { DISCORD } from './constants'
|
||||||
@@ -48,7 +48,6 @@ export class MicrosoftRewardsBot {
|
|||||||
public queryEngine?: QueryDiversityEngine
|
public queryEngine?: QueryDiversityEngine
|
||||||
public compromisedModeActive: boolean = false
|
public compromisedModeActive: boolean = false
|
||||||
public compromisedReason?: string
|
public compromisedReason?: string
|
||||||
public compromisedEmail?: string
|
|
||||||
// Mutex-like flag to prevent parallel execution when config.parallel is accidentally misconfigured
|
// Mutex-like flag to prevent parallel execution when config.parallel is accidentally misconfigured
|
||||||
private isDesktopRunning: boolean = false
|
private isDesktopRunning: boolean = false
|
||||||
private isMobileRunning: boolean = false
|
private isMobileRunning: boolean = false
|
||||||
@@ -58,7 +57,6 @@ export class MicrosoftRewardsBot {
|
|||||||
private accounts: Account[]
|
private accounts: Account[]
|
||||||
private workers: Workers
|
private workers: Workers
|
||||||
private login = new Login(this)
|
private login = new Login(this)
|
||||||
private accessToken: string = ''
|
|
||||||
// Buy mode (manual spending) tracking
|
// Buy mode (manual spending) tracking
|
||||||
private buyMode: { enabled: boolean; email?: string } = { enabled: false }
|
private buyMode: { enabled: boolean; email?: string } = { enabled: false }
|
||||||
|
|
||||||
@@ -547,7 +545,6 @@ export class MicrosoftRewardsBot {
|
|||||||
// Reset compromised state per account
|
// Reset compromised state per account
|
||||||
this.compromisedModeActive = false
|
this.compromisedModeActive = false
|
||||||
this.compromisedReason = undefined
|
this.compromisedReason = undefined
|
||||||
this.compromisedEmail = undefined
|
|
||||||
this.resetRiskTracking()
|
this.resetRiskTracking()
|
||||||
|
|
||||||
// If humanization allowed windows are configured, wait until within a window
|
// If humanization allowed windows are configured, wait until within a window
|
||||||
@@ -1004,14 +1001,14 @@ export class MicrosoftRewardsBot {
|
|||||||
}
|
}
|
||||||
return { initialPoints: 0, collectedPoints: 0 }
|
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)
|
await this.browser.func.goHome(this.homePage)
|
||||||
|
|
||||||
const data = await this.browser.func.getDashboardData()
|
const data = await this.browser.func.getDashboardData()
|
||||||
const initialPoints = data.userStatus.availablePoints || 0
|
const initialPoints = data.userStatus.availablePoints || 0
|
||||||
|
|
||||||
const browserEnarablePoints = await this.browser.func.getBrowserEarnablePoints()
|
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
|
const pointsCanCollect = browserEnarablePoints.mobileSearchPoints + appEarnablePoints.totalEarnablePoints
|
||||||
|
|
||||||
@@ -1035,12 +1032,12 @@ export class MicrosoftRewardsBot {
|
|||||||
}
|
}
|
||||||
// Do daily check in
|
// Do daily check in
|
||||||
if (this.config.workers.doDailyCheckIn) {
|
if (this.config.workers.doDailyCheckIn) {
|
||||||
await this.activities.doDailyCheckIn(this.accessToken, data)
|
await this.activities.doDailyCheckIn(accessToken, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do read to earn
|
// Do read to earn
|
||||||
if (this.config.workers.doReadToEarn) {
|
if (this.config.workers.doReadToEarn) {
|
||||||
await this.activities.doReadToEarn(this.accessToken, data)
|
await this.activities.doReadToEarn(accessToken, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do mobile searches
|
// Do mobile searches
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ export interface Config {
|
|||||||
riskManagement?: ConfigRiskManagement; // NEW: Risk-aware throttling and ban prediction
|
riskManagement?: ConfigRiskManagement; // NEW: Risk-aware throttling and ban prediction
|
||||||
dryRun?: boolean; // NEW: Dry-run mode (simulate without executing)
|
dryRun?: boolean; // NEW: Dry-run mode (simulate without executing)
|
||||||
queryDiversity?: ConfigQueryDiversity; // NEW: Multi-source query generation
|
queryDiversity?: ConfigQueryDiversity; // NEW: Multi-source query generation
|
||||||
legacy?: ConfigLegacyFlags; // Track legacy config usage for warnings
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConfigSaveFingerprint {
|
export interface ConfigSaveFingerprint {
|
||||||
@@ -186,10 +185,4 @@ export interface ConfigQueryDiversity {
|
|||||||
sources?: Array<'google-trends' | 'reddit' | 'news' | 'wikipedia' | 'local-fallback'>; // which sources to use
|
sources?: Array<'google-trends' | 'reddit' | 'news' | 'wikipedia' | 'local-fallback'>; // which sources to use
|
||||||
maxQueriesPerSource?: number; // limit per source
|
maxQueriesPerSource?: number; // limit per source
|
||||||
cacheMinutes?: number; // cache duration
|
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
|
// Check workers
|
||||||
if (config.workers) {
|
if (config.workers) {
|
||||||
const allDisabled = !config.workers.doDailySet &&
|
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 { Page } from 'rebrowser-playwright'
|
||||||
import Util from './Utils'
|
import { Util } from './Utils'
|
||||||
import type { ConfigHumanization } from '../interface/Config'
|
import type { ConfigHumanization } from '../interface/Config'
|
||||||
|
|
||||||
export class Humanizer {
|
export class Humanizer {
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ import { BrowserFingerprintWithHeaders } from 'fingerprint-generator'
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
|
|
||||||
import { Account } from '../interface/Account'
|
import { Account } from '../interface/Account'
|
||||||
import { Config, ConfigLegacyFlags, ConfigSaveFingerprint } from '../interface/Config'
|
import { Config, ConfigSaveFingerprint } from '../interface/Config'
|
||||||
|
|
||||||
let configCache: Config
|
let configCache: Config
|
||||||
let configSourcePath = ''
|
let configSourcePath = ''
|
||||||
@@ -188,15 +187,6 @@ function normalizeConfig(raw: unknown): Config {
|
|||||||
skipCompletedAccounts: jobStateRaw.skipCompletedAccounts !== false
|
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 = {
|
const cfg: Config = {
|
||||||
baseURL: n.baseURL ?? 'https://rewards.bing.com',
|
baseURL: n.baseURL ?? 'https://rewards.bing.com',
|
||||||
sessionPath: n.sessionPath ?? 'sessions',
|
sessionPath: n.sessionPath ?? 'sessions',
|
||||||
@@ -226,8 +216,7 @@ function normalizeConfig(raw: unknown): Config {
|
|||||||
crashRecovery: n.crashRecovery || {},
|
crashRecovery: n.crashRecovery || {},
|
||||||
riskManagement,
|
riskManagement,
|
||||||
dryRun,
|
dryRun,
|
||||||
queryDiversity,
|
queryDiversity
|
||||||
legacy: hasLegacyFlags ? legacy : undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import { Util } from './Utils'
|
||||||
|
|
||||||
export interface QuerySource {
|
export interface QuerySource {
|
||||||
name: string
|
name: string
|
||||||
@@ -21,6 +22,7 @@ export interface QueryDiversityConfig {
|
|||||||
export class QueryDiversityEngine {
|
export class QueryDiversityEngine {
|
||||||
private config: QueryDiversityConfig
|
private config: QueryDiversityConfig
|
||||||
private cache: Map<string, { queries: string[]; expires: number }> = new Map()
|
private cache: Map<string, { queries: string[]; expires: number }> = new Map()
|
||||||
|
private util: Util = new Util()
|
||||||
|
|
||||||
constructor(config?: Partial<QueryDiversityConfig>) {
|
constructor(config?: Partial<QueryDiversityConfig>) {
|
||||||
this.config = {
|
this.config = {
|
||||||
@@ -56,7 +58,7 @@ export class QueryDiversityEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Shuffle and limit to requested count
|
// 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)
|
return final.length > 0 ? final : this.getLocalFallback(count)
|
||||||
}
|
}
|
||||||
@@ -275,7 +277,7 @@ export class QueryDiversityEngine {
|
|||||||
'education resources'
|
'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'
|
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)
|
* Clear cache (call between runs)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { ConfigRetryPolicy } from '../interface/Config'
|
import type { ConfigRetryPolicy } from '../interface/Config'
|
||||||
import Util from './Utils'
|
import { Util } from './Utils'
|
||||||
|
|
||||||
type NumericPolicy = {
|
type NumericPolicy = {
|
||||||
maxAttempts: number
|
maxAttempts: number
|
||||||
@@ -60,5 +60,3 @@ export class Retry {
|
|||||||
throw lastErr instanceof Error ? lastErr : new Error(String(lastErr))
|
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 {
|
private validateBrowserSettings(config: Config): void {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import axios from 'axios'
|
|||||||
import { BrowserFingerprintWithHeaders } from 'fingerprint-generator'
|
import { BrowserFingerprintWithHeaders } from 'fingerprint-generator'
|
||||||
|
|
||||||
import { log } from './Logger'
|
import { log } from './Logger'
|
||||||
import Retry from './Retry'
|
import { Retry } from './Retry'
|
||||||
|
|
||||||
import { ChromeVersion, EdgeVersion, Architecture, Platform } from '../interface/UserAgentUtil'
|
import { ChromeVersion, EdgeVersion, Architecture, Platform } from '../interface/UserAgentUtil'
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import ms from 'ms'
|
import ms from 'ms'
|
||||||
|
|
||||||
export default class Util {
|
export class Util {
|
||||||
|
|
||||||
async wait(ms: number): Promise<void> {
|
async wait(ms: number): Promise<void> {
|
||||||
// Safety check: prevent extremely long or negative waits
|
// Safety check: prevent extremely long or negative waits
|
||||||
|
|||||||
Reference in New Issue
Block a user