Forked an application for the first time

in STEMGeeks4 years ago (edited)

I have been using a bot designed by someone else to play my extra Splinterlands cards. The application the bot uses had some issues upon first use and since then I have made a few changes to the scripts to make it run better on my virtual machines. And figured it would be a good idea to make my own fork of the application.

My first change was made to the package.json file. When I tried to run the application for the first time I got a package conflict error, upon opening up the file in a text editor I saw the following near the bottom.

`<<<<<<< HEAD
"puppeteer": "^2.1.1"
=======
"puppeteer": "^2.1.1",
"minimist": ">=1.2.3"
>>>>>>> ad56a3a8c469f49ccb88a7656245efe54ae43f9e`

I believe having two puppeteer entries was causing this error, so I removed one and the other invalid json in that file. Below is now how the package.json file looks. Puppeteer uses Chromium to launch an automated session in the browser, it can reload pages, enter login info and click through the menus.

`{
"name": "Solo's fork of splinter-scraper",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"dimas-kmeans": "^1.0.3",
"dotenv": "^8.2.0",
"hierarchical-clustering": "^1.1.0",
"minimist": ">=0.2.1",
"node-cron": "^2.0.3",
"node-fetch": "^2.6.0",
"pg": "^8.0.3",
"puppeteer": "^2.1.1"
  } 
}`

Now when I run the script it no longer gets a package conflict, and I added my name to the fork along with changing the version to 1.0.1

I made the readme more clear, and added how you can add an .env file to the working directory of the script instead of having to use a global environmental variable file. Since I am running multiple accounts I find this a needed addition.

This is a fork of alfficcadenti's BOT to play the game Splinterlands

Changes have been made to resolve package conflicts, and to resolve script time outs/stops

index.js
run npm start index.js

to start BOT login routine. username and password needs to be specified in the file .env as variable like:                       
ACCOUNT=yourhiveusername PASSWORD=yourhiveprivatepostingkey Create .env text file with the above in the working directory of the             
splinterlands bot and add .env text file to .gitignore

https://peakd.com/hive-13323/@solominer/set-up-my-own-splinterlands-bots

Next up was changes to the index.js file. Right now I am running this bot on a virtual machine, and it does not make use of my graphics card for rendering. So alot of CPU is used instead, this is causing the rendering of the website to take longer. Also seems the popup windows have changed since alfficcadenti's last changes to the script. So I needed to add another set of puppeteer commands to get it working.

    await page.reload();
    await page.waitFor(5000)

Now it does reloads the page three times and waits 5 seconds each time. Without this recently I found the script to stop working. I guess the lands popup is now gone and affecting the script.

As I mentioned my virtual machine runs a little slower than it would on a bare metal machine, I had to adjust the await page.waitfor command. It was set to 3 seconds which I saw the script timing out when my virtual machine could not keep up.

So I added a zero making it wait 30 seconds, more than enough time now for the rendering on the website to catch up. Now it looks like below.

await page.waitFor(30000);

I made some other changes, but found them not working as well as what was set up originally, so I reverted back to what alfficcadenti's defaults were. An example of this was the cron job timing for each battle. It was set to 14 minutes between battles and I found this to be too long. But after battling at 7 minutes for a season I started to get login denies from the Spinterlands.com stating my API calls are too frequent.

cron.schedule('*/15 * * * *', async () => {

I now run 5 of the bots using PM2, a process monitor I have in Ubuntu. I have tried getting this setup to run on my RaspberryPi4 but the ARM build of puppeteer and Chromium seem to have some issues getting it to work. The browser is failing to launch sometimes, so I need to do more research on that to get it running. If I can get it working ill do another fork of alfficcadenti's app just for ARM use.

Still some issues to iron out, such as some battles are aborted due to an error saying there are no teams available for battle. Seems to happen when new rulesets are encountered the and script does not know what to do. It also seems to have issues with calls to herokuapp, stating invalid json sometimes. Maybe the new rulesets need to be added into the script.

Feels good I was able to fix and do some improvements on the script that someone else made. Since it has not been updated since October of last year it was due for a couple changes and glad I was able to do it. Now I have my own github account and forked my first application, with the more and more scripting I do. I can see more forks happening in the future as well.

You can find a link to my fork below:

https://github.com/solominer0/splinterlands-bot

Posted with STEMGeeks

Sort:  

thanks for the post and sharing the original guys work. I took his code and got it to work for me, but as you mentioned he is missing teams for the new rulesets and his logic on team selection could be a bit better. Was also thinking you need to update a bunch of his data tables with your cards and the new ones that have since been added. I'm going to be working on utilizing the SDK published by splinterlands to change the code around. Will share when I get somewhere!

Thanks for checking it out, yeah seems a little outdated. I believe the logic is in a database that the app queries. Ill have to see if I can wrap my head around it.

Best of luck making changes, happy to add them to my fork if you want. Or you can start your own.

yeah I thought the same that he stored the logic in a database, After I have a list of card combos that works for my card set, I'm going to override his logic (still trying to decipher most of what he did). The better option would probably be to start using the splinterlands sdk and their pre built commands. https://github.com/steem-monsters/splinterlands-js

Ah okay, Ill take a look at the SDK and see if I can incorporate it into the bot.

Loading...

Good job with your fixes! I'm more of a dCity's girl, however, I forked your repo so maybe I could put my Splinterlands cards to work for me. 😉

Edit #1: I don't know if I'm doing something wrong, but could you give me a hand, please. The process gets stuck at the start and it stays like the image and won't progress.

VirtualBox_Ubuntu20_29_01_2021_10_42_45.png

Edit #2: It actually worked, just took a little while (~5 minutes just to start and open chromium). Maybe my machine sucks. 😅

nope this bot takes forever to process as written (no clue why), but at least it works!

Ah glad you got it working, theres a 14 minute cron job delay in the script. So it can take up to 14 minutes to run sometimes. I tried reducing this number, but Splinterlands.com was rejecting my logins when trying to play too often with my bots.

Cool you play dCity, I know alot of people that play that. But all my free time is tied up in Splinterlands.

Haha yah!

You are a coding dynamo now! Must be great to be able to troubleshoot and customize a solution so granular.

Has using the bot increased your success/stake in Splinterlands?

Hehe I have alot to learn, so for now I am just copying others apps and making small changes. Yeah it was a little daunting at first, but just taking my time reading it line by line it mostly makes sense whats happening.

Yes! I have made about half my money back in just 1 season of playing. My up front costs were 5x spell books so it cost me around $50 for 5 bots to get started. I found a lvl 2 gold fire spitter in one of my rewards. And another got over 10k DEC for the season rewards. So seems ill be in profit in the next month or so. The bots usually get up into Bronze I or Silver III. But my Solominer account I play usually gets somewhere into Gold.