Creating Follow Bot w/ NodeJS

in #utopian-io6 years ago (edited)


image.png

Introduction

This tutorial will show you how to automatically follow users with a bot.

First, you will need to set-up a NodeJS development environment. You can follow along the tutorial at https://steemit.com/javascript/@money-dreamer/nodejs-steemit-bot-tutorial if you need to. That tutorial is a pre-requisite for this tutorial unless if you are already familiar with JavaScript, NodeJS, GIT and the Steemit API.

You can view the full source code at: https://github.com/AdamCox9/Steemit-Follow-Bot

After getting your development environment set-up, copy and paste this code into a file named follow_trending_authors.js and execute it like node follow_trending_authors.js from a terminal as described in the previous tutorial. This will bring in all the functions from the Steem library, set the user/pass and create a log-in session to the Steem blockchain. The followingArray saves the new account so no duplicate following attempts.

var steem = require('steem'); 
var username = 'ENTER_USERNAME_HERE'; 
var password = 'ENTER_PASSWORD_HERE'; 
var wif = steem.auth.toWif(username, password, 'posting');
var followingArray = [];


Let's get the trending categories in our initial call. You can view the data printed to the console to become familiar with it.

steem.api.getState('/trending', function(err, result) {
    console.log(err, result);
    ...
});


The sleep function will time out the script so it does not make requests too fast:

    function sleep(ms) {
      return new Promise(resolve => setTimeout(resolve, ms));
    }


Create a function that will loop over the accounts in the trending tag:

    async function followAccountsInTrending(result) {

        var content = result.content;
        var accounts = result.accounts;

        for(var attributename in accounts) {
            //console.log(attributename+': '+accounts[attributename]);
            var following = accounts[attributename].name;

            let followReq = ['follow']
            followReq.push({follower: username, following: following, what: ['blog']})

            const customJson = JSON.stringify(followReq)

            console.log( followReq );

            followingArray.indexOf(following) === -1 ?
                followingArray.push(following) : console.log('This item already exists');

            steem.broadcast.customJsonAsync(wif, [], [username], 'follow', customJson)
              .then(console.log)
              .catch(console.log)

             await sleep(30000);

             console.log( followingArray );

        }

    }


Create a function that loops over each category:

    async function startFollowAccountsInTrending(result) {
        var trending_tags = result.tag_idx.trending;
        for(var attributename in trending_tags) {
            console.log(attributename+': '+trending_tags[attributename]);

            steem.api.getState('/trending/'+trending_tags[attributename], function(err, result) {
                followAccountsInTrending(result);
            });

            await sleep(30000);

        }
    }


Initialize the function to loop through the categories:

    startFollowAccountsInTrending(result);

Further Development

It will allow you to set parameters to select who to follow. Some of these parameters will be:

  • SBD/STEEM Balance
  • Reputation
  • Number of Followers
  • Number of Following
  • Total Author Rewards
  • Total Curation Rewards

You can view the full source code at: https://github.com/AdamCox9/Steemit-Follow-Bot

Proof of Work:

Previous | Next



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

This post has been moved to my mod queue by my supervisor.

Do you have any plans to expand the bot in future? There is a distinct lack of bots on Steemit that users can watch being built from the ground up to customise for themselves. If you do post more articles on this bot in future, you may consider putting them in the development category - it fits in much better there, and you will get more support from Utopian.io!

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

I am working on my next bot now. I do plan on pushing out more of these tutorials/development projects. I'll add my next submission like this one to the development section!

Thanks! I look forward to working with the Utopian.io community.

Is there a place where I can get a better big picture idea of what this is? It seems amazing, but I'm really curious to hear about the mechanics of it.

It is just an example of following the user accounts in the trending tags.

The idea is that if a user submits a post that makes it to the trending category, then that user should be worthy enough to follow.

Do you have any specific questions about the code?

Thanks for that. I think a cool bot would allow you to follow anybody who has commented upon your post. I don't know if it could somehow exclude bot comments.

Thanks for the awesome tutorial! :)

No problem at all! Expect more to come soon!

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

Achievements

  • WOW WOW WOW People loved what you did here. GREAT JOB!
  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • You are generating more rewards than average for this category. Super!;)
  • This is your first accepted contribution here in Utopian. Welcome!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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

I copied everything to sublime text editor then executed in cmd.
No errors but in reality it didnt follow anyone.

You got a 0.46% upvote from @upme requested by: @money-dreamer.
Send at least 1.5 SBD to @upme with a post link in the memo field to receive upvote next round.
To support our activity, please vote for my master @suggeelson, as a STEEM Witness

You got a 100.00% upvote from @upmewhale courtesy of @money-dreamer!

You got a 11.43% upvote from @minnowvotes thanks to @money-dreamer!

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.033
BTC 64275.05
ETH 3147.49
USDT 1.00
SBD 4.29