Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
228 commits
Select commit Hold shift + click to select a range
503334c
Add telegram notification
virgaux Sep 23, 2021
d1b2f22
Minor fix with battle log
virgaux Sep 23, 2021
2f420d5
Add Telegram Instruction
virgaux Sep 23, 2021
1031cda
Update README.md
virgaux Sep 23, 2021
d6aa619
Update README.md
virgaux Sep 24, 2021
4160823
Update .env-example
virgaux Sep 24, 2021
02cf449
Merge branch 'master' of https://github.com/virgaux/ultimate-splinter…
virgaux Sep 24, 2021
2bf4d7d
fix some codes
virgaux Sep 24, 2021
a698301
Minor fix
virgaux Sep 24, 2021
1f2b882
Add updated DEC after battle
virgaux Sep 24, 2021
b5bd8e4
Add installation and minor fix
virgaux Sep 25, 2021
0f5c241
small fix
virgaux Sep 25, 2021
930e80c
Update Install.bat and Index.js
virgaux Sep 25, 2021
e302253
Update README.md
virgaux Sep 25, 2021
aa4923d
Update index.js
virgaux Sep 25, 2021
412b738
Fix Battle errors
virgaux Sep 26, 2021
6522649
Update README.md
virgaux Sep 26, 2021
acd42fb
another fix
virgaux Sep 26, 2021
dd7c67a
fixed quest priority bug
virgaux Sep 27, 2021
0bbf383
Update quests.js
virgaux Sep 27, 2021
d3153d4
Added Features
virgaux Sep 27, 2021
2b99d48
Update index.js
virgaux Sep 27, 2021
be03032
Update newquests.js
virgaux Sep 27, 2021
cd0f5a8
update
virgaux Sep 28, 2021
38ed9b0
Update index.js
virgaux Sep 28, 2021
10a0a91
Update index.js
virgaux Sep 28, 2021
9e6d278
Update index.js
virgaux Sep 29, 2021
e104a1a
update api error
virgaux Sep 29, 2021
14740cd
added feature
virgaux Sep 29, 2021
6a096fa
update api fallback
virgaux Sep 29, 2021
7d520a4
update auto gather
virgaux Sep 30, 2021
48bfef6
Update auto-gather.js
virgaux Sep 30, 2021
403bba0
Update index.js
virgaux Sep 30, 2021
16a7e0e
Update index.js
virgaux Sep 30, 2021
7a1c82e
Update index.js
virgaux Sep 30, 2021
3509299
Update start.bat
virgaux Sep 30, 2021
163795b
fix auto gather toggle error
virgaux Oct 1, 2021
ac82841
fix auto gather toggle
virgaux Oct 1, 2021
1a7afa8
Update index.js
virgaux Oct 1, 2021
f3c8205
Fix auto gather high memory
virgaux Oct 2, 2021
86187c8
Update possibleTeams.js
virgaux Oct 2, 2021
3cece72
Update .env-example
virgaux Oct 3, 2021
4e9024c
Update README.md
virgaux Oct 3, 2021
ec1dfa8
update index.js and auto-gather
virgaux Oct 3, 2021
afc6200
Update auto-gather.js
virgaux Oct 4, 2021
2aad7c9
update telegram command
virgaux Oct 4, 2021
a259d4f
Update package.json
virgaux Oct 4, 2021
435f240
fix telegram bug
virgaux Oct 5, 2021
673a387
Update README.md
virgaux Oct 6, 2021
e57aa77
Update auto-gather.js
virgaux Oct 6, 2021
0773508
Merge branch 'master' of https://github.com/virgaux/ultimate-splinter…
virgaux Oct 6, 2021
075dd02
team selection bug
virgaux Oct 6, 2021
a72ced9
Update collection power and reward logs
virgaux Oct 7, 2021
373ed52
update collection and rewards log
virgaux Oct 7, 2021
92ebb5a
Update .env-example
virgaux Oct 7, 2021
8f3e708
Update index.js
virgaux Oct 7, 2021
6fc4097
Update newquests.js
virgaux Oct 7, 2021
9bc40b4
Update index.js
virgaux Oct 7, 2021
46fd1e5
Update README.md
virgaux Oct 8, 2021
4faafae
Update newquests.js
virgaux Oct 8, 2021
bf918bd
fixed claiming reward bug
virgaux Oct 8, 2021
79fc62d
Update index.js
virgaux Oct 9, 2021
55818bd
Update auto-gather.js
virgaux Oct 9, 2021
ce48dba
Update package-lock.json
virgaux Oct 9, 2021
b97f60c
Update index.js
virgaux Oct 9, 2021
e03e7bd
Update index.js
virgaux Oct 9, 2021
584d1cd
Update index.js
virgaux Oct 9, 2021
0bf2d36
update
virgaux Oct 9, 2021
12a3181
Update install.bat
virgaux Oct 9, 2021
de65028
Update possibleTeams.js
virgaux Oct 9, 2021
0c44fd4
Update README.md
virgaux Oct 9, 2021
77b8e4c
Create history-gather.bat
virgaux Oct 9, 2021
8c2c870
Merge branch 'master' of https://github.com/virgaux/ultimate-splinter…
virgaux Oct 9, 2021
b87ce17
update
virgaux Oct 9, 2021
1fdcd69
fixed tn.sender is not a function bug
virgaux Oct 10, 2021
971b7a8
Update index.js
virgaux Oct 11, 2021
a8d0c20
Update index.js
virgaux Oct 11, 2021
b373a9f
Update index.js
virgaux Oct 11, 2021
d50aac5
Update index.js
virgaux Oct 11, 2021
3ee2b3e
new log display.
virgaux Oct 13, 2021
0b5f89f
Update newquests.js
virgaux Oct 13, 2021
0e10be7
log display
virgaux Oct 13, 2021
f215328
Update auto-gather.js
virgaux Oct 13, 2021
7f842ee
Update index.js
virgaux Oct 13, 2021
76c4d5e
Update index.js
virgaux Oct 13, 2021
72bc128
auto switch
virgaux Oct 13, 2021
74eeb09
Update battlesGetData.js
virgaux Oct 13, 2021
32794af
Update index.js
virgaux Oct 13, 2021
fc957a7
Update index.js
virgaux Oct 13, 2021
3258cf5
Update index.js
virgaux Oct 13, 2021
b183866
Update index.js
virgaux Oct 13, 2021
e380f25
Update newHistory.json
virgaux Oct 13, 2021
6019e32
Update newHistory.json
virgaux Oct 13, 2021
57689f6
Update newHistory.json
virgaux Oct 13, 2021
aa1b18f
replace history manual battle data gather
virgaux Oct 13, 2021
e3aec5e
Update auto-gather.js
virgaux Oct 14, 2021
1bed26d
Update auto-gather.js
virgaux Oct 15, 2021
cfa1cfc
season rewards update
virgaux Oct 16, 2021
7ec0c68
Update telnotif.js
virgaux Oct 16, 2021
5418fee
Update index.js
virgaux Oct 16, 2021
138d0fc
no crash fix
virgaux Oct 17, 2021
ef68133
Update index.js
virgaux Oct 17, 2021
78fdeb8
Update index.js
virgaux Oct 17, 2021
669d19e
Update auto-gather.js
virgaux Oct 17, 2021
64f033b
Update auto-gather.js
virgaux Oct 17, 2021
907e44e
Update auto-gather.js
virgaux Oct 17, 2021
3fb6f3a
minor update
virgaux Oct 18, 2021
db4f4b6
Update auto-gather.js
virgaux Oct 18, 2021
3b9b5ef
Update newHistory.json
virgaux Oct 18, 2021
782101f
Update index.js
virgaux Oct 18, 2021
a7d43e7
Update index.js
virgaux Oct 18, 2021
9139d64
Update index.js
virgaux Oct 18, 2021
74b9ad2
Update index.js
virgaux Oct 19, 2021
3bf64a6
update
virgaux Oct 19, 2021
f52516f
Update auto-gather.js
virgaux Oct 19, 2021
c4cb85c
Update telnotif.js
virgaux Oct 19, 2021
7a15ab3
Update index.js
virgaux Oct 19, 2021
8fb96a7
auto switch update
virgaux Oct 19, 2021
04e629a
Update start.bat
virgaux Oct 19, 2021
4849655
Update newquests.js
virgaux Oct 19, 2021
713d4e2
page error fixed
virgaux Oct 20, 2021
0ba84b5
Update index.js
virgaux Oct 21, 2021
64a354f
priority card added (from yowmama)
virgaux Oct 22, 2021
9e6d344
Update index.js
virgaux Oct 23, 2021
a19765d
fix bug
virgaux Oct 23, 2021
2e41f94
Update index.js
virgaux Oct 23, 2021
df5aacf
Update index.js
virgaux Oct 23, 2021
e031aa9
JS memory limit fixed
virgaux Oct 24, 2021
083803c
file size checker for auto gather
virgaux Oct 24, 2021
8958178
Fix create new browser from error bug
virgaux Oct 24, 2021
a95bc98
instance issue fix
virgaux Oct 24, 2021
d2b1aed
Update index.js
virgaux Oct 26, 2021
9081237
manual- autogather with size limit
virgaux Oct 26, 2021
d3e685d
update sh to bat
virgaux Oct 26, 2021
1f25111
update for faster run
virgaux Oct 26, 2021
b2a0fbd
update
virgaux Oct 26, 2021
e4a2a03
update freezing bug and accurate DEC
virgaux Oct 26, 2021
738ebc2
inaccurate battle result fix
virgaux Oct 27, 2021
2e2a965
Update index.js
virgaux Oct 27, 2021
7e71c42
battledata error fixed
virgaux Oct 27, 2021
a65d959
Update start.bat
virgaux Oct 27, 2021
aae8c95
Update index.js
virgaux Oct 27, 2021
fcaf978
fixed quest reward bug
virgaux Oct 27, 2021
c766d3d
update memory usage for manual - auto gather
virgaux Oct 27, 2021
d333a3c
Update auto-gather.js
virgaux Oct 27, 2021
47ef145
Update .env-example
virgaux Oct 28, 2021
fe84f12
test
virgaux Oct 28, 2021
e0a3e4c
Update index.js
virgaux Oct 28, 2021
219e026
reverting back
virgaux Oct 28, 2021
b907c38
done with testing but revert back to old version
virgaux Oct 28, 2021
b46930f
Update index.js
virgaux Oct 29, 2021
0c3178a
Update index.js
virgaux Oct 29, 2021
9a0a424
season reward fix
virgaux Oct 31, 2021
6755261
fixed quest reward bug and added loading visual
virgaux Nov 1, 2021
17e5539
readline bug fix
virgaux Nov 1, 2021
d1b4be7
readline error fix
virgaux Nov 1, 2021
07220ca
Update index.js
virgaux Nov 1, 2021
40afdc7
Update index.js
virgaux Nov 1, 2021
e6bff81
Update auto-gather.js
virgaux Nov 1, 2021
22adb70
Update quests.js
virgaux Nov 1, 2021
a217655
Update user.js
virgaux Nov 1, 2021
ac07beb
update API
virgaux Nov 1, 2021
c36ae68
fix API call error
virgaux Nov 1, 2021
fc1d3d8
update API call
virgaux Nov 1, 2021
e4fb8b4
update API call error fix
virgaux Nov 1, 2021
366efe1
update
virgaux Nov 1, 2021
ba505bc
ECR accuracy bug fix
virgaux Nov 2, 2021
9286715
Create version.txt
virgaux Nov 2, 2021
d362b88
test
virgaux Nov 2, 2021
9841472
Update index.js
virgaux Nov 2, 2021
24af3c7
update
virgaux Nov 2, 2021
c42ecac
Update package.json
virgaux Nov 2, 2021
5e888fe
Update USBpc-Version.txt
virgaux Nov 3, 2021
584c01c
Update USBpc-Version.txt
virgaux Nov 3, 2021
04cd50d
small update
virgaux Nov 3, 2021
a17e732
Update index.js
virgaux Nov 3, 2021
1a12940
Update package-lock.json
virgaux Nov 3, 2021
8284815
Create USBpc-Version.json
virgaux Nov 3, 2021
59830fb
Update USBpc-Version.json
virgaux Nov 3, 2021
543b4b2
update
virgaux Nov 3, 2021
25fd71e
Update USBpc-Version.json
virgaux Nov 3, 2021
73e98d5
update power threshold
virgaux Nov 3, 2021
a3937f9
Update USBpc-Version.json
virgaux Nov 3, 2021
c709cc9
Update index.js
virgaux Nov 3, 2021
b97ffbd
update
virgaux Nov 3, 2021
81f8892
add back up APIs
virgaux Nov 3, 2021
bed0e21
added back up APis
virgaux Nov 3, 2021
00d4df3
Fixed API call response and ECR bug
virgaux Nov 3, 2021
d5a7633
fix bug
virgaux Nov 3, 2021
9a66d7c
update
virgaux Nov 3, 2021
ff12167
fix
virgaux Nov 3, 2021
9ef3c32
update
virgaux Nov 4, 2021
a2e0979
Update index.js
virgaux Nov 4, 2021
15425ba
update
virgaux Nov 8, 2021
c6d65b9
update Public API error.
virgaux Nov 10, 2021
1369ada
update API for card collection
virgaux Nov 23, 2021
44a5325
Update auto-gather.js
virgaux Nov 25, 2021
64063a2
update card details
virgaux Dec 8, 2021
59466ce
Update basicCards.js
virgaux Dec 8, 2021
1404905
Update package.json
virgaux Dec 9, 2021
ff5885a
update package
virgaux Dec 9, 2021
5f6947b
Update possibleTeams.js
virgaux Dec 26, 2021
42ba525
fix can't login error
virgaux Jan 8, 2022
d658976
fix can't log in error
virgaux Jan 8, 2022
faaebea
fix can't login error and make login time instant.
virgaux Jan 8, 2022
5aaecc3
fixed unable to login error
virgaux Jan 8, 2022
b6fc296
Update index.js
virgaux Jan 8, 2022
0099547
update for the fix for can't login
virgaux Jan 8, 2022
a54c2fb
Update splinterlandsPage.js
virgaux Jan 9, 2022
37a8e87
update
virgaux Jan 11, 2022
000e568
Update index.js
virgaux Jan 11, 2022
927c200
Update USBpc-Version.json
virgaux Jan 11, 2022
795ea97
minor update
virgaux Jan 12, 2022
767d264
Update splinterlandsPage.js
virgaux Jan 12, 2022
ca697c7
minor update
virgaux Jan 12, 2022
c248f94
update
virgaux Jan 13, 2022
aeaf0a5
Update index.js
virgaux Jan 13, 2022
0700b24
Update api.js
virgaux Jan 13, 2022
3815521
fixed claim reward error
virgaux Jan 16, 2022
f484586
Update cardsDetails.json
virgaux Jan 18, 2022
f158f97
Update install.bat
virgaux Jan 21, 2022
79b1276
Update cardsDetails.json
virgaux Jan 21, 2022
5844c3b
Update index.js
virgaux Jan 21, 2022
58aba0e
Update splinterlandsPage.js
virgaux Jan 22, 2022
7e94774
fixed ongoing login error.
virgaux Jan 23, 2022
07500ce
Update index.js
virgaux Jan 29, 2022
2d79de8
update for no mana error
virgaux Apr 26, 2022
e0acc23
Delete package-lock.json
virgaux Apr 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
QUEST_PRIORITY=true
MINUTES_BATTLES_INTERVAL=30
ERC_THRESHOLD=80
POWER_THRESHOLD=1000
SWITCH_THRESHOLD=50
CLAIM_SEASON_REWARD=false
CLAIM_QUEST_REWARD=true
HEADLESS=true
KEEP_BROWSER_OPEN=true
CHROME_NO_SANDBOX=true
LOGIN_VIA_EMAIL=false
GET_DATA_FOR_LOCAL=true
AUTO_SWITCH=false
EMAIL=account1@email.com,account2@email.com,account3@email.com
ACCUSERNAME=username1,username2,username3
PASSWORD=password1,password2,password3
PRIORITY_CARD=
USE_API=true
API_URL=http://splinterlandsapi.pcjones.de:8080/
USE_CLASSIC_BOT_PRIVATE_API=false
API_URL=http://splinterlandsapi2.pcjones.de:8080/
API_URL_FALLBACK=http://splinterlandsapi.pcjones.de:8080/
USE_CLASSIC_BOT_PRIVATE_API=false
TELEGRAM_NOTIF=false
TELEGRAM_TOKEN=
TELEGRAM_CHATID=
44 changes: 34 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Ultimate Splinterlands Bot by PC Jones
# Ultimate Splinterlands Bot V1 (Modified version)
A fast, free, multi-account splinderlands bot

Based on https://github.com/alfficcadenti/splinterlands-bot
Based on https://github.com/PCJones/ultimate-splinterlands-bot

## Preamble
Right now the code is a mess - I just hacked something together so I can release this asap. I'm planning on updating the code soon.
Expand All @@ -17,12 +17,17 @@ Feel free to give suggestions for features/code refurbishing via github or on di
- The bot no longer refreshes the page all the time (which often got you blocked from splinterlands for a few minutes)
- The bot clicks away popups
- The bot waits if there is a loading circle from splinterlands
- Minimum Energy Capture Rate - the bot will pause automatically if the energy capture rate is below a specified percentage
- Disabled requesting the free API because it is always overloaded and slows down the bot (I've supplied a very large history file)
- Option to disable automatic quest reward chest opening
- Support for the private API of the original bot
- **Coming Soon**: Individual wait time for each account (right now it will battle with all accounts and wait after that) (aka **Multithreading**)
- **Coming Soon**:
- **Coming Soon**: Statistics on how each account is performing
- Minimum Energy Capture Rate - the bot will pause automatically if the energy capture rate is below a specified percentage
- New battle log summary after all battles
- New DEC log after battle.
- Receive Battle log summary notification via Telegram
- **Updated Feature**: Accurate battle summary
- **Updated Feature**: Power Threshold and claimed reward log
- **Updated Feature**: Auto gather the battle history for local back.(In case supported API is down)
- **Coming Soon**: Telegram notification if bot had an error/stop running. Call to function on telegram. (virgaux)
- Any suggestions?

# Support / Community
Expand All @@ -34,10 +39,10 @@ https://discord.gg/hwSr7KNGs9)

## How to install
- Download and install [NodeJs](https://nodejs.org/it/download/)
- Download the [bot](https://github.com/PCJones/ultimate-splinterlands-bot/archive/refs/heads/master.zip) (extract if its .zip)
- Download the [bot](https://github.com/virgaux/ultimate-splinterlands-bot/archive/refs/heads/master.zip) (extract if its .zip)
- Create .env file (see .env-example)
- On windows: Execute `install.bat` in bot folder
- On MacOS/Linux: open terminal in bot folder and execute command `npm install`
- On MacOS/Linux: open terminal in bot folder and execute command `npm install`

## How to start the bot
- On windows: Execute `start.bat` in bot folder
Expand All @@ -51,7 +56,11 @@ Configuration with default values:

- `MINUTES_BATTLES_INTERVAL=30` Sleep time before the bot will fight with all accounts again. Subtract 2-3 minutes per account

- `ERC_THRESHOLD=80` If your energy capture rate goes below this the bot will stop fighting with this account until it's above again. Set to 0 to disable
- `ERC_THRESHOLD=80` If your energy capture rate goes below this the bot will stop fighting with this account until it's above again. Set to 0 to disable

- `ERC_REGEN=true` Disable/Enable ERC regeneration function.

- `ERC_REGEN_LIMIT=100` If your energy capture rate is not yet above this, the bot will not fight with this account until it's reach the pre-set parameter.

- `CLAIM_SEASON_REWARD=false` Disable/Enable season reward claiming

Expand All @@ -75,15 +84,25 @@ Configuration with default values:

- `USE_CLASSIC_BOT_PRIVATE_API=false` Set to false unless you have the private API from the original bot

- `TELEGRAM_NOTIF=false` Disable/Enable to receive telegram notification for battle result.

- `TELEGRAM_TOKEN=` API TOKEN from telegram which will send you the notification. This is private key. DO NOT GIVE IT TO ANYONE. [how to get telegram token](https://www.siteguarding.com/en/how-to-get-telegram-bot-api-token)

- `TELEGRAM_CHATID` telegram chat id for notify, get the id: https://t.me/get_id_bot

# Donations

In case you want to donate to me for updating this bot, I would be very happy! Please also consider donating to the original bot creator.

- DEC into the game to the player **pcjones**
- DEC into the game to the player **pcjones** or **virgaux**
- Bitcoin 3KU85k1HFTqCC4geQz3XUFk84R6uekuzD8
- Ethereum 0xcFE8c78F07e0190EBdD9077cF9d9E3A8DCED8d91
- WAX to account **lshru.wam** (please copy the name)
- Text me on Discord or Telegram for anything other
- or
- DEC into the game to the player **virgaux**
- Metamask wallet address: 0x6b11890566077AAC2B7fA7511d484f50Ec1335f6
- Hive wallet address: @virgaux

# FAQ
**Can I have some accounts that login via email and some via username?**
Expand All @@ -106,3 +125,8 @@ PASSWORD=password1,password2,POST_KEY3

1. Backup newHistory.json in case something goes wrong
2. Run `node combine.js` in the data folder to add the data from history.json to the newHistory.json file

**Why I can't see the Telegram notification after setting it up?**

1. Look for the name of your bot in Telegram.
2. Type `/start` to receive notifcation once battle summary result is available.
8 changes: 8 additions & 0 deletions USBpc-Version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Version": 11.25,
"Fixes": "fixed ongoing login error.",
"Update":"LostVoid Private API ready. Added code for API fallback.",
"New_feature": "Paid Version is on development with more feature. Message Virgaux for details.",
"Instuction" : "No need to npm install again. Just git pull or replace the updated files"

}
1 change: 1 addition & 0 deletions USBpc-Version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11.25
45 changes: 31 additions & 14 deletions api.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
const fetch = require('node-fetch');
const fetch = require('cross-fetch');
const fs = require('fs');
const readline = require('readline');
const chalk = require('chalk');

async function tempLog(log) {
fs.appendFile('log.txt', log + '\n', function (err) {
//console.log('LogError', log);
});
}
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

async function getPossibleTeams(matchDetails) {
try {
const response = await fetch(process.env.API_URL + 'get_team/', {
method: 'post',
body: JSON.stringify(matchDetails),
headers: {'Content-Type': 'application/json'}
});

var dataRaw = await response.text();

async function response (matchDetails,api){
const response = await fetch(api + 'get_team/', {
method: 'post',
body: JSON.stringify(matchDetails),
headers: {'Content-Type': 'application/json'}
});
return response.text()
}

async function getPossibleTeams(matchDetails,api) {
try {
let dataRaw = await response(matchDetails,api);
if (process.env.DEBUG === 'true') {
tempLog('--------------------------------------------------------');
tempLog(JSON.stringify(matchDetails));
tempLog('response:');
tempLog(dataRaw);
tempLog('--------------------------------------------------------');
}

const data = JSON.parse(dataRaw);

let apiResponseCounter = 0;
while (JSON.stringify(dataRaw).includes('hash')) {
readline.cursorTo(process.stdout, 0);
console.log(chalk.yellow(' Waiting 30 seconds for API to calculate team...'));
await sleep(30000);
dataRaw = await response(matchDetails,api);
if (++apiResponseCounter >= 4) break;
}

const data = JSON.parse(dataRaw);

return data;
} catch(e) {
console.log('API Error', e);
Expand Down
153 changes: 153 additions & 0 deletions auto-gather.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
require('dotenv').config()
const fetch = require("async-get-json");
const fs = require('fs');
const misc = require('./misc');
const chalk = require('chalk');
const readline = require('readline');





const distinct = (value, index, self) => {
return self.indexOf(value) === index;
}
function uniqueListByKey(arr, key) {
return [...new Map(arr.map(item => [item[key], item])).values()]
}

function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
async function getBattleHistory(player = '', data = {}) {
await sleep(5000);
const battleHistory = await fetch(`http://game-api.splinterlands.io/battle/history?player=` + player)
.then(b=>b.battles)
.catch(async ()=> {
readline.cursorTo(process.stdout, 0);
console.log('Fetch error. using API.spliterlands.')
await fetch(`http://api.splinterlands.io/battle/history?player=` + player)
.then(b=>b.battles)
.catch(async ()=> {
readline.cursorTo(process.stdout, 0);
console.log('Fetch error. using steemmonstes API.')
await fetch(`http://api.steemmonsters.io/battle/history?player=` + player)
.then(b=>b.battles)
.catch(async ()=> {
readline.cursorTo(process.stdout, 0);
console.log('Fetch error. using API2.')
await fetch(`http://api2.splinterlands.com/battle/history?player=` + player)
.then(b=>b.battles)
.catch(async () => {
readline.cursorTo(process.stdout, 0);
console.log('There has been a problem with your fetch operation:', error);
return [];
})
})
})
});
return await battleHistory;
}


const extractGeneralInfo = (x) => {
return {
mana_cap: x.mana_cap ? x.mana_cap : '',
ruleset: x.ruleset ? x.ruleset : '',
}
}

const extractMonster = (team) => {
const monster1 = team.monsters[0];
const monster2 = team.monsters[1];
const monster3 = team.monsters[2];
const monster4 = team.monsters[3];
const monster5 = team.monsters[4];
const monster6 = team.monsters[5];

return {
summoner_id: team.summoner.card_detail_id,
monster_1_id: monster1 ? monster1.card_detail_id : '',
monster_2_id: monster2 ? monster2.card_detail_id : '',
monster_3_id: monster3 ? monster3.card_detail_id : '',
monster_4_id: monster4 ? monster4.card_detail_id : '',
monster_5_id: monster5 ? monster5.card_detail_id : '',
monster_6_id: monster6 ? monster6.card_detail_id : '',
}
}

let battlesList = [];
let promises = [];

const battles = async (player) => await getBattleHistory(player)
.then(u => u.map(x => {
return [x.player_1, x.player_2]
}).reduce((acc, val) => acc.concat(val), []).filter(distinct))
.then(ul => ul.map(user => {
promises.push(
getBattleHistory(user)
.then(battles => battles.map(
battle => {
const details = JSON.parse(battle.details);
if (details.type != 'Surrender') {
if (battle.winner && battle.winner == battle.player_1) {
const monstersDetails = extractMonster(details.team1)
const info = extractGeneralInfo(battle)
return {
...monstersDetails,
...info,
battle_queue_id: battle.battle_queue_id_1,
//winner: battle.player_1,
//verdict: (winner && winner == battle.player_1)?'w':(winner == 'DRAW')? 'd' :'l',
}
} else if (battle.winner && battle.winner == battle.player_2) {
const monstersDetails = extractMonster(details.team2)
const info = extractGeneralInfo(battle)
return {
...monstersDetails,
...info,
battle_queue_id: battle.battle_queue_id_2,
//winner: battle.player_2,
//verdict: (winner && winner == battle.player_2)?'w':(winner == 'DRAW')? 'd' :'l',
}
}
}
})
)
.then(x => battlesList = [...battlesList, ...x])
)
}))
.then(() => { return Promise.all(promises) })
.then(() => { return new Promise((res,rej) => {
//twirlTimer();
readline.cursorTo(process.stdout, 0);
console.log('Reading local battle history');
fs.readFile(`./data/newHistory.json`, 'utf8', (err, data) => {
if (err) {
readline.cursorTo(process.stdout, 0);
misc.writeToLog(`Error reading file from disk: ${err}`); rej(err)
} else {
battlesList = data ? [...battlesList, ...JSON.parse(data)] : battlesList;
}
battlesList = uniqueListByKey(battlesList.filter(x => x != undefined),"battle_queue_id")
readline.cursorTo(process.stdout, 0);
misc.writeToLog('Adding data to battle history....');
readline.cursorTo(process.stdout, 0);
misc.writeToLog(chalk.yellow(battlesList.length))
fs.writeFile(`data/newHistory.json`, JSON.stringify(battlesList), function (err) {
if (err) {
misc.writeToLog(err,'a'); rej(err);
}
readline.cursorTo(process.stdout, 0);
misc.writeToLog(chalk.green('Success adding data.....'));
battlesList = [],
promises = [];
});
res(battlesList)
});
}) })


exports.battlesList = battles;
10 changes: 10 additions & 0 deletions autogather-manual/.env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MINUTES_GATHER_INTERVAL=10
#account name shouldn't have any spaces. ex: username1,username2
ACCOUNT=
#max size is 499999KB
SIZE_LIMIT=
#file name should end with .json ex: data.json
FILE_NAME=



Loading