Jump to content
McKay Development

Recommended Posts

Posted
    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!

Posted (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 by SnaBe
Posted (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 by vmu123
  • 4 weeks later...
  • 3 weeks later...

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