Skip to content

Instantly share code, notes, and snippets.

@oak-ib
Forked from pich4ya/alienworlds_bot.js
Last active June 9, 2021 06:10
Show Gist options
  • Save oak-ib/e3f17d4a90edc970c5a14f73f2aff644 to your computer and use it in GitHub Desktop.
Save oak-ib/e3f17d4a90edc970c5a14f73f2aff644 to your computer and use it in GitHub Desktop.
const delay = (millis) =>
new Promise((resolve, reject) => {
setTimeout((_) => resolve(), millis);
});
async function postData(url = '', data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(data) // body data type must match "Content-Type" header
});
return response.json(); // parses JSON response into native JavaScript objects
}
const checkCPU = async (userAccount) => {
let result = true;
while(result){
try {
const accountDetail = await postData('https://api.waxsweden.org/v1/chain/get_account', { account_name: userAccount })
if(accountDetail.cpu_limit != null){
const rawPercent = ((accountDetail.cpu_limit.used/accountDetail.cpu_limit.max)*100).toFixed(2)
console.log(`%c[Bot] rawPercent : ${rawPercent}%`, 'color:green')
console.log(`%c[Bot] cpu_limit max:${accountDetail.cpu_limit.max} use:${accountDetail.cpu_limit.used} = ${accountDetail.cpu_limit.max - accountDetail.cpu_limit.used}`, 'color:green')
if(rawPercent < 85){
result = false;
}
}
}catch (err) {
console.log(err.message);
result = false;
}
if(result){
const delayCheckCpu = 120000 + Math.floor(Math.random() * 30001)
console.log(`%c[Bot] delay ${(delayCheckCpu/1000/60)} min check cpu again`, 'color:green')
await delay(delayCheckCpu);
}
}
}
const userAccount = await wax.login();
unityInstance.SendMessage(
"Controller",
"Server_Response_LoginData",
userAccount
);
await delay(2000);
console.log("bot StartBot");
let checkMinedelay = false
while (true) {
let firstMine = true;
let previousMineDone = false;
let minedelay = 1;
do {
minedelay = await getMineDelay(userAccount);
// if(checkMinedelay){
// minedelay = 810000;
// }
console.log(`%c[Bot] Cooldown for ${Math.ceil((minedelay / 1000)/60)} min`, 'color:green');
await delay(minedelay + Math.floor(1000 + (Math.random() * 9000)));
minedelay = 0;
console.log("bot checkCPU");
await checkCPU(userAccount);
} while (minedelay !== 0 && (previousMineDone || firstMine));
const balance = await getBalance(userAccount, wax.api.rpc);
console.log(`%c[Bot] balance: (before mine) ${balance}`, 'color:green');
const mine_work = await background_mine(userAccount);
unityInstance.SendMessage(
"Controller",
"Server_Response_Mine",
JSON.stringify(mine_work)
);
const mine_data = {
miner: mine_work.account,
nonce: mine_work.rand_str,
};
console.log(`%c[Bot]mine data `,mine_data, 'color:green');
const actions = [
{
account: mining_account,
name: "mine",
authorization: [
{
actor: mine_work.account,
permission: "active",
},
],
data: mine_data,
},
];
try {
console.log("bot checkCPU");
await checkCPU(userAccount);
const audio = new Audio('https://media.geeksforgeeks.org/wp-content/uploads/20190531135120/beep.mp3');
audio.play();
const result = await wax.api.transact(
{
actions,
},
{
blocksBehind: 3,
expireSeconds: 360,
}
);
console.log(`%c[Bot] result is = ${result}`, 'color:green');
var amounts = new Map();
if (result && result.processed) {
result.processed.action_traces[0].inline_traces.forEach((t) => {
if (t.act.data.quantity) {
const mine_amount = t.act.data.quantity;
console.log(`%c[Bot] ${mine_work.account} Mined ${mine_amount}`, 'color:green');
if (amounts.has(t.act.data.to)) {
let obStr = amounts.get(t.act.data.to);
obStr = obStr.substring(0, obStr.length - 4);
let nbStr = t.act.data.quantity;
nbStr = nbStr.substring(0, nbStr.length - 4);
let balance = (parseFloat(obStr) + parseFloat(nbStr)).toFixed(4);
amounts.set(t.act.data.to, balance.toString() + " TLM");
} else {
amounts.set(t.act.data.to, t.act.data.quantity);
}
}
});
unityInstance.SendMessage(
"Controller",
"Server_Response_Claim",
amounts.get(mine_work.account)
);
firstMine = false;
previousMineDone = true;
checkMinedelay = true;
}
} catch (err) {
unityInstance.SendMessage(
"ErrorHandler",
"Server_Response_SetErrorData",
err.message
);
previousMineDone = false;
checkMinedelay = false;
console.log(`%c[Bot] Error`, 'color:red');
}
const afterMindedBalance = await getBalance(userAccount, wax.api.rpc);
const now = (new Date());
console.log(`%c[Bot] balance (after mined): ${afterMindedBalance}`, 'color:green');
console.log(`%c[Bot] Time : ${now}`, 'color:green');
}
@Darklightsite
Copy link

I have a error. Fetch error. Can help me?

@Darklightsite
Copy link

Can you make a auto mine clicking script to AWHelper.com?

@oak-ib
Copy link
Author

oak-ib commented May 22, 2021

Can you make a auto mine clicking script to AWHelper.com?

https://github.com/zokemoke/alien-worlds-bot
http://alien-worlds-bot.vercel.app/

@Darklightsite
Copy link

Can you make a auto mine clicking script to AWHelper.com?

https://github.com/zokemoke/alien-worlds-bot
http://alien-worlds-bot.vercel.app/

IMG_20210522_164848

@oak-ib
Copy link
Author

oak-ib commented May 23, 2021

Can you make a auto mine clicking script to AWHelper.com?

https://github.com/zokemoke/alien-worlds-bot
http://alien-worlds-bot.vercel.app/

IMG_20210522_164848

Timer=0 get cooldown time by game server

@mynameismaxz
Copy link

Can you make a auto mine clicking script to AWHelper.com?

https://github.com/zokemoke/alien-worlds-bot
http://alien-worlds-bot.vercel.app/

IMG_20210522_164848

Timer=0 get cooldown time by game server

When I set the timer to 0 (zero) it's getting loop in 1 min to mining again. I cannot see the "CheckDelay" button on this website.

@lostsomeone
Copy link

image

@lostsomeone
Copy link

what is line token

@oak-ib
Copy link
Author

oak-ib commented May 24, 2021

what is line token
notify error message to line app https://notify-bot.line.me/

@oak-ib
Copy link
Author

oak-ib commented May 24, 2021

CheckDelay

CheckDelay not work & timer=0 auto check mining time to server not work server wax return time mining zero alway.
I recommend manual timer work and first start check mining time ready to mine ,error : mine to soon loop mine
189660720_5873060689378277_7051593649577527761_n

@oak-ib
Copy link
Author

oak-ib commented May 29, 2021

Hello! Very like ur script bro, can u help me every 2 hours i get disconnect with that error and cannot fix it :(
chrome_yI5UoAnbeV
change ip address

  • restart router
  • VPN
  • ip release

or change api wax domain file message_handler.js => https://api.waxsweden.org change to https://wax.pink.gg
or bot -> http://alien-worlds-bot.vercel.app/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment