forked from alfficcadenti/splinterlands-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splinterlandsPage.js
61 lines (53 loc) · 2.63 KB
/
splinterlandsPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
async function login(page) {
try {
page.waitForSelector('#log_in_button > button').then(() => page.click('#log_in_button > button'))
await page.waitForSelector('#email')
.then(() => page.waitForTimeout(3000))
.then(() => page.focus('#email'))
.then(() => page.type('#email', process.env.ACCOUNT))
.then(() => page.focus('#password'))
.then(() => page.type('#password', process.env.PASSWORD))
// .then(() => page.waitForSelector('#login_dialog_v2 > div > div > div.modal-body > div > div > form > div > div.col-sm-offset-1 > button', { visible: true }).then(() => page.click('#login_dialog_v2 > div > div > div.modal-body > div > div > form > div > div.col-sm-offset-1 > button')))
.then(() => page.keyboard.press('Enter'))
.then(() => page.waitForTimeout(5000))
.then(() => page.reload())
.then(() => page.waitForTimeout(3000))
} catch (e) {
console.log('login error', e);
}
}
async function checkMana(page) {
var manas = await page.evaluate(() => {
var manaCap = document.querySelectorAll('div.mana-total > span.mana-cap')[0].innerText;
var manaUsed = document.querySelectorAll('div.mana-total > span.mana-used')[0].innerText;
var manaLeft = manaCap - manaUsed
return { manaCap, manaUsed, manaLeft };
});
console.log('manaLimit', manas);
return manas;
}
async function checkMatchMana(page) {
const mana = await page.$$eval("div.col-md-12 > div.mana-cap__icon", el => el.map(x => x.getAttribute("data-original-title")));
const manaValue = parseInt(mana[0].split(':')[1], 10);
console.log(manaValue);
return manaValue;
}
async function checkMatchRules(page) {
const rules = await page.$$eval("div.combat__rules > div.row > div> img", el => el.map(x => x.getAttribute("data-original-title")));
return rules.map(x => x.split(':')[0]).join('|')
}
async function checkMatchActiveSplinters(page) {
const splinterUrls = await page.$$eval("div.col-sm-4 > img", el => el.map(x => x.getAttribute("src")));
return splinterUrls.map(splinter => splinterIsActive(splinter)).filter(x => x);
}
//UNUSED ?
const splinterIsActive = (splinterUrl) => {
const splinter = splinterUrl.split('/').slice(-1)[0].replace('.svg', '').replace('icon_splinter_', '');
return splinter.indexOf('inactive') === -1 ? splinter : '';
}
exports.login = login;
exports.checkMana = checkMana;
exports.checkMatchMana = checkMatchMana;
exports.checkMatchRules = checkMatchRules;
exports.checkMatchActiveSplinters = checkMatchActiveSplinters;
exports.splinterIsActive = splinterIsActive;