This commit is contained in:
TheNetsky
2023-10-11 15:08:11 +02:00
parent 085db76f4c
commit c86a903793
13 changed files with 237 additions and 260 deletions

View File

@@ -6,74 +6,33 @@ import { doUrlReward } from './activities/UrlReward'
import { doThisOrThat } from './activities/ThisOrThat'
import { doABC } from './activities/ABC'
import { getPunchCardActivity } from '../browser/BrowserFunc'
import { getLatestTab } from '../browser/BrowserUtil'
import { getFormattedDate, wait } from '../util/Utils'
import { log } from '../util/Logger'
import { DashboardData, MorePromotion } from '../interface/DashboardData'
import { DashboardData, MorePromotion, PromotionalItem, PunchCard } from '../interface/DashboardData'
// Daily Set
export async function doDailySet(page: Page, data: DashboardData) {
const todayData = data.dailySetPromotions[getFormattedDate()]
const activitiesUncompleted = todayData?.filter(x => !x.complete) ?? []
const activitiesUncompleted = todayData?.filter(x => !x.complete && x.pointProgressMax > 0) ?? []
if (!activitiesUncompleted.length) {
log('DAILY-SET', 'All daily set items have already been completed')
log('DAILY-SET', 'All Daily Set" items have already been completed')
return
}
for (const activity of activitiesUncompleted) {
log('DAILY-SET', 'Started doing daily set items')
// Solve Activities
log('DAILY-SET', 'Started solving "Daily Set" items')
// If activity does not give points, skip
if (activity.pointProgressMax <= 0) {
continue
}
await solveActivities(page, activitiesUncompleted)
switch (activity.promotionType) {
// Quiz (Poll, Quiz or ABC)
case 'quiz':
switch (activity.pointProgressMax) {
// Poll or ABC (Usually 10 points)
case 10:
// Normal poll
if (activity.destinationUrl.toLowerCase().includes('pollscenarioid')) {
log('ACTIVITY', 'Found daily activity type: Poll')
await doPoll(page, activity)
} else { // ABC
log('ACTIVITY', 'Found daily activity type: ABC')
await doABC(page, activity)
}
break
// This Or That Quiz (Usually 50 points)
case 50:
log('ACTIVITY', 'Found daily activity type: ThisOrThat')
await doThisOrThat(page, activity)
break
// Quizzes are usually 30-40 points
default:
log('ACTIVITY', 'Found daily activity type: Quiz')
await doQuiz(page, activity)
break
}
break
// UrlReward (Visit)
case 'urlreward':
log('ACTIVITY', 'Found daily activity type: UrlReward')
await doUrlReward(page, activity)
break
default:
break
}
await wait(1500)
}
log('DAILY-SET', 'Daily set items have been completed')
log('DAILY-SET', 'All "Daily Set" items have been completed')
}
// Punch Card
@@ -82,66 +41,31 @@ export async function doPunchCard(page: Page, data: DashboardData) {
const punchCardsUncompleted = data.punchCards?.filter(x => !x.parentPromotion.complete) ?? [] // Only return uncompleted punch cards
if (!punchCardsUncompleted.length) {
log('PUNCH-CARD', 'All punch cards have already been completed')
log('PUNCH-CARD', 'All "Punch Cards" have already been completed')
return
}
for (const promotion of punchCardsUncompleted) {
const activities = promotion.childPromotions.filter(x => !x.complete) // Only return uncompleted activities
for (const punchCard of punchCardsUncompleted) {
const activitiesUncompleted = punchCard.childPromotions.filter(x => !x.complete) // Only return uncompleted activities
for (const activity of activities) {
log('PUNCH-CARD', 'Started doing daily set items')
// Solve Activities
log('PUNCH-CARD', `Started solving "Punch Card" items for punchcard: "${punchCard.parentPromotion.title}"`)
// If activity does not give points, skip
if (activity.pointProgressMax <= 0) {
continue
}
const browser = page.browser()
page = await browser.newPage()
switch (activity.promotionType) {
// Quiz (Poll, Quiz or ABC)
case 'quiz':
// Got to punch card index page in a new tab
await page.goto(punchCard.parentPromotion.destinationUrl, { referer: 'https://rewards.bing.com/' })
switch (activity.pointProgressMax) {
// Poll or ABC (Usually 10 points)
case 10:
// Normal poll
if (activity.destinationUrl.toLowerCase().includes('pollscenarioid')) {
log('ACTIVITY', 'Found daily activity type: Poll')
await doPoll(page, activity)
} else { // ABC
log('ACTIVITY', 'Found daily activity type: ABC')
await doABC(page, activity)
}
break
await solveActivities(page, activitiesUncompleted, punchCard)
// This Or That Quiz (Usually 50 points)
case 50:
log('ACTIVITY', 'Found daily activity type: ThisOrThat')
await doThisOrThat(page, activity)
break
// Close the punch card index page
await page.close()
// Quizzes are usually 30-40 points
default:
log('ACTIVITY', 'Found daily activity type: Quiz')
await doQuiz(page, activity)
break
}
break
// UrlReward (Visit)
case 'urlreward':
log('ACTIVITY', 'Found daily activity type: UrlReward')
await doUrlReward(page, activity)
break
default:
break
}
await wait(1500)
}
log('PUNCH-CARD', `All items for punchcard: "${punchCard.parentPromotion.title}" have been completed`)
}
log('PUNCH-CARD', 'Punch card items have been completed')
log('PUNCH-CARD', 'All "Punch Card" items have been completed')
}
// More Promotions
@@ -153,59 +77,87 @@ export async function doMorePromotions(page: Page, data: DashboardData) {
morePromotions.push(data.promotionalItem as unknown as MorePromotion)
}
const activitiesUncompleted = morePromotions?.filter(x => !x.complete) ?? []
const activitiesUncompleted = morePromotions?.filter(x => !x.complete && x.pointProgressMax > 0) ?? []
if (!activitiesUncompleted.length) {
log('MORE-PROMOTIONS', 'All more promotion items have already been completed')
log('MORE-PROMOTIONS', 'All "More Promotion" items have already been completed')
return
}
for (const activity of activitiesUncompleted) {
// If activity does not give points, skip
if (activity.pointProgressMax <= 0) {
continue
// Solve Activities
log('MORE-PROMOTIONS', 'Started solving "More Promotions" item')
await solveActivities(page, activitiesUncompleted)
log('MORE-PROMOTIONS', 'All "More Promotion" items have been completed')
}
// Solve all the different types of activities
async function solveActivities(page: Page, activities: PromotionalItem[] | MorePromotion[], punchCard?: PunchCard) {
try {
for (const activity of activities) {
if (punchCard) {
const selector = await getPunchCardActivity(page, activity)
// Wait for page to load and click to load the activity in a new tab
await page.waitForSelector(selector, { timeout: 5000 })
await page.click(selector)
} else {
const selector = `[data-bi-id="${activity.offerId}"]`
// Wait for page to load and click to load the activity in a new tab
await page.waitForSelector(selector, { timeout: 5000 })
await page.click(selector)
}
// Select the new activity page
const activityPage = await getLatestTab(page)
switch (activity.promotionType) {
// Quiz (Poll, Quiz or ABC)
case 'quiz':
switch (activity.pointProgressMax) {
// Poll or ABC (Usually 10 points)
case 10:
// Normal poll
if (activity.destinationUrl.toLowerCase().includes('pollscenarioid')) {
log('ACTIVITY', `Found activity type: "Poll" title: "${activity.title}"`)
await doPoll(activityPage)
} else { // ABC
log('ACTIVITY', `Found activity type: "ABC" title: "${activity.title}"`)
await doABC(activityPage)
}
break
// This Or That Quiz (Usually 50 points)
case 50:
log('ACTIVITY', `Found activity type: "ThisOrThat" title: "${activity.title}"`)
await doThisOrThat(activityPage, activity)
break
// Quizzes are usually 30-40 points
default:
log('ACTIVITY', `Found activity type: "Quiz" title: "${activity.title}"`)
await doQuiz(activityPage)
break
}
break
// UrlReward (Visit)
case 'urlreward':
log('ACTIVITY', `Found activity type: "UrlReward" title: "${activity.title}"`)
await doUrlReward(activityPage)
break
default:
break
}
await wait(1500)
}
switch (activity.promotionType) {
// Quiz (Poll, Quiz or ABC)
case 'quiz':
switch (activity.pointProgressMax) {
// Poll or ABC (Usually 10 points)
case 10:
// Normal poll
if (activity.destinationUrl.toLowerCase().includes('pollscenarioid')) {
log('ACTIVITY', 'Found daily activity type: Poll')
await doPoll(page, activity)
} else { // ABC
log('ACTIVITY', 'Found daily activity type: ABC')
await doABC(page, activity)
}
break
// This Or That Quiz (Usually 50 points)
case 50:
log('ACTIVITY', 'Found daily activity type: ThisOrThat')
await doThisOrThat(page, activity)
break
// Quizzes are usually 30-40 points
default:
log('ACTIVITY', 'Found promotion activity type: Quiz')
await doQuiz(page, activity)
break
}
break
// UrlReward (Visit)
case 'urlreward':
log('ACTIVITY', 'Found promotion activity type: UrlReward')
await doUrlReward(page, activity)
break
default:
break
}
await wait(1500)
} catch (error) {
log('ACTIVITY', 'An error occurred:' + error, 'error')
}
}