Thursday, 3 August 2017

node js bot help

I'm having issues with this code, I have a node js that connects to some cfgs, logs in w steam and should be able to trade. Can someone explain why I'm getting 0 for 'their value'const SteamUser = require('steam-user'); const SteamTotp = require('steam-totp'); const SteamCommunity = require('steamcommunity'); const TradeOfferManager = require('steam-tradeoffer-manager'); const Prices = require('./prices.json'); const config = require('./config.json'); const client = new SteamUser(); const community = new SteamCommunity();const manager = new TradeOfferManager ({ steam: client, community: community, language: 'en' }); const logOnOptions = { accountName: config.username, password: config.password, twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret) }client.logOn(logOnOptions);client.on('loggedOn', () => { console.log('BEE TRADING/IDLE BOT SUCCESSFULLY LOADED!'); console.log('TRADING/IDLING FOR GAME TEAM FORTRESS 2 #440'); client.setPersona(SteamUser.Steam.EPersonaState.Online); client.gamesPlayed(["Bee Trading Bot #1 - .help", 440]); });client.on('webSession', (sessionid, cookies) => { manager.setCookies(cookies);community.setCookies(cookies); community.startConfirmationChecker(20000, config.identitySecret); });client.on("friendMessage", function(steamID, message) { if (message == ".help") { client.chatMessage(steamID, "Current commands are:"); client.chatMessage(steamID, ".trade"); client.chatMessage(steamID, ".game"); client.chatMessage(steamID, ".joke"); client.chatMessage(steamID, ".ping"); client.chatMessage(steamID, ".contact"); client.chatMessage(steamID, ".help"); client.chatMessage(steamID, ".chika"); } if (message == ".joke") { client.chatMessage(steamID, "Why did the bot cross the road? He can't, he's a bot.."); } if (message == ".trade") { client.chatMessage(steamID, "Bot out of stock. Status: Unavailable"); } if (message == ".ping") { client.chatMessage(steamID, "Pong."); } if (message == ".contact") { client.chatMessage(steamID, "http://ift.tt/2v1Rwxu"); } if (message == ".game") { client.chatMessage(steamID, "Currently idling for: #440 (Team Fortress 2)"); client.chatMessage(steamID, "Currently trading for: #440 (Team Fortress 2)"); } if (message == ".chika") { client.chatMessage(steamID, "is gay."); } });client.on('friendRelationship', function(sid, relationship) { if(relationship == 2) { client.addFriend(sid); console.log("Friend Added!"); client.chatMessage(sid, 'Hello! This is bee idle/trade bot. Type !help.'); } });function acceptOffer(offer) { offer.accept((err) => { if (err) console.log("there was an error accepting."); }); }function declineOffer(offer) { offer.decline((err) => { if (err) console.log("there was an error declining."); }); }function processOffer(offer) { if (offer.isGlitched() || offer.state === 11) { console.log('Offer was glitched, declining'); declineOffer(offer); } else if (offer.partner.getSteamID64() === config.ownerID) { acceptOffer(offer); } else { var ourItems = offer.itemsToGive; var theirItems = offer.itemsToRecieve; var ourValue = 0; var theirValue = 0; for (var i in ourItems) { var item = ourItems[i].market_name; if(Prices[item]) { ourValue += Prices[item].sell; } else { console.log('Invalid Value'); ourValue += 99999; } } for(var i in theirItems) { var item = theirItems[i].market_name; if(Prices[item]) { theirValue += Prices[item].buy; } else { console.log('Their Value was different.') } } console.log('Our value: '+ourValue); console.log('Their value: '+theirValue);if (ourValue <= theirValue) { acceptOffer(offer); } else { declineOffer(offer); } } } manager.on('newOffer', (offer) => { processOffer(offer); });{ "Scrap Metal": { "buy": 1, "sell": 1 },"Reclaimed Metal": { "buy": 3, "sell": 3 }, "Refined Metal": { "buy": 9, "sell": 9 } }

Submitted August 03, 2017 at 12:36PM by memecasternametaken

No comments:

Post a Comment