function start() {
steem.api.streamTransactions("head", function(err, result) {
if (result && !err) {
console.log(result);//显示结果
}
});
}
运行上面的代码会显示所有发布到STEEM上的操作,比如转账,点赞,发帖,回复等。
但是我们只需要看回复的操作,所以我们需要过滤掉其他的操作,并且只看有发布指定关键词的回复。
具体实现如下:
let txType = result.operations[0][0]; //获取操作类别
let txData = result.operations[0][1];//获取操作内容
if (txType == "comment") {//如果操作是回复
let commentBody = txData.body;
let mention= '!hello';
if(commentBody.includes(mention)){
console.log('hello');
}
}
function start() { steem.api.streamTransactions("head", function(err, result) { if (result && !err) { let txType = result.operations[0][0]; let txData = result.operations[0][1]; let includesMention = checkContentForMention(txType, txData); if (includesMention) { reply(txData); } } else { console.log("Error found", err); start(); } }); }
function checkContentForMention(txType, txData) { if (txType == "comment") { let commentBody = txData.body; let mention= '!hello'; return (commentBody.includes(mention)); } }
let steem = require('steem'); let account = 'ericet'; let activeKey = '活动密钥'; let permlink = 'keybase-200-xlm';//帖子的permlink let amount = '800.000 POINTS';//要换点赞的ESTM分数