怎么用JS写个自动点赞程序?

in #cn5 years ago

image.png
(Image Source : Pixabay)

有没有好奇steemauto,steemrewarding的自动点赞是怎么实现的?

想不想自己写个属于自己的点赞程序?

其实理解原理这些点赞程序是很容易写的

steeemjs提供了一个点赞的function:

steem.broadcast.vote(postingKey, account, author, permlink, weight, function(err, result) {
    console.log(err, result);
});

只需填入相应的信息点赞程序就完成了。比如:

steem.broadcast.vote("发帖密钥", "账号", "ericet", "krwp-9zgk9bfvin", 10000, function(err, result) {
    console.log(err, result);
});

好了,点赞程序写完了。运行后会自动给我的帖子:https://steempeak.com/cn/@ericet/krwp-9zgk9bfvin 点个满赞。

是不是很简单?但是没啥实际用处。下面来添加一些功能,比如看到有新帖就自动点赞

上一篇里介绍过一个function:steem.api.streamTransactions。这个function会实时查看发布到区块链上的操作。

加上这个function和点赞的function就可以给所有新帖自动点赞了。

const steem = require("steem");
const steemid = 'steemid';
const postingKey = 'postingKey';

start();

function start() {
    steem.api.streamTransactions("head", function(err, result) {
        if (result && !err) {
            let txType = result.operations[0][0];
            let txData = result.operations[0][1];
            if (txType == "comment" && txData.parent_author == '') {
        upvote(txData.author,txData.permlink);
        }
        } else {
            console.log("Error found", err);
                start();
        }
    });
}

function upvote(author,permlink){
    steem.broadcast.vote(postingKey, steemid, author, permlink, 10000, function(err, result) {
            console.log(err, result);
    });

}

再加个新功能,点赞后自动留言:

const steem = require("steem");
const steemid = 'steemid';
const postingKey = 'postingKey';

start();

function start() {
    steem.api.streamTransactions("head", function(err, result) {
        if (result && !err) {
            let txType = result.operations[0][0];
            let txData = result.operations[0][1];
            if (txType == "comment" && txData.parent_author == '') {
        upvote(txData.author,txData.permlink);
        reply(author,permlink);
        }
        } else {
            console.log("Error found", err);
                start();
        }
    });
}

function upvote(author,permlink){
    steem.broadcast.vote(postingKey, steemid, author, permlink, 10000, function(err, result) {
            console.log(err, result);
    });

}
function reply(author,permlink){
    const timeStr = new Date().toISOString().replace(/[^a-zA-Z0-9]+/g, '');
        const newParentPermlink = txData.parent_permlink.replace(/(-\d{8}t\d{9}z)/g, '');
        var replyPermlink = 're-' + txData.author.replace(/\./g, '') + '-' + txData.permlink + '-' + new Date().toISOString().replace(/-|:|\./g, '').toLowerCase();
    steem.broadcast.comment(
        postingKey,
        author,
        permlink,
        steemid,
        replyPermlink ,
        "",
        "HELLO!",
        '{"app":"test"}',
        function(err, result) {
            console.log(err, result);
        });


}

运行后,会自动点赞新帖并且给予“HELLO”的回复。

特别说明,这个程序没有考虑任何点赞时机和调整点赞比例,如果你真要运行这个程序,做好VP被抽干,回复被踩,没有任何审查收益的心理准备。

这个程序只作为参考,你可以调整一下点赞比例,点赞时机后会是一个不错的赚审查机器人。

Sort:  

程序就是 天书 😳

其实和学外语一样,知道基本语法就可以写了。

加油!@ericet
鸽子在mediaofficials支持你。

加油!@ericet
来自鸽子在Marlians的支持。

Thanks for using eSteem!
Your post has been voted as a part of eSteem encouragement program. Keep up the good work! Install Android, iOS Mobile app or Windows, Mac, Linux Surfer app, if you haven't already!
Learn more: https://esteem.app
Join our discord: https://discord.gg/8eHupPq

你那里天气如何?新人吗?《steemit指南》拿一份吧,以免迷路; 另外一定要去 @team-cn 的新手村看看,超级热闹的大家庭。倘若你想让我隐形,请回复“取消”。

Hi, @ericet!

Thank you for using the #build-it tag. This post has been rewarded by @build-it.curator with BUILD tokens in the form of an upvote. Build-it is a new tribe on the steem blockchain that serves as a central hub for DIY contents on steemit.

We encourage steemians to post their DIY articles via our website. Have a question? Join us on Discord and telegram

This project is run and supported by our witness @gulfwaves.net. If you like what we do, vote for us as a witness on the steem blockchain.

thank you



This post has been voted on by the SteemSTEM curation team and voting trail. It is elligible for support from @curie and @minnowbooster.

If you appreciate the work we are doing, then consider supporting our witness @stem.witness. Additional witness support to the curie witness would be appreciated as well.

For additional information please join us on the SteemSTEM discord and to get to know the rest of the community!

Please consider using the steemstem.io app and/or including @steemstem in the list of beneficiaries of this post. This could yield a stronger support from SteemSTEM.

Coin Marketplace

STEEM 0.28
TRX 0.13
JST 0.032
BTC 61142.49
ETH 2928.10
USDT 1.00
SBD 3.67