Snippets to get the downvoting power of an user for dsteem and steem-js

in development •  21 days ago  (edited)

Hello,

If you are unfamiliar with steemsnippets I encourage you to read the genesis post : https://steemit.com/programming/@howo/introducting-steemsnippets

And to check out the repository : https://github.com/drov0/steemsnippets

Since hard fork 21 is out, I see a ton of downvotes, which is great, and I suppose that you will grow tired of manually downvoting, so here's a few snippets to allow you to calculate the remaining downvoting power of an user.

the logic is similar in dsteem and steem-js so I'll only post the dsteem version on the chain :

function get_downvoting_power(username) {

    return new Promise(async resolve => {
        let account = await client.database.getAccounts([username]);

        account = account[0];

        const totalShares = parseFloat(account.vesting_shares) + parseFloat(account.received_vesting_shares) - parseFloat(account.delegated_vesting_shares) - parseFloat(account.vesting_withdraw_rate);

        const elapsed = Math.floor(Date.now() / 1000) - account.downvote_manabar.last_update_time;
        const maxMana = totalShares * 1000000 / 4;
        // 432000 sec = 5 days
        let currentMana = parseFloat(account.downvote_manabar.current_mana) + elapsed * maxMana / 432000;

        if (currentMana > maxMana) {
            currentMana = maxMana;
        }

        const currentManaPerc = currentMana * 100 / maxMana;

        return resolve(currentManaPerc);
    });
}

// example
async function test()
{
    console.log(await  get_downvoting_power("howo"));
}

test();

If you'd rather read them with colors here are the github links :

dsteem :

https://github.com/drov0/steemsnippets/tree/master/dsteem/get_downvoting_power

steem-js :

https://github.com/drov0/steemsnippets/tree/master/steemjs/downvoting_power

That's it for today :)

newsteem on !

@howo

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Make downvotes great again!

  ·  21 days ago Reveal Comment

Hello I see you downvoted me I did ask tipu if it was ok to use on my post they said it was fine ?

  ·  21 days ago Reveal Comment

Thanks for the snippet. I will now build a snipper =)

Yea down votes are great. Except when you don't even offer an explanation about why you would leave one. You see that's what making real connections is about. However, when you just click the button its useless and really very cowardly. This may not apply when its a post with no thought but when it does have content with a pitch a reason should at least be given. Thanks for sharing

Posted using Partiko Android

  ·  19 days ago (edited)Reveal Comment

So some completely ridiculous blanket notion that does not even look at the work itself.
Does not add anything to the community and is a lot more harmful than someone using a bidbot.
If it's a crap post withput merit sure but for thise that actually work hard on their post a d are just trting to survive seems completely unproductive.

Posted using Partiko Android

  ·  12 days ago (edited)Reveal Comment

Are you able to explain, why are you downvoting my post of last night?

  ·  19 days ago Reveal Comment
You can be a "co-founder of SteemPress - @steempress witness", but the negative vote you gave to my project of Photography (@enmovimiento) aimed at the Hispanic community is my total distaste without leaving a comment on that negative vote.
We users are the ones who give the votes to the Witnesses to help us help

I leave between 40 and 50 downvotes a day, if I'm gonna leave a comment for each one of them it's gonna spam the chain for nothing. You were downvoted for using bidbots. A proper post will be published soon, I was just testing things.

So why did you downvote my Actifit post??? Btw you posting 50 comments a day won’t spam anything, you do realize steems blockchain can handle that right?

Which Bidbots?

  ·  18 days ago Reveal Comment
When you (@howo) cast your negative vote @ rocky1 had not voted, that can be verified in the blockchain. @ rocky1 cast its positive vote to support our photographic challenge of September through which we will distribute all the Steem collected among the participants, that way we help Venezuelans who suffer from the economic crisis without asking for charity or help humanitarian
We try to get the most out of the Blockchain of Steem without always abusing to do good, thanks for withdrawing your negative vote, from Venezuela we thank you.
Cuando usted (@howo) emitió su voto negativo @rocky1 no había votado, eso se puede comprobar en la cadena de bloques. @rocky1 emitió su voto positivo para apoyar nuestro reto fotográfico del mes de septiembre mediante el cual vamos a distribuir equitativamente todo el Steem recaudado entre los participantes, de esa manera ayudamos a los venezolanos que sufren de la crisis económica sin necesidad de pedir caridad ni ayudas humanitarias.
Intentamos sacarle el mejor provecho a la Blockchain de Steem sin causar abusos siempre para hacer el bien, gracias por retirar su voto negativo, desde Venezuela se lo agradecemos.

Loading...