Jump to content
McKay Development

Recommended Posts

Posted

Hey,

 

Running into a bit of an issue sometimes with persona_state, it's sometimes null for some reason.

 

Code:

Bot.prototype.sendMessage = function(steam_id, send_offline, message) {
    if (this.client.myFriends[steam_id] === undefined || this.client.myFriends[steam_id] === 2 || this.client.myFriends[steam_id] === 4) {
        log.error(this.data.name, 'The message recipient is not a friend.');
        return false;
    }

    this.client.getPersonas([steam_id], (personas) => {
        if (send_offline == false && personas[steam_id].persona_state == 0) {
            log.info(this.data.name, 'The recipient is offline, and the request has disabled offline sending.');
            return false;
        } else {
            // temp. debug
            log.info(this.data.name, 'Name: ' + personas[steam_id].player_name + ', State: ' + personas[steam_id].persona_state);
        }

        log.info(this.data.name, 'Sending the message...');
        this.client.chatMessage(steam_id, message);

        log.success(this.data.name, 'Success!');

        return true;
    });
};

What could cause this? The player it tries to send the message to is a friend, so that's not the issue.

 

Posted

1. Is the bot itself online on Steam? You can't get some persona data unless you're online.

2. Since it appears that you're only sending stuff to friends, there's no need to use getPersonas to get up to date data. There is a property (I think it's users?) which contains up to date persona data for all friends, provided you own state isn't offline. Steam sends updates for friends automatically.

Posted (edited)
I also found personas function sub-optimal compared with users. A very simple example illustrates this below. No need for callbacks.
 
 console.log((client.users[steamIDhere].persona_state==1) ? "online" : "offline");

Nb. Per the documentation we only get data for "users we've encountered or requested data for" so be careful. I would handle it like this.

var userInfo = client.users[steamIDhere];

if(userInfo){
// output info
} 
else {
// no data on user
} 

Disclaimer: I'm a n00b, could be wrong.

Edited by rektbot
Posted

users we've encountered

 

Friends do count as users we've encountered. That said, to be 100% safe it might be better to do it your way and check if the user's data is present and request it if not, but that shouldn't be necessary for friends (then again, this is Steam we're talking about).

Posted

1. Is the bot itself online on Steam? You can't get some persona data unless you're online.

2. Since it appears that you're only sending stuff to friends, there's no need to use getPersonas to get up to date data. There is a property (I think it's users?) which contains up to date persona data for all friends, provided you own state isn't offline. Steam sends updates for friends automatically.

1. Yes, since it succeeded sending the message to other players.

2. client.users doesn't provide the data for all users. I have a user who is a Steam friend (myFriends[steam_id] returns 3, aka friend enum), and when using client.users it doesn't find him. Any idea?

Posted

log.info(this.data.name, 'Recipient: ' + this.client.users[steam_id].player_name + ', Player state: ' + this.client.users[steam_id].persona_state);
Posted

Yeah this.client.users[steam_id] is undefined.

 

Roughly 1 minute after the login, it's called upon an API HTTP request.

 

What happens if you listen for the user data eg. client.on('user'); does their info get emitted?

Have you got an output of this.client.users? Is it definitely missing?

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...