Files
Microsoft-Rewards-Script/src/functions/activities/api/UrlReward.ts
TheNetsky 2c4d85f732 v3 init
Based of v3.0.0b10.
2025-12-11 16:16:32 +01:00

130 lines
4.9 KiB
TypeScript

import type { AxiosRequestConfig } from 'axios'
import type { BasePromotion } from '../../../interface/DashboardData'
import { Workers } from '../../Workers'
export class UrlReward extends Workers {
private cookieHeader: string = ''
private fingerprintHeader: { [x: string]: string } = {}
private gainedPoints: number = 0
private oldBalance: number = this.bot.userData.currentPoints
public async doUrlReward(promotion: BasePromotion) {
if (!this.bot.requestToken) {
this.bot.logger.warn(
this.bot.isMobile,
'URL-REWARD',
'Skipping: Request token not available, this activity requires it!'
)
return
}
const offerId = promotion.offerId
this.bot.logger.info(
this.bot.isMobile,
'URL-REWARD',
`Starting UrlReward | offerId=${offerId} | geo=${this.bot.userData.geoLocale} | oldBalance=${this.oldBalance}`
)
try {
this.cookieHeader = (this.bot.isMobile ? this.bot.cookies.mobile : this.bot.cookies.desktop)
.map((c: { name: string; value: string }) => `${c.name}=${c.value}`)
.join('; ')
const fingerprintHeaders = { ...this.bot.fingerprint.headers }
delete fingerprintHeaders['Cookie']
delete fingerprintHeaders['cookie']
this.fingerprintHeader = fingerprintHeaders
this.bot.logger.debug(
this.bot.isMobile,
'URL-REWARD',
`Prepared UrlReward headers | offerId=${offerId} | cookieLength=${this.cookieHeader.length} | fingerprintHeaderKeys=${Object.keys(this.fingerprintHeader).length}`
)
const formData = new URLSearchParams({
id: offerId,
hash: promotion.hash,
timeZone: '60',
activityAmount: '1',
dbs: '0',
form: '',
type: '',
__RequestVerificationToken: this.bot.requestToken
})
this.bot.logger.debug(
this.bot.isMobile,
'URL-REWARD',
`Prepared UrlReward form data | offerId=${offerId} | hash=${promotion.hash} | timeZone=60 | activityAmount=1`
)
const request: AxiosRequestConfig = {
url: 'https://rewards.bing.com/api/reportactivity?X-Requested-With=XMLHttpRequest',
method: 'POST',
headers: {
...(this.bot.fingerprint?.headers ?? {}),
Cookie: this.cookieHeader,
Referer: 'https://rewards.bing.com/',
Origin: 'https://rewards.bing.com'
},
data: formData
}
this.bot.logger.debug(
this.bot.isMobile,
'URL-REWARD',
`Sending UrlReward request | offerId=${offerId} | url=${request.url}`
)
const response = await this.bot.axios.request(request)
this.bot.logger.debug(
this.bot.isMobile,
'URL-REWARD',
`Received UrlReward response | offerId=${offerId} | status=${response.status}`
)
const newBalance = await this.bot.browser.func.getCurrentPoints()
this.gainedPoints = newBalance - this.oldBalance
this.bot.logger.debug(
this.bot.isMobile,
'URL-REWARD',
`Balance delta after UrlReward | offerId=${offerId} | oldBalance=${this.oldBalance} | newBalance=${newBalance} | gainedPoints=${this.gainedPoints}`
)
if (this.gainedPoints > 0) {
this.bot.userData.currentPoints = newBalance
this.bot.userData.gainedPoints = (this.bot.userData.gainedPoints ?? 0) + this.gainedPoints
this.bot.logger.info(
this.bot.isMobile,
'URL-REWARD',
`Completed UrlReward | offerId=${offerId} | status=${response.status} | gainedPoints=${this.gainedPoints} | newBalance=${newBalance}`,
'green'
)
} else {
this.bot.logger.warn(
this.bot.isMobile,
'URL-REWARD',
`Failed UrlReward with no points | offerId=${offerId} | status=${response.status} | oldBalance=${this.oldBalance} | newBalance=${newBalance}`
)
}
this.bot.logger.debug(this.bot.isMobile, 'URL-REWARD', `Waiting after UrlReward | offerId=${offerId}`)
await this.bot.utils.wait(this.bot.utils.randomDelay(5000, 10000))
} catch (error) {
this.bot.logger.error(
this.bot.isMobile,
'URL-REWARD',
`Error in doUrlReward | offerId=${promotion.offerId} | message=${error instanceof Error ? error.message : String(error)}`
)
}
}
}