Giter Club home page Giter Club logo

steem-bot's Introduction

SteemBot

SteemBot provides real-time automation on top of Steem blockchain with a very simple API. You can use it to quickly bootstrap an automated task with Steem without having much understanding about the node's mechanism and tricky API.

This library is basically an abstraction on top of the official JavaScript library of Steem, called Steem-js which is somehow a low-level API and is not easy to be used for newcomers of the platform.

Installation

NPM package is available. You should be fine to use it with any supported node-js version but feel free to report any issue:

npm install steem-bot --save

Then include the package on top of your file:

const SteemBot = require('steem-bot').default
// or if your environment supports import/export:
import SteemBot from 'steem-bot';

How to use?

Start with defining the constructor. You should define the constructor based on the type of operations you need to perform. If you are just observing the blockchain no argument is required. But if you need to post anything you would need to define your username and private postingKey. Also you would need to define your activeKey if you need to transfer STEEM or SBD.

// monitoring all the deposits to poloniex and bittrex accounts real-time
const targetUsers = ['poloniex', 'bittrex'];

const bot = new SteemBot();
// or with username and keys:
// const bot = new SteemBot({username, postingKey, activeKey});

bot.onDeposit(targetUsers, (data) => {
  console.log(data); // { from: 'p0o', to: 'poloniex', amount: '10 STEEM', memo: 'GbH4HgV35Ygv'}
});

// this function will start the bot and keep it open
bot.start();

Examples

Here you can find some sample codes of things you can do with SteemBot.

API

The API is very consistent and follow the same set of rules.

Events

SteemBot constructor after declaration will provide some methods as events which you can use to trigger different behaviors for different users. The first argument of every event method is always targetUsers and the second one is handler function. If you omit targetUsers the first one will be handler function.

Events are listed below:

onDeposit

Used to trigger deposits. Examples:

// getting all the deposits for user "bittrex"
bot.onDeposit('bittrex', eventHandler);

// getting all the deposits for users "bittrex" and "poloniex"
bot.onDeposit(['bittrex', 'poloniex'], eventHandler);

// getting all the deposits from all users
bot.onDeposit(eventHandler);

onPost

Used to trigger all the posts. You can use it for one user, many users or all users of the platform similar to the deposit example above.

// getting all the posts submited by user "bittrex"
bot.onPost('bittrex', eventHandler);

// getting all the posts submitted from users "bittrex" and "poloniex"
bot.onPost(['bittrex', 'poloniex'], eventHandler);

// getting all the posts from all users
bot.onPost(eventHandler);

onComment

Used to trigger comments. You can use it for one user, many users or all users of the platform similar to the deposit example above.

// getting all the comments submited by user "bittrex"
bot.onComment('bittrex', handler);

// getting all the comments submitted from users "bittrex" and "poloniex"
bot.onComment(['bittrex', 'poloniex'], handler);

// getting all the comments from all users
bot.onComment(handler);

targetUsers

Could be simply one string with the username of a Steem account or an array of usernames. Omitting this parameter will require the event to trigger all users.

eventHandler

The handler function (as stated above as "handler") is a function with 2 arguments. This function will be examined for every block (each 3 seconds) and if is triggered by your hooks will be executed with 2 parameters. Data and Responder.

Data

Data is the first parameter of eventHandler and is an object directly returned from blockchain's streamOperations API. The contents of this object is different based on the event and would provide the data regarding the block's operation related to your event.

Responder

Responder is the second parameter of eventHandler and is a very powerful class which will help you to directly act on your events without doing all the low-level operations. For example you can easily use Responder to comment on the data received from your event, upvote or downvote them.

You can use responder like this:

bot.onPost(handlePost);

function handlePost(data, responder) {
  responder.upvote();
  responder.comment(`Hi @${data.author} there! I just upvoted you using SteemBot JavaScript library!`);
}

bot.start();

This snippet will upvote on any new post on Steem and leave a comment in that particular post (better not to execute it!)

Currently Responder provide you these methods to use:

Responder.comment(message)

  • message is a string containing your comment text.
  • Returns: bluebird standard promise

Responder.upvote(votingPercentage)

  • votingPercentage: is a float or string to indicate the voting percentage from 0 to 100%. If omitted default is 100%.
  • Returns: bluebird standard promise

Responder.downvote(votingPercentage)

  • votingPercentage: is a float or string to indicate the flagging percentage from 0 to 100%. If omitted default is 100%.
  • Returns: bluebird standard promise

Responder.sendSbd(amount, memo)

  • amount: is a float or string to indicate the amount of SBD to be sent from your account. You need to define the activeKey to SteemBot before using this feature.
  • memo: a string to be sent as memo.
  • Returns: bluebird standard promise

Responder.sendSteem(amount, memo)

  • amount: is a float or string to indicate the amount of STEEM to be sent from your account. You need to define the activeKey to SteemBot before using this feature.
  • memo: a string to be sent as memo.
  • Returns: bluebird standard promise

Memo Operations:

It's a common practice for bots (like randowhale, minnowbooster etc) to use a Steemit link in memos while depositing so the bot can use the link for any purpose (sending money or commenting). However, extracting the memo and performin low-level operations to use it is a headache, so SteemBot is providing helper methods to facilitate this process.

Responder.commentOnMemo(message) Works similiar to Responder.comment but you can use it on deposit events when users include steemit link as memo. See randowhale example for more info.

Responder.upvoteOnMemo(votingPercentage) Works similiar to Responder.upvote but you can use it on deposit events when users include steemit link as memo. See randowhale example for more info.

Responder.downvoteOnMemo(votingPercentage) Works similiar to Responder.downvote but you can use it on deposit events when users include steemit link as memo. See randowhale example for more info.

Further development

This package is still under development. Feel free to use it and feedback using github issues.

Versioning

This package is using Semantic versioning to make sure changes in API will not break your bots.

steem-bot's People

Contributors

p0o avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

steem-bot's Issues

Delegate function

Hi again,

I needed the delegate function in my bot, I was asking if I could try to implement it by myself, but I had no idea how to start and need to work me in a little, since im pretty newbie.
So I see the .onComment etc.. functions, guess I need to start there somehwere. Using the steem js library...
So thanks if you can help out otherwise I close this!

SyntaxError: Identifier 'SteemBot' has already been declared

I used your randowhale example code and when i execute the bot using the node . command I get the following error. Can you point me in the right direction?

const SteemBot = require('../dist/loader').default;
^

SyntaxError: Identifier 'SteemBot' has already been declared
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:152:10)
at Module._compile (module.js:605:28)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Function.Module.runMain (module.js:682:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:613:3

TypeError: Cannot read property 'catch' of undefined.

When I tried to run your script errorHandling.js I ran into this error:

TypeError: Cannot read property 'catch' of undefined
    at Object.<anonymous> (C:\steemUpvoteBot\upvote-bot\errorhandle.js:30:12)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

It seems like the catch() in the last line is not working properly, while the one after responder.comment() is working just fine.

Why is in the responder no category

HI, I think it is important to add the category from the targetPost like this

var Responder = function () {
  function Responder(_ref) {
    var targetUsername = _ref.targetUsername,
        targetPermlink = _ref.targetPermlink,
        transferMemo = _ref.transferMemo,
        responderUsername = _ref.responderUsername,
        postingKey = _ref.postingKey,
        activeKey = _ref.activeKey,
->    targetCategory = _ref.targetCategory;

    _classCallCheck(this, Responder);

    this.targetUsername = targetUsername;
    this.targetPermlink = targetPermlink;
    this.transferMemo = transferMemo;
    this.responderUsername = responderUsername;
    this.postingKey = postingKey;
    this.activeKey = activeKey;
->this.targetCategory = targetCategory;
  }

How can I implement this?

PS: Very nice bot for beginners, Thanks

Error: Something went wrong with streamOperations method of Steem-js

So i have been trying to create something using steem-bot. It's working fine, but crashing randomly probably when checking for new deposits, and this is what i'm getting.

1|index | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
1|index | Error: Something went wrong with streamOperations method of Steem-js
1|index | at /root/steemBot/node_modules/steem-bot/dist/core.js:116:17
1|index | at /root/steemBot/node_modules/steem/lib/api/index.js:374:21
1|index | at /root/steemBot/node_modules/steem/lib/api/index.js:347:21
1|index | at /root/steemBot/node_modules/steem/lib/api/index.js:320:21
1|index | at /root/steemBot/node_modules/steem/lib/api/index.js:291:21
1|index | at tryCatcher (/root/steemBot/node_modules/bluebird/js/release/util.js:16:23)
1|index | at Promise._settlePromiseFromHandler (/root/steemBot/node_modules/bluebird/js/release/promise.js:512:31)
1|index | at Promise._settlePromise (/root/steemBot/node_modules/bluebird/js/release/promise.js:569:18)
1|index | at Promise._settlePromise0 (/root/steemBot/node_modules/bluebird/js/release/promise.js:614:10)
1|index | at Promise._settlePromises (/root/steemBot/node_modules/bluebird/js/release/promise.js:689:18)
1|index | at Async._drainQueue (/root/steemBot/node_modules/bluebird/js/release/async.js:133:16)
1|index | at Async._drainQueues (/root/steemBot/node_modules/bluebird/js/release/async.js:143:10)
1|index | at Immediate.Async.drainQueues (/root/steemBot/node_modules/bluebird/js/release/async.js:17:14)
1|index | at runCallback (timers.js:800:20)
1|index | at tryOnImmediate (timers.js:762:5)
1|index | at processImmediate [as _immediateCallback] (timers.js:733:5)

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

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();



create onVote event, similar to onComment, onPost...

It would be nice to have an a bot.onVote event, to make it easy to replicate the upvotes of someone else. This would be convenient for those who prefer to store their STEEM on another account for safety, but who still want their voting power to serve those they choose to upvote from their main account.

targetUsers

Hello again,
I followed your code and change targetUsers with my DB function. if I change 'targetUsers' with another value, it likes the post. otherwise nothing happens. even though targetUsers has a value... You maybe got an idea? I just read you can't connect to MongoDB synchronously, so there is no possible way?

function cb(err, results) {
  if(typeof results !== 'undefined') {
    targetUsers = results;
    console.log(targetUsers); //works!
  }
}

function getMembers(cb) {

  const results = [];

  mongodb.MongoClient.connect(uri, function(err, client) {

    if(err) {
      return cb(err);
    }

    let db = client.db('members');

    let members = db.collection('members');

    members.find({}).forEach(function(row) {
      results.push(row.member);
    },

    function(err) {

      cb(err, results);

    });
    client.close();
  });
}

bot.onPost(targetUsers, handlePost);
bot.onComment(handleComment);

function handlePost(data, responder) {
  responder.upvote();
}
function handleComment(data, responder) {
  getMembers(cb);
}

Resteem others' posts with this API?

I've been developing a bot with this package for a while, but I can't figure out how to resteem a user's post. I'm currently doing it with another Python Script, is there any chance I can integrate the two into one script?
Thanks for helping ;)

Where can you read about the available actions?

I'm trying to create a library like this but for the Go language, but I can not find the documentation that tells me what parameters to pass to the API to perform actions such as writing a post or a comment.

I want to Get all real time post with tag introduceyourself

Hello I am new to js I was Planning To Get The All post by tag not by the user I Tryed to add
this code in src/respounder.js

function getTags(author, tag) {
  return steem.api.getTrendingTags(afterTag, limit);
}

and try to use it in
voter.js
but bad luck its not working
Any One here Can Tell me Insterd of user how can i get tags

Change target variable while the bot is running

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!

How can we get user reputation in json data

Hello is there any way to get user reputation in json data like we are getting this

{ parent_author: '',
  parent_permlink: 'photo',
  author: 'prithvee',
  permlink: 'last-day-of-class-2nd',
  title: 'Last Day of Class 2nd',
  body: '![P.jpg](https://steemitimages.com/DQma643oshqxm7C9bD9fNckXBhiv4ESZWyrt
WH8vNsfKTCs/P.jpg)\n\nIt was the last day memory photograph of my class 2nd when
 I received my result and promoted to next level, I mean 3rd class. Most happy m
oments of my life and proud of my father.',
  json_metadata: '{"tags":["photo","photography","child","happiness","lovefinder
"],"image":["https://steemitimages.com/DQma643oshqxm7C9bD9fNckXBhiv4ESZWyrtWH8vN
sfKTCs/P.jpg"],"app":"steemit/0.1","format":"markdown"}' 

Proposal to Draft a Privacy Policy and About Us page for Steembot

Greetings,

I am a copywriter, and have contributed to many App and Platforms using my writing skills.

A privacy policy is a document that states an App/site potential collection/use of visitors /users data.
About us normally found on the landing page gives a brief description of the App.

I am willing to contribute to the development and stability of your platform through documentation some of which will provide you with legal indemnity.

Your response is anticipated.

Thank you.

@pope1995 on steemit
@pope1995#6757 on discord

Follow Option

Hi,

i really like your work here. thank you!
I'm searching for a option to follow a user. is it possible to bring this in an update?

some use cases: auto-follow on deposit, auto-follow of all own followers, auto-unfollow if someone unfollows, etc....

thanks for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.