- Fix login not working
- Sessions are now saved after logging in
- Check if promotions, and searches are available before counting total point amount
This commit is contained in:
TheNetsky
2024-03-01 12:19:48 +01:00
parent cf7f7ac790
commit 64048e35d7
5 changed files with 26 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "microsoft-rewards-script", "name": "microsoft-rewards-script",
"version": "1.4.4", "version": "1.4.5",
"description": "Automatically do tasks for Microsoft Rewards but in TS!", "description": "Automatically do tasks for Microsoft Rewards but in TS!",
"main": "index.js", "main": "index.js",
"engines": { "engines": {
@@ -34,9 +34,9 @@
"dependencies": { "dependencies": {
"axios": "^1.6.7", "axios": "^1.6.7",
"cheerio": "^1.0.0-rc.12", "cheerio": "^1.0.0-rc.12",
"fingerprint-generator": "^2.1.48", "fingerprint-generator": "^2.1.49",
"fingerprint-injector": "^2.1.48", "fingerprint-injector": "^2.1.49",
"playwright": "^1.41.2", "playwright": "^1.42.0",
"ts-node": "^10.9.2" "ts-node": "^10.9.2"
} }
} }

View File

@@ -142,7 +142,9 @@ export default class BrowserFunc {
let totalEarnablePoints = 0 let totalEarnablePoints = 0
// Desktop Search Points // Desktop Search Points
if (data.userStatus.counters.pcSearch?.length) {
data.userStatus.counters.pcSearch.forEach(x => totalEarnablePoints += (x.pointProgressMax - x.pointProgress)) data.userStatus.counters.pcSearch.forEach(x => totalEarnablePoints += (x.pointProgressMax - x.pointProgress))
}
// Mobile Search Points // Mobile Search Points
if (data.userStatus.counters.mobileSearch?.length) { if (data.userStatus.counters.mobileSearch?.length) {
@@ -153,12 +155,14 @@ export default class BrowserFunc {
data.dailySetPromotions[this.bot.utils.getFormattedDate()]?.forEach(x => totalEarnablePoints += (x.pointProgressMax - x.pointProgress)) data.dailySetPromotions[this.bot.utils.getFormattedDate()]?.forEach(x => totalEarnablePoints += (x.pointProgressMax - x.pointProgress))
// More Promotions // More Promotions
if (data.morePromotions?.length) {
data.morePromotions.forEach(x => { data.morePromotions.forEach(x => {
// Only count points from supported activities // Only count points from supported activities
if (['quiz', 'urlreward'].includes(x.activityType)) { if (['quiz', 'urlreward'].includes(x.activityType)) {
totalEarnablePoints += (x.pointProgressMax - x.pointProgress) totalEarnablePoints += (x.pointProgressMax - x.pointProgress)
} }
}) })
}
return totalEarnablePoints return totalEarnablePoints
} catch (error) { } catch (error) {

View File

@@ -2,6 +2,7 @@ import { Page } from 'playwright'
import readline from 'readline' import readline from 'readline'
import { MicrosoftRewardsBot } from '../index' import { MicrosoftRewardsBot } from '../index'
import { saveSessionData } from '../util/Load'
const rl = readline.createInterface({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
@@ -26,14 +27,12 @@ export class Login {
if (!isLoggedIn) { if (!isLoggedIn) {
// Check if account is locked // Check if account is locked
const isLocked = await page.waitForSelector('.serviceAbusePageContainer', { state: 'visible', timeout: 10_000 }).then(() => true).catch(() => false) const isLocked = await page.waitForSelector('.serviceAbusePageContainer', { state: 'visible', timeout: 1000 }).then(() => true).catch(() => false)
if (isLocked) { if (isLocked) {
this.bot.log('LOGIN', 'This account has been locked!', 'error') this.bot.log('LOGIN', 'This account has been locked!', 'error')
throw new Error('Account has been locked!') throw new Error('Account has been locked!')
} }
await page.waitForSelector('#loginHeader', { state: 'visible', timeout: 10_000 })
await this.execLogin(page, email, password) await this.execLogin(page, email, password)
this.bot.log('LOGIN', 'Logged into Microsoft successfully') this.bot.log('LOGIN', 'Logged into Microsoft successfully')
} else { } else {
@@ -43,6 +42,9 @@ export class Login {
// Check if logged in to bing // Check if logged in to bing
await this.checkBingLogin(page) await this.checkBingLogin(page)
// Save session
await saveSessionData(this.bot.config.sessionPath, page.context(), email, this.bot.isMobile)
// We're done logging in // We're done logging in
this.bot.log('LOGIN', 'Logged in successfully') this.bot.log('LOGIN', 'Logged in successfully')

View File

@@ -178,8 +178,7 @@ export class MicrosoftRewardsBot {
} }
// Save cookies // Save cookies
const cookies = await browser.cookies() await saveSessionData(this.config.sessionPath, browser, account.email, this.isMobile)
await saveSessionData(this.config.sessionPath, account.email, this.isMobile, cookies)
// Close desktop browser // Close desktop browser
return await this.closeBrowser(browser, account.email) return await this.closeBrowser(browser, account.email)
@@ -247,8 +246,7 @@ export class MicrosoftRewardsBot {
private async closeBrowser(browser: BrowserContext, email: string) { private async closeBrowser(browser: BrowserContext, email: string) {
// Save cookies // Save cookies
const cookies = await browser.cookies() await saveSessionData(this.config.sessionPath, browser, email, this.isMobile)
await saveSessionData(this.config.sessionPath, email, this.isMobile, cookies)
// Close browser // Close browser
await browser.close() await browser.close()

View File

@@ -1,4 +1,4 @@
import { Cookie } from 'playwright' import { BrowserContext, Cookie } from 'playwright'
import { BrowserFingerprintWithHeaders } from 'fingerprint-generator' import { BrowserFingerprintWithHeaders } from 'fingerprint-generator'
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
@@ -67,8 +67,10 @@ export async function loadSessionData(sessionPath: string, email: string, isMobi
} }
} }
export async function saveSessionData(sessionPath: string, email: string, isMobile: boolean, cookies: Cookie[]): Promise<string> { export async function saveSessionData(sessionPath: string, browser: BrowserContext, email: string, isMobile: boolean): Promise<string> {
try { try {
const cookies = await browser.cookies()
// Fetch path // Fetch path
const sessionDir = path.join(__dirname, '../browser/', sessionPath, email) const sessionDir = path.join(__dirname, '../browser/', sessionPath, email)