p0o / steem-bot

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

Change target variable while the bot is running #21

Closed phaitonican closed 6 years ago

phaitonican commented 6 years ago

Hello p0o, I really appreciate you work. I have a database, where I update the targets. However, do I have the problem to update the targetUsers variable in for example the .onPost() function while the bot is already running. You maybe got an Idea? Thanks!

p0o commented 6 years ago

Hi @phaitonican , thank you very much.

I believe you can do it by handling that part yourself. Something like this:

let targetUsers = ['p0o' 'ned'];
bot.onComment(handleComment);

function handleComment(data, responder) {
  // change it on the fly or appoint to a function which synchronously returns the latest changes
  targetUsers = ['p0o'];

  // exit if author is not in targetUsers
  if(!targetUsers.includes(data.author)) return;

  console.log('user %s commented!', data.author);
  console.log(data.body);

  responder.comment('Hi there! I just upvoted you using SteemBot JavaScript library!');
  responder.upvote(); // 100% upvote

}

Let me know if it fixes your problem so I can close this issue.

phaitonican commented 6 years ago

oh i made it work with it, thank you. So it refreshes the variable every time someone comments. Tricky workaround thank you!