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