Browse Source

hz log

master
gsd 1 year ago
parent
commit
0909d302a7
  1. 172
      tradebot.js

172
tradebot.js

@ -5,126 +5,134 @@ var trade_checker_imp = require("./trade_checker")
var backend = new backend_integration();
var trade_checker = new trade_checker_imp();
const VERSION = require("./version");
console.log(`Build date: ${VERSION}`);
var SteamTradeOfferManager = require('steam-tradeoffer-manager');
async function sync(timeout) {
console.log(`Build date: ${VERSION}`);
let sleep = function sleep (howLong) {
return new Promise(function (resolve) {
setTimeout(() => {resolve()}, howLong)
})
}
var steam_client;
while (true) {
try {
await backend.pulse().then(() => {
await backend.pulse().then(async () => {
if (backend.up) {
backend.getPrices(trade_checker);
if (steam_client === undefined) {
console.log("Setup Steam Client...")
steam_client = setupClient();
}
} else {
console.log(`wait ${timeout} seconds after destroy, where pulse failed`);
await sleep(timeout * 1000);
if (!backend.up) {
process.exit(228);
}
}
});
} catch (e) {
console.log(e);
} finally {
if (!backend.up) {console.log(`wait ${timeout} seconds after destroy, where pulse failed`)}
await sleep(timeout * 1000);
if (!backend.up) {process.exit(228);}
}
}
}
sync(60);
/////////////////////////////////////////////////////////////////
var SteamUser = require('steam-user');
var SteamCommunity = require('steamcommunity');
var SteamTradeOfferManager = require('steam-tradeoffer-manager');
var SteamTOTP = require('steam-totp');
/////////////////////////////////////////////////////////////////
var client = new SteamUser();
var community = new SteamCommunity();
var manager = new SteamTradeOfferManager({
steam: client,
language: 'en'
});
console.log('connecting to steam account...');
const config = require("./auth_data/auth.json")
client.logOn({
accountName: config.login,
password: config.password,
twoFactorCode: SteamTOTP.getAuthCode(config.shared_secret)
});
/////////////////////////////////////////////////////////////////
client.on('loggedOn', function(details, parental) {
console.log('SteamID64 :', client.steamID.getSteamID64());
client.setPersona(SteamUser.EPersonaState.Online);
});
client.on('webSession', function(sessionID, cookies) {
manager.setCookies(cookies, function(err) {
if (err) {
console.log(err);
process.exit(1); // Fatal error since we couldn't get our API key
return;
}
console.log("Web session created!");
});
community.setCookies(cookies);
});
client.on('error', function(error) {
console.log('connection error\n');
console.log(error);
});
////////////////////////////////////////////////////////////////////
function calculate(offer) {
if (offer.state !== SteamTradeOfferManager.ETradeOfferState.Active) {
console.log(`[${offer.id}] trade have not active stats`)
return false;
}
if (offer.itemsToGive.length>0) {
console.log(`[${offer.id}] partner wanna get bot items, decine trade`);
return false;
}
if (offer.itemsToReceive.length>50) {
console.log(`[${offer.id}] cannot accept trade with more 50 items`)
return false;
}
const seconds = trade_checker.Items2Seconds(offer.itemsToReceive);
if (seconds === 0) {
console.log(`[${offer.id}] cannot accept trade not valid items`)
return false;
}
return seconds > 0;
}
manager.on('newOffer', function(offer) {
console.log(`[${offer.id}] Incoming trade from ${offer.partner.getSteamID64()}`);
if (calculate(offer)) {
console.log(`[${offer.id}] Try accept trade`);
offer.accept(false, function(error, status) {});
} else {
console.log(`[${offer.id}] Try decline trade`);
offer.decline(function(error, status) {})
}
})
function setupClient() {
const config = require("./auth_data/auth.json")
/////////////////////////////////////////////////////////////////
var SteamUser = require('steam-user');
var SteamCommunity = require('steamcommunity');
var SteamTOTP = require('steam-totp');
/////////////////////////////////////////////////////////////////
var client = new SteamUser();
var community = new SteamCommunity();
var manager = new SteamTradeOfferManager({
steam: client,
language: 'en'
});
/////////////////////////////////////////////////////////////////
console.log('connecting to steam account...');
client.logOn({
accountName: config.login,
password: config.password,
twoFactorCode: SteamTOTP.getAuthCode(config.shared_secret)
});
/////////////////////////////////////////////////////////////////
client.on('loggedOn', function(details, parental) {
console.log('SteamID64 :', client.steamID.getSteamID64());
client.setPersona(SteamUser.EPersonaState.Online);
});
manager.on('receivedOfferChanged', function(offer, oldState) {
console.log(`[${offer.id}] changed: ${SteamTradeOfferManager.ETradeOfferState[oldState]} -> ${SteamTradeOfferManager.ETradeOfferState[offer.state]}`);
if (offer.state === SteamTradeOfferManager.ETradeOfferState.Accepted) {
offer.getExchangeDetails((err, status, tradeInitTime, receivedItems, sentItems) => {
const seconds = trade_checker.Items2Seconds(receivedItems);
if (seconds > 0) {
const extra = `keys=${trade_checker.mannco_key(receivedItems)};metal=${trade_checker.pure_metal(receivedItems)};`;
backend.vip(offer.partner.getSteamID64(), seconds, extra, offer.id);
} else {
console.log(`[${offer.id}] Trade accepted, but vip not gived!`);
client.on('webSession', function(sessionID, cookies) {
manager.setCookies(cookies, function(err) {
if (err) {
console.log(err);
process.exit(1); // Fatal error since we couldn't get our API key
return;
}
})
}
});
console.log("Web session created!");
});
community.setCookies(cookies);
});
client.on('error', function(error) {
console.log('connection error\n');
console.log(error);
});
////////////////////////////////////////////////////////////////////
manager.on('newOffer', function(offer) {
console.log(`[${offer.id}] Incoming trade from ${offer.partner.getSteamID64()}`);
if (calculate(offer)) {
console.log(`[${offer.id}] Try accept trade`);
offer.accept(false, function(error, status) {
console.log("Cannot accept trade", error, status)
});
} else {
console.log(`[${offer.id}] Try decline trade`);
offer.decline(function(error, status) {
console.log("Cannot decline trade", error, status)
})
}
})
manager.on('receivedOfferChanged', function(offer, oldState) {
console.log(`[${offer.id}] changed: ${SteamTradeOfferManager.ETradeOfferState[oldState]} -> ${SteamTradeOfferManager.ETradeOfferState[offer.state]}`);
if (offer.state === SteamTradeOfferManager.ETradeOfferState.Accepted) {
offer.getExchangeDetails((err, status, tradeInitTime, receivedItems, sentItems) => {
const seconds = trade_checker.Items2Seconds(receivedItems);
if (seconds > 0) {
const extra = `keys=${trade_checker.mannco_key(receivedItems)};metal=${trade_checker.pure_metal(receivedItems)};`;
backend.vip(offer.partner.getSteamID64(), seconds, extra, offer.id);
} else {
console.log(`[${offer.id}] Trade accepted, but vip not gived!`);
}
})
}
});
return client;
}
sync(60);
Loading…
Cancel
Save