Bot Build #2 - Auto Follow Bot

in #utopian-io6 years ago (edited)

What Will I Learn?

  • Build Auto Follow Bot that follows by trending tag every 5 minutes

Requirements

  • Node.JS, Here
  • Steem Package (Install: npm install steem --save)

Difficulty

  • Basic

Tutorial Contents

In this tutorial, you will learn how to make auto follow bot that follows every 5 minutes users by trending tag.

Curriculum

The Tutorial

first, we want a function to make the follow,
create a function called AutoFollow, we need the function to set a timer for every 5 minutes.

function AutoFollow(name, tag, wif, limit){

}

name - the follower username, the username which sends the follow.

tag - the tag to get the posts from.

wif - the private posting wif key to send the follow.

limit - the limit number of the posts.

now let's get the posts and make a loop

  steem.api.getDiscussionsByTrending({tag: tag, limit: limit}, function(err, result){
  if(!!err)
  throw err;
  result.forEach(function(row){

  });

getDiscussionsByTrending - this function will give the recent trending posts.

tag - the tag we get the posts from.

limit - the limit of the posts we get.

result.forEach - making a loop for the posts.

now we need some variables and a json variable

  var follower = name;
  var following = row.author;
  var json = JSON.stringify(
  ['follow', {
  follower: follower,
  following: following,
  what: ['blog']
  }]);

follower - the follower username, the user who sends the follow.

following - the user you going to follow.

json - json variable for the follow function.

if we done all correctly just broadcast the follow with customJson function

  steem.broadcast.customJson(wif, [], [follower], 'follow', json, function(err, result) {
  console.log(err, result);
  });

wif - the wif private posting key.

follower - the follower name (you).

follow - the role of the customJson function.

json - the json variable that contains the follower name, following name and the type of blog.

now we want to send the function every 5 minutes (or any time else)

setTimeout(function(){AutoFollow("lonelywolf", "dtube", "XXXX", 1)}, 5*60*1000);

lonelywolf - the username.

dtube - the tag.

XXX - wif key (private posting key).

1 - the limit of posts.

5*60*1000 - 5, minutes. 60, seconds. 1000, milliseconds.

the full function code

function AutoFollow(name, tag, wif, limit){
  steem.api.getDiscussionsByTrending({tag: tag, limit: limit}, function(err, result){
  if(!!err)
  throw err;
  result.forEach(function(row){
  var follower = name;
  var following = row.author;
  var json = JSON.stringify(
  ['follow', {
  follower: follower,
  following: following,
  what: ['blog']
  }]);
  steem.broadcast.customJson(wif, [], [follower], 'follow', json, function(err, result) {
  console.log(err, result);
  });
  });
  setTimeout(function(){AutoFollow("lonelywolf", "dtube", "XXX", 1)}, 5*60*1000);
  });
}

if we done all correctly we can send the function when the script starts

AutoFollow("lonelywolf", "dtube", "XXX", 1);

and we will see that result

image.png

(the script run for 15 minutes now, so I followed 3 users already)

text result

null { id: 'f634e79b3264ab96f2942ad4f03442e97fcf3425',
  block_num: 21432131,
  trx_num: 24,
  expired: false,
  ref_block_num: 1835,
  ref_block_prefix: 914276676,
  expiration: '2018-04-10T02:19:15',
  operations: [ [ 'custom_json', [Object] ] ],
  extensions: [],
  signatures:
  [ '20337c080cca9b4be0d4fff05eb34974579f90ac28b50d1c7609df14df13737e9710336ebd5536e6e9e900eebe4772e50abdfa73528d808207886f39c5d0b734dd' ] }
null { id: '89b09e78962e84f301b115ac149335a4f2f68468',
  block_num: 21432231,
  trx_num: 58,
  expired: false,
  ref_block_num: 1937,
  ref_block_prefix: 3893587431,
  expiration: '2018-04-10T02:24:18',
  operations: [ [ 'custom_json', [Object] ] ],
  extensions: [],
  signatures:
  [ '207267a2841addf839e203c1b3135ba0b08726fd5f16fd20b08f71f8b850fdee3947a9478661a107ad76bc00835867dee8a7c506f8e71562c7b910fdaa61380975' ] }
null { id: 'b1632efd8e4d88ec812d127ed938a667a8211c00',
  block_num: 21432338,
  trx_num: 10,
  expired: false,
  ref_block_num: 2043,
  ref_block_prefix: 980857,
  expiration: '2018-04-10T02:29:36',
  operations: [ [ 'custom_json', [Object] ] ],
  extensions: [],
  signatures:
  [ '2013c002f7e4d0ba7f2d8ba32fbb3d41a7374095ebf6e84becf31accc2c2dbe4825ee60ae981b3a2f97812ffe1ecca483ab6968a08aee787220b73156e46245486' ] }

steemd results

image.png

(tested few times so there is more then 3 follows)



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hi @scipio the contribution got back to the review state, I think because the new system. Hope you can re-review it. Thanks

Re-reviewed it ;-)

Thank you for the contribution. It has been approved.

You can contact us on Discord. [utopian-moderator]


Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Great but look that the post isn't in approved state

Wonderful, I am working with a bot application using angularjs and sql server.
Seems this article will help me to play with steemjs.
Thanks
😊😊😊

Hey @lonelywolf I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Utopian Witness!

Participate on Discord. Lets GROW TOGETHER!

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.16
TRX 0.15
JST 0.028
BTC 57647.49
ETH 2274.93
USDT 1.00
SBD 2.50