Jump to content
McKay Development

Recommended Posts

Posted

Hey guys, I'm trying to make a bot that posts comments every 3 secs on a profile. I'm new to JS, I don't know so much and don't know how to do this.

I want to make a log-on to steam, then my bot needs to post a comment like 5 times to profile, waiting 3 secs before posting again.
Please help.
Posted (edited)

Here's a how I would post a comment to a profile using Steamcommunitys postUserComment().

//Custom function to post and log a comment to a Steam profile
function commentOnUserProfile(steamID, message) {
  community.postUserComment(steamID, message, function(err) {
  	if(err) {
  	  console.log(err);
  	} else {
  	  console.log('Successfully commented: ' + message)
  	}
  });
}

When you know which profile to post on (Steamid64) and the messsage, you can call the function like so:

var user = "76561198089922529";
var message = "What do you think of this comment?";
commentOnUserProfile(user, message);

To post every 3 seconds you would have to learn about setInterval etc.

 

Creating the log-on shouldn't be hard, there's plenty of examples on the wiki page for newcomers like you.

 

I hope this helps!

Edited by SnaBe
Posted (edited)

You're using steamcommunity to log on instead of steam-user.

 

Make a new instance with steam-user, name it client or user.

const SteamUser = require('steam-user');
const client = new SteamUser();

Add your login details to the logOnOptions object.

const logOnOptions = {
  accountName: config.username, 
  password: config.password
}; 

After that you can use your client instance to log on to Steam.

client.logOn(logOnOptions);

And when your client emits the event loggedOn, you can console log it loggin on to Steam.

client.on('loggedOn', function(details) {
  console.log('Bot ' + client.steamID.getSteamID64() + ' successfully logged into Steam!');
  client.setPersona(SteamUser.Steam.EPersonaState.Online, "Bot online!"); 
  client.gamesPlayed(440); 
});

And if there's an error login on, you can log that error to the console aswell.

client.on('error', function(err) {
  console.log('Error: ' + err);
});

I hope this solves your current issue!

Edited by SnaBe
Posted (edited)

Thank you a lot. The last problem I have.

The code is:

function commentOnUserProfile(steamID, message) {
    community.postUserComment(steamID, message, function(err) {
        if(err) {
          console.log(err);
        } else {
          console.log('Successfully commented: ' + message)
        }
    });
}

var user = config.toWho;
var message = config.comment;
commentOnUserProfile(user, message);

And the error I get is:
(First my settings was comments - private-only, but i changed it to public and I get this error)

Error: The settings on this account do not allow you to add comments.
    at SteamCommunity.<anonymous> (D:\Websites\SteamBot\node_modules\steamcommun
ity\components\users.js:154:13)
    at Request._callback (D:\Websites\SteamBot\node_modules\steamcommunity\compo
nents\http.js:67:15)
    at Request.self.callback (D:\Websites\SteamBot\node_modules\request\request.
js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (D:\Websites\SteamBot\node_modules\request\request.js
:1157:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (D:\Websites\SteamBot\node_modules\request\re
quest.js:1079:12)
    at Object.onceWrapper (events.js:313:30)
Edited by DanH3r3
Posted (edited)

The settings on this account do not allow you to add comments. Your bot can't post a comment on the users profile due to their privacy settings I believe.

Edited by SnaBe
Posted

Their profile must be set to allow comments, and even if they set it to allow comments, they may not allow it from people not on their friend's list.

Posted (edited)

Yea the comments are on public. But it tries to post the comment before the login. How to make to post the comment after login.

This is the full code:

const SteamCommunity = require('steamcommunity');
let community = new SteamCommunity();
const config = require('./config.json')

var SteamUser = require('steam-user');
var client = new SteamUser();

client.logOn({
    "accountName": config.username,
    "password": config.password,
});

client.on('loggedOn', function(details) {
console.log("Logged into Steam as " + client.steamID.getSteam3RenderedID());
client.setPersona(SteamUser.EPersonaState.Online);
});

client.on('error', function(e) {
    console.log('An error ocurred:')
    console.log(e);
});


client.on("friendMessage", function(steamID, message) {
console.log("Friend message from " + steamID+ ": " + message);
if (message == "Ping") {
client.chatMessage(steamID, "Pong");
console.log("Send back: Pong");
}

else {
client.chatMessage(steamID, config.greetMsg);
console.log("Send back the standard reply");
}

});

function commentOnUserProfile(steamID, message) {
community.postUserComment(steamID, message, function(err) {
if(err) {
console.log(err);
} else {
console.log('Successfully commented: ' + message)
}
});
}

var user = config.toWho;
var message = config.comment;
commentOnUserProfile(user, message);

Edited by DanH3r3
Posted (edited)

The comment function will be called before the loggedOn is emitted successfully, that's how Javascript works. You can add a callback to ensure no function or method is called before the bot is logged in.

Edited by SnaBe
Posted (edited)

The profile comments are on public, account is premium and I get the error. How to fix it?

Error: The settings on this account do not allow you to add comments.
    at SteamCommunity.<anonymous> (D:\Websites\SteamBot\node_modules\steamcommun
ity\components\users.js:154:13)
    at Request._callback (D:\Websites\SteamBot\node_modules\steamcommunity\compo
nents\http.js:67:15)
    at Request.self.callback (D:\Websites\SteamBot\node_modules\request\request.
js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (D:\Websites\SteamBot\node_modules\request\request.js
:1157:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (D:\Websites\SteamBot\node_modules\request\re
quest.js:1079:12)
    at Object.onceWrapper (events.js:313:30)
Edited by DanH3r3
Posted (edited)

Here's how I would do it.

const config = require('./config.json');

const SteamUser = require('steam-user');
const SteamCommunity = require('steamcommunity');

const client = new SteamUser();
const community = new SteamCommunity();

const user = "76561198089922529";
const message = "Hey bud.";
//Our account details
const logOnOptions = {
  accountName: config.account.username, 
  password: config.account.password
};
//Try to log on
client.logOn(logOnOptions);
//We logged on
client.on('loggedOn', function(details) {
  console.log('Bot ' + client.steamID.getSteamID64() + ' successfully logged into Steam!'); 
  client.setPersona(SteamUser.Steam.EPersonaState.LookingToTrade, config.bot.displayName); 
  client.gamesPlayed(config.tf2.ID); 
});
//Error login to Steam
client.on('error', function(err) {
  console.log('Error: ' + err);
});
//Got web session and cookies
client.on('webSession', function(sessionID, cookies) {
  console.log('Got web session from Steam.');
  community.setCookies(cookies);
  //We can now post a comment
  commentOnUserProfile(user, message);
});
//Custom function to post and log comments on steam profiles
function commentOnUserProfile(steamID, message) {
  community.postUserComment(steamID, message, function(err) {
    if(err) {
      console.log(err);
    } else {
      console.log('Successfully commented: ' + message)
    }
  });
}


Edited by SnaBe

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