mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-27 07:51:02 +00:00
Refactor: Remove legacy code and improve import statements across multiple files
This commit is contained in:
@@ -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