Easy check voting power in discordapp

0

Hi all, did you coding discord bot recently?
I will share with you some code to check voting power, the credit for this code belongs to @mahdiyari.

Required

All you need for running this bot is:

  1. node.js, you can verify by this command node -v
  2. npm, can verify by this command npm -v
  3. discord bot user and token,
    Ex. MzYxNDE5NDgwNDc3MzM1NTUy.DNWyyA.oAbz0uzK9ILWt6PNs1ebu9jpeXX

Installing and using

  1. clone bot from GitHub:git clone git@github.com:baroesa/vp.git
  2. change dir to vp, cd vp
  3. run npm install, npm install
  4. invite your bot to your own server by click this link, https://discordapp.com/oauth2/authorize?client_id=3614194804773355524&scope=bot&permissions=0 don’t forget to change client id, whit your bot client id.
  5. test running : node index.js
  6. if everything ok your bot is on.

Code

const Eris = require("eris");
var steem = require("steem");
var bot = new Eris("MzYxNDE5NDgwNDc3MzM1NTUy.DNWyyA.oAbz0uzK9ILWt6PNs1ebu9jxXX"); // Your bot token here
var regex=/(\$vp)+(\ )/;
bot.on("ready", () => {console.log('VP-CHECK START!');}); //when it is ready
bot.on("messageCreate", (msg) => {
    console.log(msg.content);
if(msg.content.match(regex)){
var user = msg.content.replace(msg.content.match(regex)[0],'');
    steem.api.getAccounts([user], function(err, result) {
                if(result){
                    var userData=result[0];
                    var voting_power = userData.voting_power;
                    var last_vote_time = userData.last_vote_time;
                    var lastVoteTime = new Date(last_vote_time).getTime(); // get lastVoteTime
                    var now = new Date(); // get local time
                    var offset = now.getTimezoneOffset(); // define offset
                    var nowUtcTime = now.getTime() + (offset * 60000); // get UTC time
                    var powerNow = (Math.floor((nowUtcTime - lastVoteTime)) / 43200) + voting_power; 
                    if (powerNow > 10000) powerNow = 10000; // maximum 100%
                    powerNow = (powerNow / 100).toFixed(2); //  rounding to exactly four decimals
        setTimeout(function(){bot.createMessage(msg.channel.id,'Voting Power `@'+user+ '`= ' +powerNow+'%');},1000);
               }
                if(err){
                    setTimeout(function(){bot.createMessage(msg.channel.id,'can not connect to `https://steemd.steemit.com`');},1000);
        }
            });
}
});
bot.connect();

don’t forget say thx to @mahdiyari.
Steem On!

Share.

About Author

Leave A Reply