This commit is contained in:
TheNetsky
2023-10-08 13:55:36 +02:00
parent e982e6e25f
commit 03ba5129c6
16 changed files with 419 additions and 345 deletions

View File

@@ -1,10 +1,9 @@
import { Browser, mobileBrowser } from './browser/Browser'
import Browser from './browser/Browser'
import { getDashboardData, getEarnablePoints, goHome } from './browser/BrowserFunc'
import { log } from './util/Logger'
import { login } from './functions/Login'
import { doDailySet } from './functions/DailySet'
import { doMorePromotions } from './functions/MorePromotions'
import { doDailySet, doMorePromotions } from './functions/Workers'
import { doSearch } from './functions/activities/Search'
import { Account } from './interface/Account'
@@ -12,115 +11,119 @@ import { Account } from './interface/Account'
import accounts from './accounts.json'
import { runOnZeroPoints, searches } from './config.json'
let collectedPoints = 0
// Main bot class
class MicrosoftRewardsBot {
private collectedPoints: number = 0
private browserFactory: Browser = new Browser()
async function main() {
log('MAIN', 'Bot started')
async run() {
log('MAIN', 'Bot started')
for (const account of accounts) {
log('MAIN', `Started tasks for account ${account.email}`)
for (const account of accounts) {
log('MAIN', `Started tasks for account ${account.email}`)
// Desktop Searches, DailySet and More Promotions
await Desktop(account)
// Desktop Searches, DailySet and More Promotions
await this.Desktop(account)
// If runOnZeroPoints is false and 0 points to earn, stop and try the next account
if (!runOnZeroPoints && collectedPoints === 0) {
continue
// If runOnZeroPoints is false and 0 points to earn, stop and try the next account
if (!runOnZeroPoints && this.collectedPoints === 0) {
continue
}
// Mobile Searches
await this.Mobile(account)
log('MAIN', `Completed tasks for account ${account.email}`)
}
// Mobile Searches
await Mobile(account)
log('MAIN', `Completed tasks for account ${account.email}`)
// Clean exit
log('MAIN', 'Completed tasks for ALL accounts')
log('MAIN', 'Bot exited')
process.exit(0)
}
// Clean exit
log('MAIN', 'Completed tasks for ALL accounts')
log('MAIN', 'Bot exited')
process.exit(0)
}
// Desktop
async Desktop(account: Account) {
const browser = await this.browserFactory.createBrowser(account.email, false)
const page = await browser.newPage()
log('MAIN', 'Starting DESKTOP browser')
// Desktop
async function Desktop(account: Account) {
const browser = await Browser(account.email)
const page = await browser.newPage()
// Login into MS Rewards
await login(page, account.email, account.password)
log('MAIN', 'Starting DESKTOP browser')
const wentHome = await goHome(page)
if (!wentHome) {
throw log('MAIN', 'Unable to get dashboard page', 'error')
}
// Login into MS Rewards
await login(page, account.email, account.password)
const data = await getDashboardData(page)
log('MAIN-POINTS', `Current point count: ${data.userStatus.availablePoints}`)
const wentHome = await goHome(page)
if (!wentHome) {
throw log('MAIN', 'Unable to get dashboard page', 'error')
}
const earnablePoints = await getEarnablePoints(data)
this.collectedPoints = earnablePoints
log('MAIN-POINTS', `You can earn ${earnablePoints} points today`)
const data = await getDashboardData(page)
log('MAIN-POINTS', `Current point count: ${data.userStatus.availablePoints}`)
// If runOnZeroPoints is false and 0 points to earn, don't continue
if (!runOnZeroPoints && this.collectedPoints === 0) {
log('MAIN', 'No points to earn and "runOnZeroPoints" is set to "false", stopping')
const earnablePoints = await getEarnablePoints(data)
collectedPoints = earnablePoints
log('MAIN-POINTS', `You can earn ${earnablePoints} points today`)
// Close desktop browser
return await browser.close()
}
// If runOnZeroPoints is false and 0 points to earn, don't continue
if (!runOnZeroPoints && collectedPoints === 0) {
log('MAIN', 'No points to earn and "runOnZeroPoints" is set to "false", stopping')
// Complete daily set
await doDailySet(page, data)
// Complete more promotions
await doMorePromotions(page, data)
// Do desktop searches
if (searches.doDesktop) {
await doSearch(page, data, false)
}
// Close desktop browser
return await browser.close()
await browser.close()
}
// Complete daily set
await doDailySet(page, data)
async Mobile(account: Account) {
const browser = await this.browserFactory.createBrowser(account.email, true)
const page = await browser.newPage()
// Complete more promotions
await doMorePromotions(page, data)
log('MAIN', 'Starting MOBILE browser')
// Do desktop searches
if (searches.doDesktop) {
await doSearch(page, data, false)
}
// Login into MS Rewards
await login(page, account.email, account.password)
// Close desktop browser
await browser.close()
}
await goHome(page)
async function Mobile(account: Account) {
const browser = await mobileBrowser(account.email)
const page = await browser.newPage()
const data = await getDashboardData(page)
log('MAIN', 'Starting MOBILE browser')
// If no mobile searches data found, stop (Does not exist on new accounts)
if (!data.userStatus.counters.mobileSearch) {
log('MAIN', 'No mobile searches found, stopping')
// Login into MS Rewards
await login(page, account.email, account.password)
// Close mobile browser
return await browser.close()
}
await goHome(page)
// Do mobile searches
if (searches.doMobile) {
await doSearch(page, data, true)
}
const data = await getDashboardData(page)
// Fetch new points
const earnablePoints = await getEarnablePoints(data, page)
// If no mobile searches data found, stop (Does not exist on new accounts)
if (!data.userStatus.counters.mobileSearch) {
log('MAIN', 'No mobile searches found, stopping')
// If the new earnable is 0, means we got all the points, else retract
this.collectedPoints = earnablePoints === 0 ? this.collectedPoints : (this.collectedPoints - earnablePoints)
log('MAIN-POINTS', `The script collected ${this.collectedPoints} points today`)
// Close mobile browser
return await browser.close()
await browser.close()
}
// Do mobile searches
if (searches.doMobile) {
await doSearch(page, data, true)
}
// Fetch new points
const earnablePoints = await getEarnablePoints(data, page)
// If the new earnable is 0, means we got all the points, else retract
collectedPoints = earnablePoints === 0 ? collectedPoints : (collectedPoints - earnablePoints)
log('MAIN-POINTS', `The script collected ${collectedPoints} points today`)
// Close mobile browser
await browser.close()
}
// Run main script
main()
new MicrosoftRewardsBot().run()