p0o / steem-bot

Easy automation on top of Steem blockchain
MIT License
53 stars 40 forks source link

Its commenting nearly some time 5 or some time 10 or working fine don't know whats Wrong #15

Open tomriddle54 opened 6 years ago

tomriddle54 commented 6 years ago

I have Created a Bot for an introduction but sometimes its working fine and some time commenting more than 1 time and he has done 10 comments in one post don't know whats wrong here can any one help here is the code

// No need for the line below if your environment already supports ES6 with JavaScript import/export
require('babel-register');

// change the line below to:
// const SteemBot = require('steem-bot').default
// or:
// import SteemBot from 'steem-bot';
const SteemBot = require('../src/loader').default;

const username = '';
const postingKey = ''; 

const targetUsers = ['kamesh']; rs
const bot = new SteemBot({username, postingKey});

//bot.onComment(handleComment);
bot.onPost(handlePost);

function handlePost(data, responder) 
{
    tagg=data.json_metadata;
    obj = JSON.parse(tagg);

if (obj.tags.indexOf("introduceyourself") > -1)
 {
    console.log("did it ");

     responder.comment('Hi Thank you for #introducingyourself. Im myself quite new in steemit community but I realized that there are few things you could do to have a better start: \n Mostly I invested a little bit in STEEM in order to purchase STEEM POWER and STEEM DOLLARS. Why? Its simply important. Without initial investment it will be very hard for you to build reach here and be noticed.\n \n Im not sure if you ever heard about this site: \n http://steemd.com/@your_username \n Example: https://steemd.com/@example \n Perhaps you know it already :) \n If you will reply to this message (that would allow me to believe that we may develop mutual engagement and help each other) then I will follow you and upvote some of your future posts. \n Cheers and good luck.').catch((err) => {
    console.log('Some error happened while posting comment');

  });

 }

}

bot.start();
TwinkieWInkie commented 6 years ago

Hmm, maybe the compiler can't handel your indentation.

TwinkieWInkie commented 6 years ago

I personally employ getAccountHistory instead of streamOperations and a database to prevent double actions. getAccountHistory is way more reliable(and SteemJS is absolute junk)

Would this be a problem caused by 8fbbef9336efe6b52026408dd86c11a82fd180fc ? @p0o Lol, looking at that commit closely now, naughty naughty fix :p

p0o commented 6 years ago

Can you send the link of the post that the code above put 10 comments?

p0o commented 6 years ago

@TwinkieWInkie You are right, I remember that sometimes after resetting the streamOperations I would see repeated results. However, I say that moving to getAccountHistory is an overkill and would not be a general answer to all use cases.

I think we can change streamOperations to streamBlock to keep the lastest block number somewhere in SteemBot internally to avoid repeated triggers. I'm a little busy these days so if you like to submit a PR with this approach I would be more than happy.

TwinkieWInkie commented 6 years ago

@p0o Seems like a worty challenge, I'll see if I can make some time for that :)

TwinkieWInkie commented 6 years ago

Considering implementing streamBlockNumber/getBlock.

p0o commented 6 years ago

Isn't the blockNumber included in the data received from streamBlock?

TwinkieWInkie commented 6 years ago

Probably. But if it falls behind due to an error, we have an easier way to loop through the missing blocks with this method