Frost Byte Posted November 13, 2016 Report Posted November 13, 2016 (edited) Hello everyone! Just a really quick question.Let's say I want my bot to run 24/7. How can I make sure it won't stop at all? I don't really mean like:1. Keep your computer / bot running on your local machine 24/7.2. Buy a VPS and run the bot on that machine.Because that is quite obvious. I mean like, the session not expiring. Is the following code enough to make sure that my steambot runs 24/7 on a Raspberry Pie for example? client.on("webSession", function(steamID, cookies) { logger.debug("Got web session"); setInterval(function() { client.webLogOn(); }, 1000*60*60); /* And some more stuff which need cookies */ });Thanks for your help! Edited November 13, 2016 by Frost Byte Quote
Dr. McKay Posted November 13, 2016 Report Posted November 13, 2016 That will create a new interval every time your session expires. Either use setTimeout or create the internal outside of that event callback. Also, you may want to listen for the sessionExpired event. EthanBOT 1 Quote
Frost Byte Posted November 13, 2016 Author Report Posted November 13, 2016 If I'm right, the setTimeout method only runs a function once after a specified amount of time, whereas setInterval runs a function every time after a specified amount of time. If my session expires, why would I want to run the webLogOn method only once with setTimeout? And if my session expires another time after the last one, will my bot then just stop working? Or is my reasoning completely wrong now? Besides, I implemented the following code, to keep my session active: // Re-login after a session expires community.on("sessionExpired", function(err) { if (err) { logger.info("Session is still up"); } else { logger.warn("Session expired, trying to re-login"); client.webLogOn(); } }); Will this assure that my Steambot continues to run 24/7 on a Raspberry Pie which will be on 24/7 as well? If not, could you be so kind to give a few suggestions to keep my bot running? It would be awesome to get it working! Quote
Dr. McKay Posted November 13, 2016 Report Posted November 13, 2016 You're correct regarding the behavior of setTimeout and setInterval. The problem is, if you create a new interval every time you get a new web session, then you end up with many auto-repeating timers. Quote
Frost Byte Posted November 14, 2016 Author Report Posted November 14, 2016 Alright good to know! Just a little quick question: Will the code the following code be enough to keep the bot running 24/7? // Re-login after a session expires community.on("sessionExpired", function(err) { if (err) { logger.info("Session is still up"); } else { logger.warn("Session expired, trying to re-login"); client.webLogOn(); } }); If not, could you give a suggestion to keep my bot running? That would be extremely helpful and much appreciated. As always, thanks for helping me out every time! You are awesome you know Quote
Dr. McKay Posted November 14, 2016 Report Posted November 14, 2016 You will always get an err in sessionExpired. It's not indicating that there was an error in the session expiring or anything, it's just the Error that made us aware that the session has expired. Also, I'd suggest keeping the login interval as well. Quote
Frost Byte Posted November 14, 2016 Author Report Posted November 14, 2016 Ah, wonderful! I was indeed in doubt whether the error from sessionExpired was actually the part that makes us aware that the session expired or whether it was a real error, which would mean that the session was actually still up. Well, that is sorted out now . If I'm right, this should do the trick now: client.on("webSession", function(steamID, cookies) { logger.debug("Got web session"); setInterval(function() { client.webLogOn(); }, 1000*60*60); /* And some more stuff which need cookies */ }); And at the end of the file: // Re-login after a session expires community.on("sessionExpired", function(err) { if (err) { logger.warn("Session expired, trying to re-login"); client.webLogOn(); } }); You suggested the login interval, but do you actually mean the .setInterval or the .setTimeout method? Thanks for your answer! Quote
Dr. McKay Posted November 14, 2016 Report Posted November 14, 2016 Use setInterval but outside of any event callback. Also, you need to keep track of the last time you called webLogOn and abandon if it was too soon ago, as sessionExpired can be emitted at any frequency (perhaps several times a second). Quote
Frost Byte Posted November 14, 2016 Author Report Posted November 14, 2016 I'm sorry, but I have no clue what you meant with your last sentence...I need to keep track of the last time I called webLogOn, but after that you lost me Do you mean that I can only use webLogOn if my session has expired and it doesn't work when my session is still running? And I shouldn't link it to the sessionExpired event, because that can be emitted at any frequency? Quote
Dr. McKay Posted November 15, 2016 Report Posted November 15, 2016 You can use webLogOn at any time, but if you spam Steam then Valve is not likely to be happy. You shouldn't create an interval inside of an event callback. Create it outside the callback, in the root level of the module (the part that has no indentation). Keep track of the last time you called webLogOn (a timestamp) and don't call it if it was less than say a minute ago. Quote
MikesTooLz Posted November 27, 2016 Report Posted November 27, 2016 If you got it all worked out, please post the info as I'm wanting to do the same 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.