xzan Posted August 3, 2017 Report Posted August 3, 2017 (edited) Hey I was wondering why my bot doesn't work at a 100% rate. I was interested if it is possible to farm the number on my profile of "Trades Made". So I tried coding me a bot that would send a TF2 item from one account to my second account and sends another TF2 item back after the first trade has finished. When he sends it back to the first account, the first account will accept it and send another item back to the second account, and so on ... I started putting code together with slight success. After running the bot 5 times, finally one successful trade. Now after 30 more tries, no success. I tried adding a *sleep* module for steam to handle me receiving the trade and accepting it. No success. var colors = require("colors"); var sleep = require('system-sleep'); const SteamUser1 = require("steam-user"); const SteamTotp1 = require("steam-totp"); const SteamCommunity1 = require("steamcommunity"); const TradeOfferManager1 = require("steam-tradeoffer-manager"); const client1 = new SteamUser1(); const community1 = new SteamCommunity1(); const manager1 = new TradeOfferManager1({ steam: client1, community: community1, language: "en" }); const SteamUser2 = require("steam-user"); const SteamTotp2 = require("steam-totp"); const SteamCommunity2 = require("steamcommunity"); const TradeOfferManager2 = require("steam-tradeoffer-manager"); const client2 = new SteamUser2(); const community2 = new SteamCommunity2(); const manager2 = new TradeOfferManager2({ steam: client2, community: community2, language: "en" }); const logOnOptions1 = { accountName: "", password: "", twoFactorCode: SteamTotp1.generateAuthCode("=") }; const logOnOptions2 = { accountName: "", password: "", twoFactorCode: SteamTotp2.generateAuthCode("=") }; client1.logOn(logOnOptions1); client1.on("loggedOn", () => { console.log("Logged into Steam as 11th".yellow); client1.setPersona(SteamUser1.Steam.EPersonaState.Offline); }); client2.logOn(logOnOptions2); client2.on("loggedOn", () => { console.log("Logged into Steam as ruben".blue); client2.setPersona(SteamUser2.Steam.EPersonaState.Offline); }); client1.on("webSession", (sessionid, cookies1) => { manager1.setCookies(cookies1); community1.setCookies(cookies1); community1.startConfirmationChecker(10000, "="); sendRandomItem1(); }); client2.on("webSession", (sessionid, cookies2) => { manager2.setCookies(cookies2); community2.setCookies(cookies2); community2.startConfirmationChecker(10000, "="); }); client1.on("friendMessage", function(steamid, message) { console.log("11th: ".yellow + "Friend message from " + steamid.getSteam3RenderedID() + ": " + message); }); client2.on("friendMessage", function(steamid, message) { console.log("ruben: ".blue + "Friend message from " + steamid.getSteam3RenderedID() + ": " + message); }); function sendRandomItem1() { manager1.loadInventory(440, 2, true, (err, inventory1) => { if (err) { console.log(err); } else { const offer1 = manager1.createOffer(""); const item1 = inventory1[Math.floor(Math.random() * inventory1.length - 1)]; offer1.addMyItem(item1); offer1.setMessage("There ya go!".yellow); offer1.send((err, status) => { if (err) { console.log(err); } else { console.log("Sent offer.".yellow); // sleep(5000); } }); } }); } function sendRandomItem2() { manager2.loadInventory(440, 2, true, (err, inventory2) => { if (err) { console.log(err); } else { const offer2 = manager2.createOffer(""); const item2 = inventory2[Math.floor(Math.random() * inventory2.length - 1)]; offer2.addMyItem(item2); offer2.setMessage("There ya go!".blue); offer2.send((err, status2) => { if (err) { console.log(err); } else { console.log("Sent offer.".blue); // sleep(5000); } }); } }); } manager1.on("newOffer", (offer1) => { if (offer1.partner.getSteamID64() === "id64 of account2") { offer1.accept((err, status1) => { if (err) { console.log(err); } else { console.log("Accepted offer.".yellow); console.log("Making a new offer.".yellow); sendRandomItem1(); } }); } }); manager2.on("newOffer", (offer2) => { if (offer2.partner.getSteamID64() === "id64 of account1") { offer2.accept((err, status2) => { if (err) { console.log(err); } else { console.log("Accepted offer.".blue); console.log("Making a new offer.".blue); sendRandomItem2(); } }); } }); Console (no error) Logged into Steam as ruben Logged into Steam as 11th Sent offer. Edited August 4, 2017 by xzan Quote
Dr. McKay Posted August 3, 2017 Report Posted August 3, 2017 A few things:Colors are only useful in console.log output. You cannot and should not use them in offer messages. You should not be using the confirmation checker. I suspect you're being rate-limited because you're using it twice with a relatively low poll interval. Instead, use community.acceptConfirmationForObject as needed (in the callback to offer.accept(); check the status). It is not safe to start sending an offer until the callback to manager.setCookies fires. Quote
xzan Posted August 4, 2017 Author Report Posted August 4, 2017 Alright, so the first mistake you pointed out I was actually aware of. But thanks because I didn't notice it!I removed the confirmation checker and added the acceptConfirmForObject method and called the status back. This works now. client1.on("webSession", (sessionid, cookies1) => { manager1.setCookies(cookies1); community1.setCookies(cookies1); // community1.startConfirmationChecker(10000, "account1-identySecret"); sendRandomItem1(); }); client2.on("webSession", (sessionid, cookies2) => { manager2.setCookies(cookies2); community2.setCookies(cookies2); // community2.startConfirmationChecker(10000, "account2-identySecret"); }); function sendRandomItem1() { manager1.loadInventory(440, 2, true, (err, inventory1) => { if (err) { console.log(err); } else { const offer1 = manager1.createOffer("account2"); const item1 = inventory1[Math.floor(Math.random() * inventory1.length - 1)]; offer1.addMyItem(item1); offer1.setMessage("There ya go!"); offer1.send((err, status1) => { if (err) { console.log(err); return; } if (status1 == "pending") { //if pending, confirm it. console.log(`Offer #${offer1.id} sent, but requires confirmation. (yellow)`); community1.acceptConfirmationForObject(logOnOptions1.identySecret, offer1.id, function(err) { if (err) { console.log(err); } else { console.log(`Offer #${offer1.id} confirmed! (yellow)`); } }); } else { console.log(`Offer #${offer1.id} sent successfully`); } }); } }); } function sendRandomItem2() { manager2.loadInventory(440, 2, true, (err, inventory2) => { if (err) { console.log(err); } else { const offer2 = manager2.createOffer("account1"); const item2 = inventory2[Math.floor(Math.random() * inventory2.length - 1)]; offer2.addMyItem(item2); offer2.setMessage("There ya go!"); offer2.send((err, status2) => { if (err) { console.log(err); return; } if (status2 == "pending") { //if pending, confirm it. console.log(`Offer #${offer2.id} sent, but requires confirmation. (blue)`); community2.acceptConfirmationForObject(logOnOptions2.identySecret, offer2.id, function(err) { if (err) { console.log(err); } else { console.log(`Offer #${offer2.id} confirmed! (blue)`); } }); } else { console.log(`Offer #${offer2.id} sent successfully`); } }); } }); } manager1.on("newOffer", (offer1) => { if (offer1.partner.getSteamID64() === "account2") { offer1.accept((err, status1) => { if (err) { console.log(err); } else { community1.checkConfirmations(); //I added this, that's all for the manager console.log("Accepted offer.".yellow); console.log("Making a new offer.".yellow); sendRandomItem1(); } //if (status == "pending")? }); } }); manager2.on("newOffer", (offer2) => { if (offer2.partner.getSteamID64() === "account1") { offer2.accept((err, status2) => { if (err) { console.log(err); } else { community2.checkConfirmations(); //I added this, that's all for the manager console.log("Accepted offer.".blue); console.log("Making a new offer.".blue); sendRandomItem2(); } //if (status == "pending")? }); } }); First attempt outputs an error loading the TF2 inventory followed by my second attempt without an error, still stuck after sending and confirming the trade: C:\Users\Admin\Desktop>node trade_farm.js Logged into Steam as 11th Logged into Steam as ruben C:\Users\Admin\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:419 if (typeof details.appid === 'undefined' || typeof details.contextid === 'undefined' || (typeof details.assetid === 'undefined' && typeof details.id === 'undefined')) { ^ TypeError: Cannot read property 'appid' of undefined at addItem (C:\Users\Admin\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:419:20) at TradeOffer.addMyItem (C:\Users\Admin\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:332:9) at manager1.loadInventory (C:\Users\Admin\Desktop\trade_farm.js:84:11) at SteamCommunity.<anonymous> (C:\Users\Admin\node_modules\steamcommunity\components\users.js:331:5) at Request._callback (C:\Users\Admin\node_modules\steamcommunity\components\http.js:67:15) at Request.self.callback (C:\Users\Admin\node_modules\request\request.js:188:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request.<anonymous> (C:\Users\Admin\node_modules\request\request.js:1171:10) at emitOne (events.js:96:13) C:\Users\Admin\Desktop>node trade_farm.js Logged into Steam as 11th Logged into Steam as ruben Offer #2364986494 sent, but requires confirmation. (yellow) Offer #2364986494 confirmed! (yellow) ^C C:\Users\Admin\Desktop> Yet I don't fully understand what I should do in the *manager.on("newOffer")*s. Thank you Quote
Dr. McKay Posted August 5, 2017 Report Posted August 5, 2017 That crash is because you're trying to pass undefined to addMyItem. 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.