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!