Ron Posted February 25, 2017 Report Posted February 25, 2017 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. Quote
Dr. McKay Posted February 25, 2017 Report Posted February 25, 2017 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. Quote
rektbot Posted February 25, 2017 Report Posted February 25, 2017 (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 February 25, 2017 by rektbot Quote
Dr. McKay Posted February 26, 2017 Report Posted February 26, 2017 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). Quote
rektbot Posted February 26, 2017 Report Posted February 26, 2017 ^ yeh. i quoted your wiki on that one. Quote
Ron Posted February 26, 2017 Author Report Posted February 26, 2017 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? Quote
Dr. McKay Posted February 26, 2017 Report Posted February 26, 2017 Please show the code you're using to look them up in client.users. Quote
Ron Posted February 26, 2017 Author Report Posted February 26, 2017 log.info(this.data.name, 'Recipient: ' + this.client.users[steam_id].player_name + ', Player state: ' + this.client.users[steam_id].persona_state); Quote
Dr. McKay Posted February 26, 2017 Report Posted February 26, 2017 this.client.users[steam_id] is undefined? When are you calling this? Very soon after logon? Some time after? Quote
Ron Posted February 27, 2017 Author Report Posted February 27, 2017 Yeah this.client.users[steam_id] is undefined. Roughly 1 minute after the login, it's called upon an API HTTP request. Quote
rektbot Posted February 27, 2017 Report Posted February 27, 2017 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? 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.