Jump to content


Photo
Question

getPersonas not working with module.exports

node.js node-steam-user

Best Answer Dr. McKay , 29 April 2019 - 05:38 PM

If the code you posted in your original post is that entire file, then that specific client is not logged on. You instead created a new one.

Go to the full post


  • Please log in to reply
4 replies to this topic

#1 Space Engineer

Space Engineer

    Newbie

  • Member
  • Pip
  • 3 posts
  • LocationAround

Posted 28 April 2019 - 07:36 PM

Hello mates!

This might be a weird question, but I'm having trouble getting "client.getPersonas" to function in a module.export.
 

Here is my file my problem is located in:
(Problem is in the exports.GetSteamName)

var exports = module.exports = {};

var SteamUser = require('steam-user');
var client = new SteamUser();

const SteamRepAPI = require('steamrep');

exports.CheckRep = function (SteamId64) {
    return new Promise(resolve => {
        SteamRepAPI.isScammer(SteamId64, function (err, result) {
            if (err) {
                console.log("Error Checking SteamREP for " + SteamId64);
                resolve(true); // true == Not a scammer
            } else {
                if (result) {
                    console.log("eww thats gross")
                    resolve(false);
                } else {
                    console.log("Got Not-Scammer!")
                    resolve(true); // true == Not a scammer
                }
            }
        });
    })
}

exports.GetSteamName = function (SteamID) {
    return new Promise(resolve => {
        client.getPersonas([SteamID], function (personas) {
            persona = personas[SteamID.getSteamID64()];
            name = persona ? persona.player_name : ("[" + SteamID.getSteamID64() + "]");
            resolve(name)
        })
    })
}

What happens is once the program gets to"client.getPersonas([SteamID], function (personas) {" , it seems to run over everything inside of the function(personas). Including the "resolve"

If I were to change exports.GetSteamName to:

exports.GetSteamName = function (SteamID) {
    return new Promise(resolve => {
        client.getPersonas([SteamID], function (personas) {
            persona = personas[SteamID.getSteamID64()];
            name = persona ? persona.player_name : ("[" + SteamID.getSteamID64() + "]");
            resolve(name)
        })
        console.log("Fired?")
    })
}
I will get back "Fired?" in console.
 
 
The problem is present in another file I am using for Chat messages.
The problem is not present in "CheckRep".
 
This could just be me not understanding how module.exports works exactly as this is still a somewhat new concept for me.
CheckRep, however, works as expected and that's what I'm getting caught up on.
 
I think it could be that "SteamUser" and "client" are being called more than expected (I'm declaring them in multiple files).
SteamRepAPI is only declared in this file.
 
I have resorted to moving the function into the main file, which works as expected. I would greatly prefer it to function in this file.
 
 
Taken from package.json:
"steam-user": "^3.28.2",
 
 
Any help is greatly appreciated, Thanks!
 
 


#2 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,070 posts

Posted 29 April 2019 - 02:59 PM

Did you ever log on with the client?



#3 Space Engineer

Space Engineer

    Newbie

  • Member
  • Pip
  • 3 posts
  • LocationAround

Posted 29 April 2019 - 05:28 PM

Did you ever log on with the client?

In the main file, yes.

client.setOption("promptSteamGuardCode", false);

const logOnOptions = {
	accountName: config.username,
	password: config.password,
	rememberPassword: true,
	twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
};
client.logOn(logOnOptions);


#4 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,070 posts

Posted 29 April 2019 - 05:38 PM   Best Answer

If the code you posted in your original post is that entire file, then that specific client is not logged on. You instead created a new one.



#5 Space Engineer

Space Engineer

    Newbie

  • Member
  • Pip
  • 3 posts
  • LocationAround

Posted 29 April 2019 - 06:07 PM

If the code you posted in your original post is that entire file, then that specific client is not logged on. You instead created a new one.

Excellent, thank you for the help!

 

Im now just supplying the "client" information in the request.

 

Thanks again!
 







Also tagged with one or more of these keywords: Question, node.js, node-steam-user

5 user(s) are reading this topic

0 members, 5 guests, 0 anonymous users