(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被抽干,回复被踩,没有任何审查收益的心理准备。
这个程序只作为参考,你可以调整一下点赞比例,点赞时机后会是一个不错的赚审查机器人。