Last active
April 5, 2021 08:41
-
-
Save rafalwojcik/c47dbcfe1357225dd2209c86ae06246e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sleep(ms = 5000) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
function stripHTML(html) { | |
return html.replace(/(<([^>]+)>)/gi, ""); | |
} | |
function clickOnAction(actionSelector) { | |
var buttons = document.querySelectorAll(actionSelector); | |
if (buttons.length != 0) { | |
buttons.item(buttons.length - 1).click(); | |
} | |
} | |
async function runAction(action_id) { | |
console.log(`💩 ${action_id}`) | |
clickOnAction(`[data-qa-action-id='tower-${action_id}']`); | |
await sleep(); | |
clickOnAction(`[data-qa-action-id='tower-startround']`); | |
await sleep(); | |
} | |
async function hide() { | |
await runAction("hide"); | |
} | |
async function searchForWeapons() { | |
await runAction("searchforweapons"); | |
} | |
async function searchForHealth() { | |
await runAction("searchforhealth"); | |
} | |
async function healMe() { | |
await runAction("reviveself"); | |
} | |
async function progress() { | |
clickOnAction(`[data-qa-action-id='tower-progress']`); | |
await sleep(); | |
} | |
function getHealthValue() { | |
var progressHTML = document.querySelectorAll('[data-qa="message_pane"] [data-qa="slack_kit_list"]')[0].innerHTML; | |
var healthStatus = stripHTML(progressHTML).match(/\(\s\d{1,3}\s\/\s100\s\)/g); | |
var healthValue = parseInt(healthStatus[healthStatus.length - 1].match(/\d{1,3}/)); | |
console.log(`💩 Health: ${healthValue}/100`); | |
return healthValue; | |
} | |
async function healIfNeeded(healthValue) { | |
if (healthValue <= 65) { | |
await hide(); | |
await healMe(); | |
} | |
return getHealthValue(); | |
} | |
async function botForWeapons(max = 1000) { | |
for (i=0;i<max;i++) { | |
console.log(`💩 Iteration: ${i}`); | |
if (i % 5) { | |
await progress(); | |
} | |
await searchForWeapons(); | |
await healMeBot(); | |
console.error | |
} | |
} | |
async function healMeBot() { | |
var healthValue = 0; | |
do { | |
await searchForHealth(); | |
healthValue = await getHealthValue(); | |
healthValue = await healIfNeeded(healthValue); | |
} while (healthValue <= 65); | |
} | |
// healMeBot(); | |
botForWeapons(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment