Verize Posted September 26, 2017 Report Posted September 26, 2017 This may be a more general question but I hope you can still help me. I have following code: bot.jsI created a class which I export using module.exports and can now import in other files. (To keep my code organized) class SteamBot { constructor(logOnOptions){ this.client = new SteamUser(); this.community = new SteamCommunity(); this.manager = new TradeOfferManager({ steam: this.client, community: this.community, language: 'en' }); this.logOn(logOnOptions); } logOn(logOnOptions){[...] } getUserInventory(sid, gameid, contextid, onlyTradeable, callback){ this.manager.getUserInventoryContents(sid, gameid, contextid, onlyTradeable, (err, inventory) => { if(err){ console.log(err); callback(new Error('Could not fetch user inventory'), false); } else { if(inventory){ callback(err, inventory) } } }) }}module.exports = SteamBot; in another file (app.js) I then require the file above (bot.js) and instantiate a new bot: const SteamBot = require('./bots/bot.js');const bot = new SteamBot({ accountName: config.botusername, password: config.botpassword, twoFactorCode: SteamTotp.generateAuthCode(config.botsharedsecret)}); So far everything works. I can call the function getUserInventory() by typing bot.getUserInventory(). What I am currently trying to solve is: I need to use the function in other files also (more specifically my router files) and I don't want to instantiate a new bot since it wouldn't be practical. How exactly can I do this? Thanks Quote
Dr. McKay Posted September 26, 2017 Report Posted September 26, 2017 You could add a function to that app.js file which returns the bot instance. Like exports.getBot = function() { ... } 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.