Galorch Posted June 12, 2016 Report Posted June 12, 2016 (edited) So I'm quite new to this stuff and I'd like to get some help.I want to make a bot that accepts only certain trade offers, for ex, user put a KB-808 in the trade offer and took 3 scrap(/1 rec) and I want that to be accepted, what I have right now accepts everything, here's the bot: ----------------------------------------- var Steam = require ('steam'); var SteamUser = require('steam-user'); var client = new SteamUser(); var SteamTotp = require('steam-totp'); var fs = require("fs"); var SteamCommunity = require('steamcommunity'); var community = new SteamCommunity(steamClient); var steamClient = new Steam.SteamClient(); var SteamUser = new Steam.SteamUser(steamClient); var SteamFriends = new Steam.SteamFriends(steamClient); var crypto = require('crypto'); var SteamTradeOffers = require('steam-tradeoffers'); var offers = new SteamTradeOffers(); var config; try { config = JSON.parse(fs.readFileSync('./config.json')); } catch (err) { console.log("Error: Unable to parse config.json"); console.log(err); process.exit(1); } client.logOn({ "accountName": config.username, "password": config.password }); var TradeOfferManager = require('steam-tradeoffer-manager'); var manager = new TradeOfferManager({ "community": community, "language": "en", "pollInterval": 1000 }); client.on("webSession", function(steamID, cookies){ manager.setCookies(cookies); community.setCookies(cookies); SteamTotp.steamID = steamID; community.startConfirmationChecker(2500, config.identitySecret) }); manager.on('newOffer', function(offer) { console.log("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID()); offer.accept(function(err) { if (err) { console.log("Unable to accept offer: " + err.message); } else { community.checkConfirmations(); // Check for confirmations right after accepting the offer console.log("Offer accepted"); } }); }); manager.on('receivedOfferChanged', function(offer, oldState) { console.log("Offer #" + offer.id + " changed: " + TradeOfferManager.getStateName(oldState) + " -> " + TradeOfferManager.getStateName(offer.state)); if (offer.state == TradeOfferManager.ETradeOfferState.Accepted) { offer.getReceivedItems(function(err, items) { if (err) { console.log("Couldn't get received items: " + err); } else { var names = items.map(function(item) { return item.name; }); console.log("Received: " + names.join(', ')); } }); } }); client.on("loggedOn", function(details) { client.setPersona(Steam.EPersonaState.Online) client.gamesPlayed(440) console.log("Successfully logged onto Steam, APIKey: " + config.apikey) }); client.on("steamGuard", function(domain, callback, lastCodeWrong) { if(lastCodeWrong) { console.log("Last code wrong, retrying"); } var shared_secret = config.sharedsecret; callback(SteamTotp.generateAuthCode(shared_secret)); }); community.on("newConfirmation", function(conf) { conf.respond(Math.floor(Date.now() / 1000), SteamTotp.getConfirmationKey(config.identitysecret,Math.floor(Date.now() / 1000), "allow"), true, function(err){ if(err) { console.log("Confirmation failed: " + err); return; } console.log("Sucessfully confirmed!"); }); }); community.on("confKeyNeeded", function(tag, callback){ var time = Math.floor(Date.now() / 1000); callback(null, time, SteamTotp.getConfirmationKey(config.identitysecret, time, tag)); }); Edited June 19, 2016 by Galorch Quote
Dr. McKay Posted June 12, 2016 Report Posted June 12, 2016 (edited) Use [ code ] tags (without spaces) please. Why are you using steam with steam-user, and steam-tradeoffers with steam-tradeoffer-manager? Edited June 13, 2016 by Dr. McKay Quote
Galorch Posted June 13, 2016 Author Report Posted June 13, 2016 (edited) Because I'm a noob, I have no idea what 50% of the above does, nor do I know what means C: Edited June 13, 2016 by Galorch Quote
Dr. McKay Posted June 13, 2016 Report Posted June 13, 2016 It modified my post. Wrap your code in [ code ] and [ /code ] (without spaces in the brackets). Quote
Galorch Posted June 17, 2016 Author Report Posted June 17, 2016 Alright I did it, sorry I didn't respond sooner, didn't have time Quote
Dr. McKay Posted June 17, 2016 Report Posted June 17, 2016 Your original code, which I sure hope has indentation. Quote
Galorch Posted June 18, 2016 Author Report Posted June 18, 2016 This should be the original code, if it's not then I have no idea what you're talking about and I don't know what 'identation' means Quote
Dr. McKay Posted June 18, 2016 Report Posted June 18, 2016 https://en.wikipedia.org/wiki/Indentation_(typesetting) Quote
Galorch Posted June 19, 2016 Author Report Posted June 19, 2016 Alright, I did it just like you asked Quote
Dr. McKay Posted June 19, 2016 Report Posted June 19, 2016 You're calling offer.accept for every incoming offer. You need to add some checks there to make sure it only accepts offers you want to accept. Quote
Galorch Posted June 20, 2016 Author Report Posted June 20, 2016 That is exactly why I'm here, I don't know how I can make it only accept certain trade offers. Quote
Dr. McKay Posted June 20, 2016 Report Posted June 20, 2016 Sorry, but I'm not here to teach you JavaScript. Quote
Dr. McKay Posted June 21, 2016 Report Posted June 21, 2016 You could try Codecademy to learn JavaScript, and Stack Overflow to ask your general JavaScript questions. 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.