Image source
@acidyo wanted a super simple bot so I made a super simple bot. The basic idea of the bot was to send a discord message whenever a brand new account created a post. I thought of two ways of doing it.
The first way was the rejected way. We stream the chain, looking for root posts. We then see if they had made any other root posts using the getDiscussionBeforeDate
call. That would have made more calls to a hivemind node and I didn't really want to do that. Which is what led to the second way.
The way that we did do it was to stream the chain to looking for the account creation action. Whenever that happens, we save 2 things to the db, who created the account and the name of the new account. We also look for posts made with our stream, and whenever a root post is made, we check our DB to see if the author of the post is in there. If so we send a message on discord, and then delete them from the DB. The only problem here is that it'll only work for accounts created after we started the stream(or set our start block to an earlier point) but thats something we can live with.
This was a relatively simple bot to make for me. A lot of it I was able to copy paste from my old projects since I've worked with hive streaming a ton. Check out lines 14-859(https://github.com/Rishi556/NewUserPostBot/blob/main/index.js#L22-L85), that handles the streaming.
Then we look for accounts created and save them to the db(https://github.com/Rishi556/NewUserPostBot/blob/main/index.js#L91-L108). We have to look for both the account_create
and create_claimed_account
operation since there's two ways to create accounts. Account create is done by paying fees, and with claimed it's done using account tokens that can be claimed for RC.
Now for some new parts. This was my first time working with webhooks for discord. Webhooks was better than a bot for this since all we would be doing is pushing stuff on events and a whole bot wasn't needed for that. This makes things a lot lighter. I used https://discohook.org/ to play around with the discord webhooks and decide on a format I liked.
The code from https://github.com/Rishi556/NewUserPostBot/blob/main/index.js#L109 onward is going to handle the sending part. We basically check to see if the parent_author
field is blank(if it isn't that means it's a comment) and then if it is, check to see if the User is inside our database. If they are, it means that they are a new user who's post hasn't been shared to discord yet. And so we share it, then delete them off the database so their other posts won't get shared.
Starting this bot up is pretty simple. It supports multiple discord webhook targets so one instance can share to multiple locations at once. It also lets you skip accounts created by known problematic accounts.
It's built in nodejs so you'd just have to install a version of nodejs compatible with aixos and mongoose(I like 15). I'm not going to go in depth on that, as there's plenty of general how to start a node app guides on google.
Configuration for this bot in particular just needs to be done in the config.json file. mongo_url
should be the url to your mongo instance with a DB specified. discord_webhook_urls
should be an array of webhooks that you want to send it to. By using an array we can send to multiple destinations with one instance. nodes
should be an array of urls to hive nodes. If one of the nodes has problems, this lets us switch to another node automatically and not have to check up on it. I'd recommend putting a few in there. errorToSwitch
is how many errors you'd want from a node before you switch to the next node(I might have forgotten to reset error count after a successful attempt on this version but its fine). Finally creator_to_skip
should be an array of accounts to ignore on them creating accounts. If they make an account, the author never gets added to the DB.
state.json
stores the last processed block. Setting this to -1
will start at the head block and setting to any other block will let you start at that block, so you can replay the chain if needed.
And thats all there is to it. It's relatively simple to start up and once you do its easy to use, and if you are a curator, you might find some use out of it.
If you run a discord and want the notifications in your server, throw a comment here and I'll reach out on how to get it added. My discord tag is Rishi#0556(unless my nitro lapses and then who knows what it'll be, find me in the main hive discord and we can go from there).
Grab it on git here: https://github.com/Rishi556/NewUserPostBot
Thanks for taking the time to make this, I think that with some curator eyes on this channel and hopefully more communities, tribes and curation projects adapting to it and assisting newcomers with their Hive beginning journeys, if they're not sure where or how to post and helping them find the right communities, this could be a tool for an increased retention rate for newcomers.
Hopefully more people step up at wanting to use this as well!
Helping newcomers is going to be awesome. Retention is a problem on hive and hopefully this can help alleviate some of that problem.
!WINE
Cheers @zelensky, Thank You For Inviting @rishi556 To A Glass Of WINE.
At The Moment You Don't Have Enough WINE Staked To Order A Glass Of WINE From @wine.bot.
Please Refill Your Barrels By Directly Buying WINE From Marketplace & Make Sure You Have Atleast 25.00 WINE In Staked Wallet.
Total Purchase : 24725.918 WINE & Last Price : 0.290 HIVE
HURRY UP & GET YOUR SPOT IN WINE INITIAL TOKEN OFFERING -ITO-
WINE Current Market Price : 0.500 HIVE
Neat initiative boys. Herding new users towards resources they'll need to be successful is important. Well done.
Gotta help them out. Its hard being new in this world.
I think it's a great project, it's an excellent tool. Thanks for your effort guys!
Happy to do work that should help new users out.
Awesome. You have skillz!
Thanks. So do you :)
Very nice!
Good Work @rishi556 !
I think it would be easy to modify the Script that will check the User-Account for the first time posted in a specific tag. For example an onboarded User for the German Community will write it's first Post in the main german tag "deutsch" and get notified by this in our German D-A-CH Discord Server. I'm gonna ping @jedigeiss who is the Owner of our Discord - Maybe this would be helpful to find out language specific new users on the chain.
thanks and greetings 😀 Awesome idea @acidyo
That should be a pretty easy change to make. Just check to see if the tags have that and if they don't, ignore it. If they do. Send the notification.
Awesome, and useful. Hope to see more little tools like this pop up.
Dat a boi!!!!!!!!
Es exelente tu post, la verdad es una buena manera para que los nuevos integrantes se adapten, saludos.
Nice work Rishi. I haven't explored webhooks yet. I guess looking at your code will give me a good first glance for a simple understanding. !BEER
It's really simple, especially for all it does. No need for an entire discord bot. I just wish there was a way to webhoook into dms :)
!wine
Congratulations, @theguruasia You Successfully Shared 0.200 WINE With @rishi556.
You Earned 0.200 WINE As Curation Reward.
You Utilized 2/3 Successful Calls.
Total Purchase : 24809.918 WINE & Last Price : 0.290 HIVE
HURRY UP & GET YOUR SPOT IN WINE INITIAL TOKEN OFFERING -ITO-
WINE Current Market Price : 0.271 HIVE
WoW maybe we need thiamin the terminal thanks for sharin
I'd be happy to help you set it up in there. Just send me a dm and I'll tell you what I need from you.
Cada dia llegan nuevas actualizaciones y nos facilita muchos comandos. poco a poco seguirá mejorando hive, todos los dias aprendo algo nuevo sobre todo al leer sus post. son de gran ayuda. mil gracias.
Welcome