Jump to content
McKay Development

Recommended Posts

Posted

This may be a more general question but I hope you can still help me. I have following code:

 

bot.js

I 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 

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...