小机器人第二步重生之我在HIVE自动点赞与回复

Words
286
Reading
2 min
Listen
Play
2y

from pixabay

题记

1.PNG

正文

  • 干货 其实这次主要就弄了三个函数。搞定他们就能自动点赞与自动回复了。

  • 获取帖子信息 getTopPosts获取指定板块头部的帖子

/* 
const tag = 'hive-105017'; //比如中文板块就是hive-105017
const limit = 10;  //获取的限制数量
*/

async function getTopPosts(tag, limit) {
    try {
        const posts = await client.database.getDiscussions('created', {
            tag: tag,
            limit: limit,
        });
        return posts;
    } catch (error) {
        console.error('Error fetching posts:', error);
        return [];
    }
}
  • 投票 vote函数就是如何投票了,其实dhive做得简化的了
async function vote(voter, privateKey, author, permlink, weight=10000) {
    try {
        // 构造投票操作
        const voteOperation = [
            'vote',
            {
                voter: voter,       // 投票者用户名
                author: author,     // 被投票内容的作者
                permlink: permlink, // 被投票内容的唯一标识
                weight: weight      // 投票权重(-10000 到 10000,10000 表示 100%)
            }
        ];

        // 发送交易
        const result = await client.broadcast.sendOperations(
            [voteOperation],
            privateKey // 使用投票者的私钥签名
        );

        console.log('投票成功!交易 ID:', result.id);
        return result;
    } catch (error) {
        console.error('投票失败:', error);
        throw error;
    }
}

  • 回复 rely函数就是怎么回复了。
async function reply(parentAuthor, parentPermlink, author, body, privateKey) {
    try {
        // 构造回复操作
        const replyOperation = [
            'comment',
            {
                parent_author: parentAuthor, // 父级作者(如果是直接回复帖子,则为帖子作者)
                parent_permlink: parentPermlink, // 父级内容的唯一标识
                author: author, // 回复者用户名
                permlink: generatePermlink(), // 生成唯一的 permlink
                title: '', // 标题(可以为空)
                body: body, // 回复内容
                json_metadata: JSON.stringify({ app: 'dhive-nodejs-hivebot' }) // 元数据
            }
        ];

        // 发送交易
        const result = await client.broadcast.sendOperations(
            [replyOperation],
            privateKey // 使用回复者的私钥签名
        );

        console.log('回复成功!交易 ID:', result.id);
        return result;
    } catch (error) {
        console.error('回复失败:', error);
        throw error;
    }
}

反馈

  • 有意思 首先要感谢hive社区的小伙伴不反感机器人的的骚扰!纷纷对这个Ai Agent有意思的评价。谢谢hive的小伙伴的理解与支持。目前只是作为技术储备,希望未来能够对社区发光发热。

2.PNG

3.PNG

  • 遗憾 目前代码整体代码写得太逻辑混乱了,就不好意思发出来了。以后慢慢完善呗。
小机器人第二步重生之我在HIVE自动点赞与回复 | Ecency