Jump to content


Photo

Trying to make a bot.


Best Answer SnaBe , 22 July 2018 - 04:37 PM

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)
    }
  });
}


Go to the full post


  • Please log in to reply
13 replies to this topic

#1 DanH3r3

DanH3r3

    Newbie

  • Member
  • Pip
  • 8 posts

Posted 21 July 2018 - 06:29 PM

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.


#2 SnaBe

SnaBe

    Member

  • Member
  • PipPip
  • 16 posts
  • LocationDenmark

Posted 22 July 2018 - 08:59 AM

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, 22 July 2018 - 09:13 AM.


#3 DanH3r3

DanH3r3

    Newbie

  • Member
  • Pip
  • 8 posts

Posted 22 July 2018 - 12:56 PM

Thank you so much!


Edited by DanH3r3, 22 July 2018 - 01:38 PM.


#4 DanH3r3

DanH3r3

    Newbie

  • Member
  • Pip
  • 8 posts

Posted 22 July 2018 - 01:20 PM

(DELETED)


Edited by DanH3r3, 22 July 2018 - 04:05 PM.


#5 SnaBe

SnaBe

    Member

  • Member
  • PipPip
  • 16 posts
  • LocationDenmark

Posted 22 July 2018 - 01:41 PM

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, 22 July 2018 - 01:55 PM.


#6 DanH3r3

DanH3r3

    Newbie

  • Member
  • Pip
  • 8 posts

Posted 22 July 2018 - 02:59 PM

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, 22 July 2018 - 03:03 PM.


#7 SnaBe

SnaBe

    Member

  • Member
  • PipPip
  • 16 posts
  • LocationDenmark

Posted 22 July 2018 - 03:03 PM

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, 22 July 2018 - 04:16 PM.


#8 DanH3r3

DanH3r3

    Newbie

  • Member
  • Pip
  • 8 posts

Posted 22 July 2018 - 03:08 PM

It can post comments, In normal style:

 

 

Attached Files



#9 SnaBe

SnaBe

    Member

  • Member
  • PipPip
  • 16 posts
  • LocationDenmark

Posted 22 July 2018 - 03:18 PM

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.



#10 DanH3r3

DanH3r3

    Newbie

  • Member
  • Pip
  • 8 posts

Posted 22 July 2018 - 03:25 PM

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, 22 July 2018 - 03:27 PM.


#11 SnaBe

SnaBe

    Member

  • Member
  • PipPip
  • 16 posts
  • LocationDenmark

Posted 22 July 2018 - 03:32 PM

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, 22 July 2018 - 03:34 PM.


#12 DanH3r3

DanH3r3

    Newbie

  • Member
  • Pip
  • 8 posts

Posted 22 July 2018 - 03:35 PM

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, 22 July 2018 - 04:04 PM.


#13 SnaBe

SnaBe

    Member

  • Member
  • PipPip
  • 16 posts
  • LocationDenmark

Posted 22 July 2018 - 04:37 PM   Best Answer

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, 22 July 2018 - 04:39 PM.


#14 DanH3r3

DanH3r3

    Newbie

  • Member
  • Pip
  • 8 posts

Posted 24 July 2018 - 01:13 PM

Thank you!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users