___  ___    _ _    _  _ _____   _____
 / __|/ _ \  | | |  | || |_ _\ \ / / __|
| (_ | (_) | |_  _| | __ || | \ V /| _|
 \___|\___/    |_|  |_||_|___| \_/ |___|

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

How to create a tag-specific auto-comment STEEM bot Using NODEJS

BY: @akintunde | CREATED: Nov. 4, 2018, 3:05 p.m. | VOTES: 34 | PAYOUT: $14.94 | [ VOTE ]

Repository

https://github.com/steemit/steem-js

What Will I Learn?

Requirements

Difficulty

Tutorial Contents

Ever since I joined steem, I have seen a lot of bots auto-comment on blog posts, when the authors use a particular community tag. This is done to familarize such a user with the activities of the community that uses such a tag. It is usually like this below. This tutorial explains how to make such a bot.

[IMAGE: https://cdn.steemitimages.com/DQmekqANjeetZEUEEsJTgcGci97rGkzgJDGi6rTv8RQjYxX/2.PNG]

After satisfying all the requirements above, please follow the steps below:

lets get down to the code

//Declarations And Assignment
var steem = require('steem');
const username = 'username'; //replace with your username
var tag = 'utopian-io'; //the tag to be inspected
var tagFetchLimit = 10; //limit of posts to be fetched each time
const wif = '5Jcnjhjjjhzjighgi7trdDSBuTQbdURKmxMtbUzioioitj9bfqN'; // replace with your your posting key, make sure this is just your posting key, your password is not needed
 ```

Note: The First Line `var steem = require('steem'); ` is for importing steem module while assigning it to the variable name `steem`. 

The rest of the code above have explanatory comments on the side, please read.

- Now, use the `steem.api` command for getting recently created posts. There are other commands for getting posts on the trending or hot section but using the created section makes the commenting come in early and helps to avoid missing out on post. This is shown in the code below


```javascript
steem.api.getDiscussionsByCreated({"tag": tag, "limit": tagFetchLimit}, function(err, result) {
         //YOur Code
});
 ```

The  `err` and `result` variable is for returning the error result (if  the command fell through) and the success result (if it worked out fine).

- Now let's manipulate the list of posts that will come through to pick the ones that are worthy of commenting. This is where the real work is done. Insert the following codes in `//YOUR CODE` section above.

```javascript
  var textResult = JSON.stringify(result);
   var arrayResult = JSON.parse(textResult);

NOTE: You can try to test this code at this point to see how the results is , you can do this with console.log(arrayResult). I will suggest you leave that until the whole tutorial is done.

 arrayResult.forEach( 
           function (value,key){
                  setTimeout(function(){
                        console.log(3000*key+'seconds');
                        steem.api.getContentReplies(value['author'], value['permlink'] , function (commentCheckErr,commentCheckResult) {
                              var CCtextResult = JSON.stringify(commentCheckResult);
                              var CCarrayResult = JSON.parse(CCtextResult);

                              var CC = CCarrayResult.filter(function(person) {
                                  return person.author == username;
                                });

                              if (CC == ''){

                                    jsonMetadata = {
                                        community: 'tutocity',
                                        purpose: 'testrun',
                                        app: 'NAPP/0.1'
                                    };

                                    var comment_permlink = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '').toLowerCase();

                                    content = '@'+value['author']+', thank you for suing the tag';

                                    steem.broadcast.comment(wif, value['author'], value['permlink'], username, comment_permlink , '', content, jsonMetadata, function(err, result) {
                                      console.log(err, result);
                                    });
                              }
                         });                  
                }, 3000*key);

var CCtextResult = JSON.stringify(commentCheckResult); var CCarrayResult = JSON.parse(CCtextResult); converts the json result to a string and then to an array so we can search if username has commented on the post before. The searching is done with the filter function which only works on arrays and the result of the checking is assigned to CC as shown in the code: var CC = CCarrayResult.filter(function(person) {return person.author == username; });

All the above explanations were made so you can understand how the code works, the complete code can be found here.

NOTE: You can run this code as a cron job to make the bot fully independent at 30 minutes interval each day. Whereas , you can also run the bot yourself at certain time of the day when you know your users post the most.

Proof of Work Done

https://github.com/Akintunde102/Steem-Comment_Bot/blob/master/index.js

TAGS: [ #utopian-io ] [ #tutorials ] [ #steem ] [ #steemdev ]

Replies

@portugalcoin | Nov. 4, 2018, 9:34 p.m. | Votes: 11 | [ VOTE ]

Thank you for your contribution @akintunde.
We've been reviewing your tutorial and suggest the following points below:

  • Provide better quality, clearer, and more professional screenshots.

  • Use the code markup to place your code. It is easier to read the code. Link

  • Put your code ident, it is important the code be indented to make it easier to read the code.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.

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

@akintunde | Nov. 4, 2018, 10:30 p.m. | Votes: 0 | [ VOTE ]

Provide better quality, clearer, and more professional screenshots.

  • The screenshots has been replaced with better ones

Use the code markup to place your code. It is easier to read the code.

  • The code markup has been improved upon

Put your code indent, it is important the code be indented to make it easier to read the code.

  • The code has been indented , you can check it now.
@utopian-io | Nov. 7, 2018, 6:06 p.m. | Votes: 0 | [ VOTE ]

Thank you for your review, @portugalcoin! Keep up the good work!

@steem-ua | Nov. 4, 2018, 10:29 p.m. | Votes: 0 | [ VOTE ]

Hi @akintunde!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

@utopian-io | Nov. 4, 2018, 10:32 p.m. | Votes: 0 | [ VOTE ]

Hey, @akintunde!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>