From 8e1be006186d2e7eff5884a0ca93c63470a3ddd3 Mon Sep 17 00:00:00 2001 From: LightZirconite Date: Tue, 4 Nov 2025 20:54:10 +0100 Subject: [PATCH] feat: update README and SchedulerManager for improved automatic scheduling configuration --- README.md | 2 +- src/index.ts | 8 ++--- src/util/SchedulerManager.ts | 60 ++++-------------------------------- 3 files changed, 10 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index fd972db..062cc75 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ This TypeScript-based automation bot helps you maximize your **Microsoft Rewards - 📅 **Daily Activities** — Quizzes, polls, daily sets, and punch cards - 🤖 **Human-like Behavior** — Advanced humanization system to avoid detection - 🛡️ **Risk Management** — Built-in ban detection and prediction with ML algorithms -- ⏰ **External Scheduling** — Ready for cron, systemd timers, and Windows Task Scheduler +- ⏰ **Automatic Scheduling** — Easy configuration for cron (Linux/Raspberry Pi) and Windows Task Scheduler - 🔔 **Notifications** — Discord webhooks and NTFY push alerts - 🐳 **Docker Support** — Easy containerized deployment - 🔐 **Multi-Account** — Manage multiple accounts with parallel execution diff --git a/src/index.ts b/src/index.ts index 6210946..45013b9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -130,11 +130,9 @@ export class MicrosoftRewardsBot { this.accountJobState = new JobState(this.config) } - // Setup automatic scheduler if enabled - if (this.config.scheduling?.enabled) { - const scheduler = new SchedulerManager(this.config) - await scheduler.setup() - } + // Setup or remove automatic scheduler based on config + const scheduler = new SchedulerManager(this.config) + await scheduler.setup() } private shouldSkipAccount(email: string, dayKey: string): boolean { diff --git a/src/util/SchedulerManager.ts b/src/util/SchedulerManager.ts index 5f51ca8..f560cc6 100644 --- a/src/util/SchedulerManager.ts +++ b/src/util/SchedulerManager.ts @@ -19,7 +19,9 @@ export class SchedulerManager { async setup(): Promise { const scheduling = this.config.scheduling if (!scheduling?.enabled) { - log('main', 'SCHEDULER', 'Automatic scheduling is disabled in config', 'log') + // If scheduling is disabled, remove any existing scheduled tasks + log('main', 'SCHEDULER', 'Automatic scheduling is disabled, checking for existing tasks to remove...') + await this.remove() return } @@ -291,13 +293,13 @@ export class SchedulerManager { try { currentCrontab = execSync('crontab -l', { encoding: 'utf-8' }) } catch { - log('main', 'SCHEDULER', 'No crontab found', 'log') + // No crontab exists, nothing to remove return } const jobMarker = '# Microsoft-Rewards-Bot' if (!currentCrontab.includes(jobMarker)) { - log('main', 'SCHEDULER', 'No Microsoft Rewards Bot cron job found', 'log') + // No job found, nothing to remove return } @@ -325,58 +327,8 @@ export class SchedulerManager { try { execSync(`schtasks /Delete /TN "${taskName}" /F`, { stdio: 'ignore' }) log('main', 'SCHEDULER', '✅ Windows Task removed successfully', 'log', 'green') - } catch (error) { - log('main', 'SCHEDULER', `Task "${taskName}" not found or already removed`, 'log') - } - } - - async status(): Promise { - const platform = os.platform() - log('main', 'SCHEDULER', 'Checking scheduler status...') - - try { - if (platform === 'win32') { - await this.statusWindowsTask() - } else if (platform === 'linux' || platform === 'darwin') { - await this.statusCron() - } - } catch (error) { - log('main', 'SCHEDULER', `Failed to check status: ${error instanceof Error ? error.message : String(error)}`, 'error') - } - } - - private async statusCron(): Promise { - try { - const currentCrontab = execSync('crontab -l', { encoding: 'utf-8' }) - const jobMarker = '# Microsoft-Rewards-Bot' - - if (currentCrontab.includes(jobMarker)) { - const lines = currentCrontab.split('\n') - const jobIndex = lines.findIndex(line => line.includes(jobMarker)) - if (jobIndex >= 0 && jobIndex + 1 < lines.length) { - log('main', 'SCHEDULER', '✅ Cron job is active', 'log', 'green') - log('main', 'SCHEDULER', `Job: ${lines[jobIndex + 1]}`, 'log') - } - } else { - log('main', 'SCHEDULER', '❌ No cron job found', 'warn') - } } catch { - log('main', 'SCHEDULER', '❌ No crontab configured', 'warn') - } - } - - private async statusWindowsTask(): Promise { - const taskConfig = this.config.scheduling?.taskScheduler || {} - const taskName = taskConfig.taskName || 'Microsoft-Rewards-Bot' - - try { - const result = execSync(`schtasks /Query /TN "${taskName}" /FO LIST /V`, { encoding: 'utf-8' }) - if (result.includes(taskName)) { - log('main', 'SCHEDULER', '✅ Windows Task is active', 'log', 'green') - log('main', 'SCHEDULER', `Task name: ${taskName}`, 'log') - } - } catch { - log('main', 'SCHEDULER', `❌ Task "${taskName}" not found`, 'warn') + // Task doesn't exist or already removed, nothing to do } } }