vmu123 Posted June 17, 2018 Report Posted June 17, 2018 var SteamUser = require('steam-user'); var SteamTotp = require('steam-totp'); var botFactory = {}; botFactory.buildBot = function (config) { var bot = new SteamUser({ promptSteamGuardCode: false, dataDirectory: "./sentry", singleSentryfile: false }); bot.username = config.username; bot.password = config.password; bot.sharedSecret = config.sharedSecret; bot.games = config.games; bot.messageReceived = {}; bot.on('loggedOn', function(details) { console.log("[" + this.username + "] Logged into Steam as " + bot.steamID.getSteam3RenderedID()); bot.setPersona(SteamUser.EPersonaState.Away); bot.gamesPlayed(this.games); }); bot.on('error', function(e) { console.log("[" + this.username + "] " + e); setTimeout(function() {bot.doLogin();}, 5*60*1000); }); bot.doLogin = function () { this.logOn({ "accountName": this.username, "password": this.password }); } bot.on('steamGuard', function(domain, callback) { if ( !this.sharedSecret ) { var readlineSync = require('readline-sync'); var authCode = readlineSync.question("[" + this.username + "] " + 'Steam Guard' + (!domain ? ' App' : '') + ' Code: '); callback(authCode); } else { var authCode = SteamTotp.generateAuthCode( this.sharedSecret ); console.log("[" + this.username + "] Generated Auth Code: " + authCode); callback(authCode); } }); bot.on("friendMessage", function(steamID, message) { console.log("[" + this.username + "] Message from " + " (" + steamID + ")"+ ": " + message); if ( !this.messageReceived[steamID] ) { bot.chatMessage(steamID, "[Automated Message] I am currently idle."); bot.chatMessage(steamID, "[Mensagem Automática] Estou ausente no momento."); this.messageReceived[steamID] = true; } }); bot.on('vacBans', function(numBans, appids) { if(numBans > 0) { console.log( "[" + this.username + "] " + numBans + " VAC ban" + (numBans == 1 ? '' : 's') + "." + (appids.length == 0 ? '' : " In apps: " + appids.join(', ')) ); } }); bot.on('accountLimitations', function(limited, communityBanned, locked, canInviteFriends) { var limitations = []; if(limited) { limitations.push('LIMITED'); } if(communityBanned) { limitations.push('COMMUNITY BANNED'); } if(locked) { limitations.push('LOCKED'); } if(limitations.length !== 0) { console.log("[" + this.username + "] Limitations: " + limitations.join(', ') + "."); } }); return bot; } module.exports = botFactory; First of all, this is a "bot" to farm hours. I want help with this particular part of the code: bot.on("friendMessage", function(steamID, message) { console.log("[" + this.username + "] Message from " + " (" + steamID + ")"+ ": " + message); if ( !this.messageReceived[steamID] ) { bot.chatMessage(steamID, "[Automated Message] I am currently idle."); bot.chatMessage(steamID, "[Mensagem Automática] Estou ausente no momento."); this.messageReceived[steamID] = true; } });So what i want to do is show in console not only the steamID of the sender, but also its display name on Steam (if there's anyway to also show a nickname I set for the sender that would be nice). I did some research and could get it to work, but then it would break the part where it shows the name of the account that got the message, by doing: bot.on("friendMessage", function(steamID, message) { bot.getPersonas([steamID], function(personas) { var persona = personas[steamID.getSteamID64()]; var name = persona ? persona.player_name : ("[" + steamID.getSteamID64() + "]"); console.log("[" + this.username + "] Message from " + name + " (" + steamID + ")"+ ": " + message); }); if ( !this.messageReceived[steamID] ) { bot.chatMessage(steamID, "[Automated Message] I am currently idle."); bot.chatMessage(steamID, "[Mensagem Automática] Estou ausente no momento."); this.messageReceived[steamID] = true; } }); Any help is appreciated! Quote
SnaBe Posted June 19, 2018 Report Posted June 19, 2018 (edited) Here's how I would get the users display name on any chat message: client.on('friendMessage', function(steamID, message) { //When we get a message show the users steamid64 and display name. client.getPersonas([steamID], function(personas) { var persona = personas[steamID.getSteamID64()]; var name = persona ? persona.player_name : ("[" + steamID.getSteamID64() + "]"); console.log('User: ' + steamID + '\'s display name is ' + name); }); }); An example of using setNickname to set a users nickname with a chat command: //Command for setting a nickname client.on('friendMessage', function(steamID, message) { //If the message meets the requirements. var setNick; if(setNick = message.match(/^!setnick (\d+) (\D+)/i)) { var id = setNick[1]; var nickname = setNick[2]; console.log('User: ' + steamID + ' would like to give user: ' + id + ' the nickname of: ' + nickname); //Set the nickname client.setNickname(id, nickname, function(err) { if(err) { console.log('Error giving the user a nickname.'); } else { console.log('Success setting user ' + id + '\'s nickname as ' + nickname + '.'); } }); } }); I hope this helps! Edited June 19, 2018 by SnaBe vmu123 1 Quote
vmu123 Posted June 19, 2018 Author Report Posted June 19, 2018 (edited) Thanks for the answer @SnaBe! Sorry if I wasn't clear, but unfortunately it doesn't really answer my question :/Good news though, is that I was able to partially solve my problem. I made "name" and "persona" global variables, and did this: bot.on("friendMessage", function(steamID, message) { bot.getPersonas([steamID], function(personas) { persona = personas[steamID.getSteamID64()]; name = persona ? persona.player_name : ("[" + steamID.getSteamID64() + "]"); }); console.log("[" + this.username + "] Message from " + name + " (" + steamID + ")"+ ": " + message); if ( !this.messageReceived[steamID] ) { bot.chatMessage(steamID, "[Automated Message] I am currently idle/away/afk."); bot.chatMessage(steamID, "[Mensagem Automática] Estou ausente no momento."); this.messageReceived[steamID] = true; } });Now I am able to retrieve the username of the person who sent me a message and keeps the "this.username" part working as intended in the console.log function. The only issue is that on the first message that I receive, the "name" variable shows "undefined" in the console log. From the second message onwards, it gets fixed and works as expected. If anyone can help fix this small issue would be great. Edited June 19, 2018 by vmu123 Quote
mcdota Posted July 16, 2018 Report Posted July 16, 2018 do you have the full source code of this project?! Quote
Revadike Posted July 21, 2018 Report Posted July 21, 2018 The code in the OP seems already complete Quote
vmu123 Posted August 11, 2018 Author Report Posted August 11, 2018 do you have the full source code of this project?! Just search "ez steam hours booster" on google, probably will be the first result. 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.