TextDynasty Posted December 18, 2016 Report Posted December 18, 2016 Hi.I got a problem like this and i don't know how to fix it. log.verbose("polldata.json is corrupt"); ^ ReferenceError: log is not defined at Object.<anonymous> (C:\Users\kingwang\Desktop\Trade Offer Bot\bot2.js:55:3) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:139:18) at node.js:974:3 And here is my code if(fs.existsSync(POLLDATA_FILENAME)) { try { manager.pollData = JSON.parse(fs.readFileSync(POLLDATA_FILENAME)); } catch(e) { log.verbose("polldata.json is corrupt"); } } manager.on('pollData', function(pollData) { fs.writeFile(POLLDATA_FILENAME, JSON.stringify(pollData)); }); var logger = new (Winston.Logger)({ transports: [ new (Winston.transports.Console)({ colorize: true, level: 'debug' }), new (Winston.transports.File)({ level: 'info', timestamp: true, filename: 'cratedump.log', json: false }) ] }); var client = new SteamUser(); var offers = new TradeOfferManager({ steam: client, domain: config2.domain, language: "en", pollInterval: 10000, cancelTime: 50000 }); fs.readFile('polldata.json', function (err, data) { if (err) { logger.warn('Error reading polldata.json. If this is the first run, this is expected behavior: '+err); } else { console.log('Welcome back my master.'.green); console.log("Found previous trade offer poll data. Importing it to keep things running smoothly.".info); offers.pollData = JSON.parse(data); } }); client.logOn({ accountName: config2.username, password: config2.password, }); client.on('loggedOn', function (details) { console.log(timestamp("[hh:mm:ss] Logged into Steam as " + config2.username.green)); // If you wanted to go in-game after logging in (for crafting or whatever), you can do the following client.gamesPlayed(440); }); client.on('webSession', function (sessionID, cookies) { console.log("Got web session".info); client.setPersona(1) offers.setCookies(cookies, function (err){ if (err) { logger.error('Unable to set trade offer cookies: '+err); process.exit(1); } logger.info("Trade offer cookies set."); manager.loadInventory(440, 2, true, function(err, inventory) { if (err) { console.log(err); return; } if (inventory.length == 0) { // Inventory empty console.log("TF2 inventory is empty"); return; } console.log("Found " + inventory.length + " TF2 items"); var ref = inventory.filter(function (item) { return item.name == 'Refined Metal' }); var rec = inventory.filter(function (item) { return item.name == 'Reclaimed Metal' }); var scrap = inventory.filter(function (item) { return item.name == 'Scrap Metal' }); console.log("Found " + ref.length + " Refined Metal"); console.log("Found " + rec.length + " Reclaimed Metal"); console.log("Found " + scrap.length + " Scrap Metal"); var inventory = inventory.filter(function (item) { return item.name == 'Refined Metal' }); var trade = offers.createOffer(admin); trade.addMyItems(inventory); trade.setMessage("Here, have some items!"); trade.send(function(err, status) { if (err) { console.log(err); } else { console.log("Success. Offer was sent to admin.") } }); }); }); }); Any ideas how to fix this problem? Also, my bot is working fine before Quote
Dr. McKay Posted December 18, 2016 Report Posted December 18, 2016 That is happening because log is not defined. You want to move the polldata-reading block of code beneath where you define your logger, and change log.verbose to logger.verbose. Quote
TextDynasty Posted December 18, 2016 Author Report Posted December 18, 2016 That is happening because log is not defined. You want to move the polldata-reading block of code beneath where you define your logger, and change log.verbose to logger.verbose.Thanks for answering. But i got this after i changed to this coding var logger = new (Winston.Logger)({ transports: [ new (Winston.transports.Console)({ colorize: true, level: 'debug' }), new (Winston.transports.File)({ level: 'info', timestamp: true, filename: 'cratedump.log', json: false }) ] }); if(fs.existsSync(POLLDATA_FILENAME)) { try { manager.pollData = JSON.parse(fs.readFileSync(POLLDATA_FILENAME)); } catch(e) { logger.verbose("polldata.json is corrupt"); } } manager.on('pollData', function(pollData) { fs.writeFile(POLLDATA_FILENAME, JSON.stringify(pollData)); }); Error verbose: polldata.json is corrupt Welcome back my master. Found previous trade offer poll data. Importing it to keep things running smoothly. undefined:1 SyntaxError: Unexpected end of input at Object.parse (native) at C:\Users\kingwang\Desktop\Trade Offer Bot\bot2.js:93:32 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3) Press any key to continue . . . Quote
Dr. McKay Posted December 18, 2016 Report Posted December 18, 2016 Your code's syntax is wrong. I suggest that you post a question containing your full code at stackoverflow.com Quote
TextDynasty Posted December 18, 2016 Author Report Posted December 18, 2016 Your code's syntax is wrong. I suggest that you post a question containing your full code at stackoverflow.combut my bot was working fine before 1 week. And i didn't changed anything 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.