manic Posted December 27, 2018 Report Posted December 27, 2018 I'm running a bot and the majority of trade offers are not going through. The bot logs in and handles expired sessions like this: let client = new SteamUser(); let community = new SteamCommunity(); let manager = new TradeOfferManager({ community: community, steam: client, domain: "example.com", language: "en", pollInterval: 2000 }); let logOnOptions = { "accountName": data.username, "password": data.password, "twoFactorCode": SteamTotp.getAuthCode(data.shared_secret) }; client.logOn(logOnOptions); client.on('loggedOn', function() { console.log("Logged into Steam"); client.setPersona(SteamUser.EPersonaState.Online); }); client.on('webSession', function(sessionID, cookies) { manager.setCookies(cookies); community.setCookies(cookies); console.log("weblogon") }); community.on("sessionExpired", function(err) { console.log("## Session Expired"); client.webLogOn(); }); The bot gets new offers with manager.on('newOffer', function(offer) { , makes a simple request using https://www.npmjs.com/package/request and calls offer.getUserDetails. An offer is accepted like this: offer.accept(accept(offer, 1)); These are the two functions that handle accepting and confirming trades: function confirm(offer, count) { return function(err) { if (err) { if (count < 20) { console.log(err); setTimeout(community.acceptConfirmationForObject, 10000, data.identity_secret, offer.id, confirm(offer, count + 1)); } else { console.error("CONFIRM FUNCTION: "); console.error(err); } } } } function accept(offer, count) { return function(err, status) { if (err) { if (count < 20) { console.log(err); setTimeout(offer.accept, 10000, accept(offer, count + 1)); } else { console.error("ACCEPT FUNCTION: "); console.error(err); } } else { if (status === "pending") { community.acceptConfirmationForObject(data.identity_secret, offer.id, confirm(offer, 1)); } } } } Whenever I run the code it works for a few hours accepting offers and confirming them. Then offer comes in and the sessionExpired and webSession events are emitted twice. Error: Cannot accept an unsent offer happens every time it tries to accept the offer.This from stdout (it also logs the timestamp): 16:31:23 Error: Not Logged In at SteamCommunity._checkCommunityError (/home/user/bot/node_modules/steamcommunity/components/http.js:128:9) at Request._callback (/home/user/bot/node_modules/steamcommunity/components/http.js:51:88) at Request.self.callback (/home/user/bot/node_modules/request/request.js:185:22) at emitTwo (events.js:126:13) at Request.emit (events.js:214:7) at Request.<anonymous> (/home/user/bot/node_modules/request/request.js:1161:10) at emitOne (events.js:116:13) at Request.emit (events.js:211:7) at Gunzip.<anonymous> (/home/user/bot/node_modules/request/request.js:1083:12) at Object.onceWrapper (events.js:313:30) 16:31:23 ## Session Expired 16:31:23 ## Session Expired 16:31:23 Error: Not Logged In at SteamCommunity.manager._community.httpRequestPost (/home/user/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:483:25) at Request._callback (/home/user/bot/node_modules/steamcommunity/components/http.js:67:15) at Request.self.callback (/home/user/bot/node_modules/request/request.js:185:22) at emitTwo (events.js:126:13) at Request.emit (events.js:214:7) at Request.<anonymous> (/home/user/bot/node_modules/request/request.js:1161:10) at emitOne (events.js:116:13) at Request.emit (events.js:211:7) at IncomingMessage.<anonymous> (/home/user/bot/node_modules/request/request.js:1083:12) at Object.onceWrapper (events.js:313:30) 16:31:23 weblogon 16:31:24 weblogon 16:31:33 Error: Cannot accept an unsent offer at Timeout.TradeOffer.accept [as _onTimeout] (/home/user/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:451:23) at ontimeout (timers.js:502:15) at tryOnTimeout (timers.js:323:5) at Timer.listOnTimeout (timers.js:290:5) 16:31:43 Error: Cannot accept an unsent offer at Timeout.TradeOffer.accept [as _onTimeout] (/home/user/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:451:23) at ontimeout (timers.js:502:15) at tryOnTimeout (timers.js:323:5) at Timer.listOnTimeout (timers.js:290:5) ... etc What am I doing wrong? Quote
Dr. McKay Posted December 28, 2018 Report Posted December 28, 2018 You're accepting offers very wrongly. First, remove the offer.accept(...) around your call to your own accept function. Second, passing offer.accept to setTimeout like that will cause problems because the this reference is lost. For example: function TestObj(name) { this.name = name; } TestObj.prototype.printThis = function() { console.log(this); }; let obj = new TestObj('foobar'); obj.printThis(); setTimeout(obj.printThis, 500); Prints this: TestObj { name: 'foobar' } undefined The reason this happens is because this is set to the reference of the object on which the method was called. So when you call obj.printThis(), the this reference is to obj. But when you pass obj.printThis to setTimeout, what setTimeout sees is something like: function setTimeout(callback, delay) { wait(delay); callback(); } As you can see, when callback is called (which is obj.printThis in this case), there is no object reference on which it's called, so this is undefined. If you want to pass offer.accept to setTimeout like that, you'll need to bind it like this: setTimeout(offer.accept.bind(offer), delay) Quote
manic Posted December 29, 2018 Author Report Posted December 29, 2018 It's been working for over 24 hours, thanks. Dr. McKay 1 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.