之前一直在用Discord的GinaBot消息提醒机器人,但是可惜分家后,GinaBot跑去HIVE链上去了
后来STEEM这边的开发者也开发了2款Discord消息提醒机器人,他们分别是MimeeBot 和RUPA机器人
这两款我都试过,体验都挺一般的。两款都不能设置接受哪种消息提醒,所以都是一窝蜂的把所有记录推送给你。如果你的帖子被几百个账号点赞,那消息提醒可把手机折腾要死。没用的提醒一大堆,有用的提醒又掩盖在一堆没用的消息提醒里面。
而我只想要回复,转账,关注,踩,mention这类的消息,所以就打算自己写个Discord 消息提醒机器人
Discord机器人比我想象的简单,尤其使用了一个叫eris的库,省下了很多时间来美化消息提醒
完成后的效果:
机器人代码:
const Eris = require("eris");
const steem = require('steem');
const bot = new Eris("TOKEN");
const channelId = 'CHANNEL ID';
const account = 'STEEM ID';
function start() {
steem.api.streamTransactions("head", function (err, result) {
if (!err) {
if (result) {
let op = result.operations[0];
const time = new Date();
const type = op[0];
const params = op[1];
switch (type) {
case 'comment': {
const isRootPost = !params.parent_author;
//Find reply
if (!isRootPost && params.parent_author === account) {
let content = `@${params.parent_author}:\n@${params.author} has commented on your post`;
let title = `${params.permlink}`;
let comment = params.body.substring(0, 100);
let url = `https://steem.buzz/@${params.author}/${params.permlink}`;
createMessge(content, title, comment, url, time);
}
//Find Mention
if (params.body.includes(`@${account}`)) {
let content = '';
let title = '';
let comment = '';
let url = '';
if (isRootPost) {
content = `@${account}:\n"@${account}" was mentioned by @${params.author} in a post`;
title = `${params.title}`;
comment = params.body.substring(0, 100);
} else {
content = `@${account}:\n"@${account}" was mentioned by @${params.author} in a comment`;
title = `${params.permlink}`;
comment = params.body.substring(0, 100);
}
url = `https://steem.buzz/@${params.author}/${params.permlink}`;
createMessge(content, title, comment, url, time);
}
break;
}
case 'custom_json': {
let json = {};
try {
json = JSON.parse(params.json);
} catch (err) {
console.log('Wrong json format on custom_json', err);
}
switch (params.id) {
case 'follow': {
/** Find follow */
if (json[0] === 'follow' && json[1].following === account) {
let content = `@${json[1].follower} now follows you`;
let title = '';
let comment = '';
let url = '';
createMessge(content, title, comment, url, time);
}
}
}
break;
}
case 'transfer': {
if (params.to === account) {
let content = `@${params.from} transferred ${params.amount} to you`;
let title = '';
let comment = params.memo;
let url = '';
createMessge(content, title, comment, url, time);
}
break;
}
case 'vote': {
//Find downvote
if (params.weight < 0 && params.author === account) {
let content = `@${params.voter} downvoted your post`;
let title = params.permlink;
let comment = '';
let url = `https://steem.buzz/@${params.author}/${params.permlink}`;
createMessge(content, title, comment, url, time);
}
}
}
}
} else {
sleep(2000).then(() => {
console.error(err);
start();
});
}
});
}
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
bot.once("ready", () => { // When the bot is ready
console.log("Ready!"); // Log "Ready!"
console.log(new Date());
start();
});
function createMessge(content, title, comment, url, time) {
bot.createMessage(channelId, {
content: content,
embed: {
title: title,
color: 0x008000,
url: url,
description: comment,
footer: {
text: `Time:${time}`
}
}
})
}
bot.connect(); // Get the bot to connect to Discord
并不是很完善的代码,但是基本消息提醒都有了。
Thank you for supporting @CatsMakeKittens by being a part of our community @ericet.
Each CATS you purchase gets you daily upvotes from me @CatScientist as our community grows so do your rewards for being a member!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
支持您的DIY贴子(By BUILD Token)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
加油!@ericet,
来自鸽子在Marlians的支持。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
你好鸭,村长!
@bossku赠送1枚SHOP币给你!
目前你总共有: 12枚SHOP币
查看或者交易
无聊吗?跟我猜拳吧! **石头,剪刀,布~**SHOP币
请到 steem-engine.com.Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
@tipu curate !trdo
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @leveuf, you successfuly trended the post shared by @ericet!
@ericet will receive 0.05370300 TRDO & @leveuf will get 0.03580200 TRDO curation in 3 Days from Post Created Date!
"Call TRDO, Your Comment Worth Something!"
To view or trade TRDO go to steem-engine.com
Join TRDO Discord Channel or Join TRDO Web Site
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Upvoted 👌 (Mana: 0/16 - need recharge?)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
@cardboard @tipu
I have not get the refund about the missing tx, check please.
alanyao transfer 8 SBD to tipu @huaren.news/btc20200427 hide
https://steemd.com/tx/806f26c630f9b206f470dccfb59a34f0e9b046ea
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for your support. Here's a !shop as token of appreciation.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Support your post (by ACTNEARN Token)
Thank you for sharing, Nice post
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Du erhieltest aufgrund deiner LanaCharleenToken Miner ein Upvote von @sebescen81
Vielen lieben Dank für euren Support. Der Account meiner Tochter wächst und gedeiht.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
牛批的村长
拍拍拍
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
这篇也没有拍手?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @ericet, your post successfully recieved 0.053703 TRDO from below listed TRENDO callers:
To view or trade TRDO go to steem-engine.com
Join TRDO Discord Channel or Join TRDO Web Site
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hi @ericet how can I subscribe to this discord notification made by you? I have the same problem as you too with rupa and mimeebot. Thanks in advance.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I haven't made it into a service everyone can subscribe to use. If you know programming, I put the code at the bottom of the post, you can just use it.
I might try to make it subscribable if i have time
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit