Skip to content

Commit

Permalink
Merge pull request #78 from alfficcadenti/SkipQuest
Browse files Browse the repository at this point in the history
added skip quest functoinality
  • Loading branch information
alfficcadenti authored Nov 10, 2021
2 parents 9e3618c + 2898c54 commit 6d5e14f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CLAIM_SEASON_REWARD=false
CLAIM_DAILY_QUEST_REWARD=true
#ECR_STOP_LIMIT=50
#ECR_RECOVER_TO=99
#SKIP_QUEST=life,snipe,neutral
#FAVOURITE_DECK=dragon #choose only one splinter among: fire, life, earth, water, death, dragon
ACCOUNT=lowercase_username
PASSWORD=postingkey
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ By default, the BOT checks automatically for daily quest rewards but the claim o
By default, the BOT will run as headless. Set `HEADLESS` to false to see your browser. The default option is true
By default, the BOT will run no matter the ECR level. Set `ECR_STOP_LIMIT` to a specific value you want the bot to rest and recover the ECR. The bot will recover until the `ECR_RECOVER_TO` is reached or until 100% ECR.
If you want the bot to play only one color (when it's possible), use the variable `FAVOURITE_DECK` and specify the splinter by choosing only one among: fire, life, earth, water, death, dragon.
If you want the bot to try to skip specific quest types you can include multiple quest in the variable `SKIP_QUEST` separated by the comma (`SKIP_QUEST=life,snipe,neutral`). whenever it's possible, the bot will click to ask for a new one. Remember you can only ask for a new one once based on the game rules.

Example:

Expand All @@ -57,6 +58,9 @@ Example:

- `FAVOURITE_DECK=dragon`

- `SKIP_QUEST=life,snipe,neutral`




## Local History backup (battlesGetData.js)
Expand Down
4 changes: 2 additions & 2 deletions helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const teamActualSplinterToPlay = (teamIdsArray) => teamIdsArray.reduce(deckValid

const clickOnElement = async (page, selector, timeout=20000, delayBeforeClicking = 0) => {
try {
const elem = await page.waitForSelector(selector, { timeout: timeout });
const elem = await page.waitForSelector(selector, {timeout: timeout });
if(elem) {
await sleep(delayBeforeClicking);
console.log('Clicking element', selector);
Expand All @@ -42,7 +42,7 @@ const clickOnElement = async (page, selector, timeout=20000, delayBeforeClicking
}

const getElementText = async (page, selector, timeout=15000) => {
const element = await page.waitForSelector(selector, { timeout: timeout });
const element = await page.waitForSelector(selector, {timeout: timeout });
const text = await element.evaluate(el => el.textContent);
return text;
}
Expand Down
35 changes: 29 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ async function startBotPlayMatch(page) {
console.log('Error for quest details. Splinterlands API didnt work or you used incorrect username, remove @ and dont use email')
}

if(process.env.SKIP_QUEST && quest?.splinter && process.env.SKIP_QUEST.split(',').includes(quest?.splinter) && quest?.total !== quest?.completed) {
try {
await page.click('#quest_new_btn')
.then(async a=>{
await page.reload();
console.log('New quest requested')})
.catch(e=>console.log('Cannot click on new quest'))

} catch(e) {
console.log('Error while skipping new quest')
}
}

console.log('getting user cards collection from splinterlands API...')
const myCards = await getCards()
.then((x)=>{console.log('cards retrieved'); return x})
Expand Down Expand Up @@ -319,13 +332,13 @@ const blockedResources = [
args: ['--no-sandbox',
'--disable-setuid-sandbox',
//'--disable-dev-shm-usage',
// '--disable-accelerated-2d-canvas',
//'--disable-accelerated-2d-canvas',
// '--disable-canvas-aa',
// '--disable-2d-canvas-clip-aa',
// '--disable-gl-drawing-for-tests',
//'--disable-gl-drawing-for-tests',
// '--no-first-run',
// '--no-zygote',
// '--disable-dev-shm-usage',
'--disable-dev-shm-usage',
// '--use-gl=swiftshader',
// '--single-process', // <- this one doesn't works in Windows
// '--disable-gpu',
Expand Down Expand Up @@ -357,14 +370,24 @@ const blockedResources = [
await page.on('dialog', async dialog => {
await dialog.accept();
});
await page.on('error', function(err) {
const errorMessage = err.toString();
console.log('browser error: ', errorMessage)
});
await page.on('pageerror', function(err) {
const errorMessage = err.toString();
console.log('browser page error: ', errorMessage)
});
page.goto('https://splinterlands.io/');
page.recoverStatus = 0;
page.favouriteDeck = process.env.FAVOURITE_DECK || '';
while (true) {
console.log('Recover Status: ', page.recoverStatus)
console.log(chalk.bold.redBright.bgBlack('Dont pay scammers!'));
console.log(chalk.bold.whiteBright.bgBlack('If you need support for the bot, join the telegram group https://t.me/splinterlandsbot and discord https://discord.gg/bR6cZDsFSX'));
console.log(chalk.bold.greenBright.bgBlack('If you interested in a higher winning rate with the private API, contact the owner via discord or telegram'));
if(!process.env.API) {
console.log(chalk.bold.redBright.bgBlack('Dont pay scammers!'));
console.log(chalk.bold.whiteBright.bgBlack('If you need support for the bot, join the telegram group https://t.me/splinterlandsbot and discord https://discord.gg/bR6cZDsFSX'));
console.log(chalk.bold.greenBright.bgBlack('If you interested in a higher winning rate with the private API, contact the owner via discord or telegram'));
}
try {
await startBotPlayMatch(page)
.then(() => {
Expand Down

0 comments on commit 6d5e14f

Please sign in to comment.