|
@ -5,38 +5,65 @@ var trade_checker_imp = require("./trade_checker") |
|
|
var backend = new backend_integration(); |
|
|
var backend = new backend_integration(); |
|
|
var trade_checker = new trade_checker_imp(); |
|
|
var trade_checker = new trade_checker_imp(); |
|
|
const VERSION = require("./version"); |
|
|
const VERSION = require("./version"); |
|
|
console.log(`Build date: ${VERSION}`); |
|
|
var SteamTradeOfferManager = require('steam-tradeoffer-manager'); |
|
|
|
|
|
|
|
|
async function sync(timeout) { |
|
|
async function sync(timeout) { |
|
|
|
|
|
console.log(`Build date: ${VERSION}`); |
|
|
let sleep = function sleep (howLong) { |
|
|
let sleep = function sleep (howLong) { |
|
|
return new Promise(function (resolve) { |
|
|
return new Promise(function (resolve) { |
|
|
setTimeout(() => {resolve()}, howLong) |
|
|
setTimeout(() => {resolve()}, howLong) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
var steam_client; |
|
|
while (true) { |
|
|
while (true) { |
|
|
try { |
|
|
try { |
|
|
await backend.pulse().then(() => { |
|
|
await backend.pulse().then(async () => { |
|
|
if (backend.up) { |
|
|
if (backend.up) { |
|
|
backend.getPrices(trade_checker); |
|
|
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) { |
|
|
} catch (e) { |
|
|
console.log(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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function setupClient() { |
|
|
|
|
|
const config = require("./auth_data/auth.json") |
|
|
/////////////////////////////////////////////////////////////////
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
var SteamUser = require('steam-user'); |
|
|
var SteamUser = require('steam-user'); |
|
|
var SteamCommunity = require('steamcommunity'); |
|
|
var SteamCommunity = require('steamcommunity'); |
|
|
var SteamTradeOfferManager = require('steam-tradeoffer-manager'); |
|
|
|
|
|
var SteamTOTP = require('steam-totp'); |
|
|
var SteamTOTP = require('steam-totp'); |
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
var client = new SteamUser(); |
|
|
var client = new SteamUser(); |
|
|
var community = new SteamCommunity(); |
|
|
var community = new SteamCommunity(); |
|
@ -44,8 +71,8 @@ var manager = new SteamTradeOfferManager({ |
|
|
steam: client, |
|
|
steam: client, |
|
|
language: 'en' |
|
|
language: 'en' |
|
|
}); |
|
|
}); |
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
console.log('connecting to steam account...'); |
|
|
console.log('connecting to steam account...'); |
|
|
const config = require("./auth_data/auth.json") |
|
|
|
|
|
client.logOn({ |
|
|
client.logOn({ |
|
|
accountName: config.login, |
|
|
accountName: config.login, |
|
|
password: config.password, |
|
|
password: config.password, |
|
@ -76,41 +103,18 @@ client.on('error', function(error) { |
|
|
console.log(error); |
|
|
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) { |
|
|
manager.on('newOffer', function(offer) { |
|
|
console.log(`[${offer.id}] Incoming trade from ${offer.partner.getSteamID64()}`); |
|
|
console.log(`[${offer.id}] Incoming trade from ${offer.partner.getSteamID64()}`); |
|
|
if (calculate(offer)) { |
|
|
if (calculate(offer)) { |
|
|
console.log(`[${offer.id}] Try accept trade`); |
|
|
console.log(`[${offer.id}] Try accept trade`); |
|
|
offer.accept(false, function(error, status) {}); |
|
|
offer.accept(false, function(error, status) { |
|
|
|
|
|
console.log("Cannot accept trade", error, status) |
|
|
|
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
console.log(`[${offer.id}] Try decline trade`); |
|
|
console.log(`[${offer.id}] Try decline trade`); |
|
|
offer.decline(function(error, status) {}) |
|
|
offer.decline(function(error, status) { |
|
|
|
|
|
console.log("Cannot decline trade", error, status) |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
@ -128,3 +132,7 @@ manager.on('receivedOfferChanged', function(offer, oldState) { |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
return client; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sync(60); |