Bogdan2609 Posted September 25, 2016 Report Posted September 25, 2016 Hello, my bot sends the exchange, but does not confirm it. Please help me. Fasten code below. var SteamUser = require('steam-user'); var SteamCommunity = require('steamcommunity'); var SteamTotp = require('steam-totp'); var TradeOfferManager = require('steam-tradeoffer-manager'); var fs = require('fs'); var request = require('request'); var async = require('async'); var client = new SteamUser({ "dataDirectory": null }); var manager = new TradeOfferManager({ "steam": client, "domain": "site.ru", "language": "ru" }); var community = new SteamCommunity(); var steamID = SteamCommunity.SteamID; if(fs.existsSync('./users/users.json') && fs.existsSync('./users/master_ssfn')) { var users = JSON.parse(fs.readFileSync('./users/users.json')); var sentry = fs.readFileSync('./users/master_ssfn'); } else { console.log("Users file or master ssfn missing. Exiting.."); process.exit(1); } var user = users.thor; var logOnOptions = { "accountName": user.accountName, "password": user.password, "twoFactorCode": SteamTotp.getAuthCode(user.twoFactorCode) }; if(fs.existsSync('./polls/' + user.accountName + '.json')) { manager.pollData = JSON.parse(fs.readFileSync('./polls/' + user.accountName + '.json')); } client.setSentry(sentry); client.logOn(logOnOptions); client.on('loggedOn', function() { console.log("Logged into Steam account " + user.accountName); }); client.on('webSession', function(sessionID, cookies) { manager.setCookies(cookies, function(err) { if(err) { console.log(err); process.exit(1); return; } console.log("Got API key: " + manager.apiKey + " for user " + user.accountName); }); community.setCookies(cookies); community.startConfirmationChecker(10000, user.identitySecret); // Checks and accepts confirmations every 30 seconds client.setPersona(SteamUser.Steam.EPersonaState.Online, user.personaName); sessionInterval(3600000); }); manager.on('newOffer', function(offer) { var steamID64 = offer.partner.getSteamID64(); console.log('Received new offer from ' + steamID64); if(steamID64 == "steamID") { offer.accept(); } else { offer.decline(); } }); manager.on('sentOfferChanged', function(offer, oldState) { var offerTradeId = offer.id; var state = offer.state; console.log('Offer.Changed: ', offerTradeId + " is now " + state); request({ "url": "http://site/steam/set-offer-state/" + offerTradeId + "/" + state }); }); manager.on('pollData', function(pollData) { fs.writeFile('./polls/' + user.accountName + '.json', JSON.stringify(pollData)); }); function sessionInterval(time) { setTimeout(function() { console.log('Getting new cookies.'); client.webLogOn(); }, time); } /** * Express API to access SteamBot features and functions */ var express = require('express'); var app = express(); var bodyParser = require('body-parser'); app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.get('/', function(req, res) { res.send('"Иди в дом, там мама тебе нальёт томатного." - Ðнди Картрайт'); }); app.post('/MakePlayerExchange/:steamid', function(req, res) { var user = new steamID(req.params.steamid); var bot = new steamID(req.body['botsteamid']); var token = req.body['token']; var uItems = req.body['userItems']; var bItems = req.body['botItems']; manager.getEscrowDuration(user, token, function(err, him, me) { if( err) { res.json({ "error": err }); return; } if( ! (him == 0 && me == 0)) { res.json({ "error": "Escrow Error. User has not enabled 2FA." }); return; } async.parallel({ userInventory: function(callback) { manager.loadUserInventory(user, 730, 2, true, function(err, inventory) { if( err) { callback(err); } else { callback(null, inventory); } }); }, botInventory: function(callback) { manager.loadUserInventory(bot, 730, 2, true, function(err, inventory) { if( err) { callback(err); } else { callback(null, inventory); } }); } }, function(err, results) { if( err) { res.json({ "error": err }); return; } var Exchange = manager.createOffer(user); var Message = "Site.ru | Thank You for trading with us. Here's your items from the Exchange page. This offer expires in 10 minutes."; var ExchangeUser = GetExchangeItems(results.userInventory, uItems); var ExchangeBot = GetExchangeItems(results.botInventory, bItems); if(typeof ExchangeUser.error != "undefined") { res.json(ExchangeUser); return; } if(typeof ExchangeBot.error != "undefined") { res.json(ExchangeBot); return; } Exchange.addTheirItems(ExchangeUser); Exchange.addMyItems(ExchangeBot); Exchange.send(Message, token, function(err, status) { if( err) { res.json({ "error": err }); return; } console.log('Exchange send: ', status); console.log('Exchange Offer ID: ', Exchange.id); res.json({ "offer": Exchange.id, "status": status, "state": Exchange.state }); }); }); }); }); function GetExchangeItems(Inventory, Items) { var ReturnItems = []; var i; for(i in Items) { var Item = i; var Count = +Items[i]; var j; for(j in Inventory) { var invItem = Inventory[j]; if(invItem.market_hash_name == Item) { //console.log('Should push here: ', invItem.classid); ReturnItems.push(invItem); Count--; } //console.log(invItem.market_hash_name, Count); if(Count == 0) { break; } } if(Count > 0) { return { "error": "Not enough Items in Inventory. Missing: " + Item + ", need " + Count + " more. Only got " + (+Items[i] - Count) }; break; } } //console.log(ReturnItems); return ReturnItems; } Quote
adma Posted September 27, 2016 Report Posted September 27, 2016 To mobile confirm you have to use steam-community newConfirmation event community.on("newConfirmation", function(conf) { var time = Math.floor(Date.now() / 1000); conf.respond(time, SteamTotp.getConfirmationKey(PLACEYOURCONFKEYHERE, time, "allow"), true, function(err) { if (err) { // error } else { // anything you want to do when you mobile confirm } }); }); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.