mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-10 17:26:17 +00:00
feat: update README and SchedulerManager for improved automatic scheduling configuration
This commit is contained in:
@@ -25,7 +25,7 @@ This TypeScript-based automation bot helps you maximize your **Microsoft Rewards
|
|||||||
- 📅 **Daily Activities** — Quizzes, polls, daily sets, and punch cards
|
- 📅 **Daily Activities** — Quizzes, polls, daily sets, and punch cards
|
||||||
- 🤖 **Human-like Behavior** — Advanced humanization system to avoid detection
|
- 🤖 **Human-like Behavior** — Advanced humanization system to avoid detection
|
||||||
- 🛡️ **Risk Management** — Built-in ban detection and prediction with ML algorithms
|
- 🛡️ **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
|
- 🔔 **Notifications** — Discord webhooks and NTFY push alerts
|
||||||
- 🐳 **Docker Support** — Easy containerized deployment
|
- 🐳 **Docker Support** — Easy containerized deployment
|
||||||
- 🔐 **Multi-Account** — Manage multiple accounts with parallel execution
|
- 🔐 **Multi-Account** — Manage multiple accounts with parallel execution
|
||||||
|
|||||||
@@ -130,11 +130,9 @@ export class MicrosoftRewardsBot {
|
|||||||
this.accountJobState = new JobState(this.config)
|
this.accountJobState = new JobState(this.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup automatic scheduler if enabled
|
// Setup or remove automatic scheduler based on config
|
||||||
if (this.config.scheduling?.enabled) {
|
const scheduler = new SchedulerManager(this.config)
|
||||||
const scheduler = new SchedulerManager(this.config)
|
await scheduler.setup()
|
||||||
await scheduler.setup()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private shouldSkipAccount(email: string, dayKey: string): boolean {
|
private shouldSkipAccount(email: string, dayKey: string): boolean {
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ export class SchedulerManager {
|
|||||||
async setup(): Promise<void> {
|
async setup(): Promise<void> {
|
||||||
const scheduling = this.config.scheduling
|
const scheduling = this.config.scheduling
|
||||||
if (!scheduling?.enabled) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,13 +293,13 @@ export class SchedulerManager {
|
|||||||
try {
|
try {
|
||||||
currentCrontab = execSync('crontab -l', { encoding: 'utf-8' })
|
currentCrontab = execSync('crontab -l', { encoding: 'utf-8' })
|
||||||
} catch {
|
} catch {
|
||||||
log('main', 'SCHEDULER', 'No crontab found', 'log')
|
// No crontab exists, nothing to remove
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const jobMarker = '# Microsoft-Rewards-Bot'
|
const jobMarker = '# Microsoft-Rewards-Bot'
|
||||||
if (!currentCrontab.includes(jobMarker)) {
|
if (!currentCrontab.includes(jobMarker)) {
|
||||||
log('main', 'SCHEDULER', 'No Microsoft Rewards Bot cron job found', 'log')
|
// No job found, nothing to remove
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,58 +327,8 @@ export class SchedulerManager {
|
|||||||
try {
|
try {
|
||||||
execSync(`schtasks /Delete /TN "${taskName}" /F`, { stdio: 'ignore' })
|
execSync(`schtasks /Delete /TN "${taskName}" /F`, { stdio: 'ignore' })
|
||||||
log('main', 'SCHEDULER', '✅ Windows Task removed successfully', 'log', 'green')
|
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<void> {
|
|
||||||
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<void> {
|
|
||||||
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 {
|
} catch {
|
||||||
log('main', 'SCHEDULER', '❌ No crontab configured', 'warn')
|
// Task doesn't exist or already removed, nothing to do
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async statusWindowsTask(): Promise<void> {
|
|
||||||
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')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user