Skip to content

Commit

Permalink
Better handling of no entry giveways. Re-try if fails once
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Chapiewsky committed Apr 7, 2019
1 parent da6a600 commit dabb466
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/giveaways.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ async function navigateToGiveaway(page, giveawayNumber) {
}

/**
* Checks for the result of the giveaway entry and log appropriately
* Checks for the result of the giveaway entry and log appropriately.
* Returns true if result found, false if not.
* @param {Puppeteer.Page} page
* @returns {Promise<void>}
* @returns {Promise<Boolean>}
*/
async function handleGiveawayResult(page) {
try {
Expand Down Expand Up @@ -201,29 +202,41 @@ async function handleGiveawayResult(page) {
await sgMail.send(msg);
}
}
return true;
} catch (error) {
console.log('could not get result, oh well. Moving on!');
return false;
}
}

/**
* Attempts to enter a no entry requirement type giveaway
* Attempts to enter a no entry requirement type giveaway.
* Will try again if it fails once.
* @param {Puppeteer.Page} page
* @param {boolean} [repeatAttempt]
* @returns {Promise<void>}
*/
async function enterNoEntryRequirementGiveaway(page) {
async function enterNoEntryRequirementGiveaway(page, repeatAttempt) {
console.log('waiting for box...');
await checkForSwitchAccount(page);
await checkForPassword(page);
await checkForCaptcha(page);
try {
await page.waitForSelector('.tapToSeeText', { visible: true });
await page.waitFor(
() => document.querySelector('.tapToSeeText').style.opacity === '1'
);
await page.waitForSelector('#box_click_target');
await page.click('#box_click_target', { delay: 2000 });
} catch (error) {
console.log('could not find box?');
}

await handleGiveawayResult(page);
const resultFound = await handleGiveawayResult(page);
if (!resultFound && !repeatAttempt) {
console.log('lets try that again.');
await enterNoEntryRequirementGiveaway(page, true);
}
}

/**
Expand Down Expand Up @@ -312,11 +325,10 @@ async function enterGiveaways(page, pageNumber) {
try {
await navigateToGiveaway(page, i);
} catch (error) {
console.log('could not navigate to giveaway ' + i + ', oh well. Moving on!');
console.log('could not navigate to giveaway ' + i + '. Next!');
return;
}


//check if ended
let ended = await hasGiveawayEnded(page);
if (ended) {
Expand Down

0 comments on commit dabb466

Please sign in to comment.