So I'm building a Steemit bot: Dev post #1steemCreated with Sketch.

in #steemit7 years ago

nocturnal-code.png

So @papa-pepper recently posted about running his periodical Steem-Pocalypse games and how difficult it can be to track the state and inventory of all the players, especially since the number of players can run into the hundreds in the early rounds of the game. He now has a spreadsheet to help him out, but it made me think about how a Steemit bot could be used to track these sorts of things automatically based on the content of his posts and how the players reply to them.

This led me to look further into developing against the Steem blockchain. Now I don't mention it much in my other posts, but I'm a software developer by hobby and profession, and I have been for some time; I started out writing BASIC programs on an Apple II. Check out my GitHub profile for a (so far somewhat meager) list of projects that I've worked on under my Nocturnal alias.

Soon after joining Steemit and finding the Esteem iOS app, I started looking into developing my own Steem client for iOS, because Esteem is… uh… periodically not up to its own standards, I'm sure. Anyway, the new terminology and technology just lost me pretty quick. I didn't get it.

But after papa-pepper's thread, I looked into it again, and after some studying of the code of existing bots and such as well as finding posts like this one, I was able to make some successful test queries of the blockchain. Hey, it's just JSON-RPC! It's not that weird. I got this.

I had a hard time at first, though, trying to figure out how to get a list of all posts and comments to the site. The list of API functions for Steemit includes ones to get all comments on a post or posts in a tag or posts by a certain user, but not really anything to get all posts or comments regardless of other criteria. Eventually, though, by again seeing what other code was doing, I found that this can be achieved by using the API function to get a block. Blocks contain a list of various transactions on the blockchain of all sorts; posts and comments, yes, but also money transfers, memos, upvotes, and so on. So I can grab a block, scan through it to find the posts and comments, and then grab the next block and so on until I run out of blocks that have been created. More progress!

Now here's a tip to people out there who are new to programming: When you're working with a new technology as I am here, start off with really simple projects. Don't just jump in to some super mega magnum opus. Do something small that will cause less confusion and that you can finish quicker. That way, you see working results faster, and that keeps your motivation up for the big projects.

To that end, I'm not going to jump into developing a bot for papa-pepper's game right off the bat. (I haven't even asked him if he would even find such a thing useful, actually. Maybe I'd build this thing and nobody would come…) I decided the first bot I'm going to make will provide random numbers by rolling virtual dice when requested. So, for example, if you write @dice-bot 3d6 in a post or comment, the bot will reply to you with the results of rolling three six-sided dice. You could also use it to decide winners in a random drawing contest: give all of your potential winners a number and then ask the bot to pick one. Perhaps the random numbers the bot generates could even be seeded using the block ID and time and date of the post, so that the "random" results of the bot are easily recreatable to avoid claims of the bot cheating or being biased.

One possible pitfall: I haven't looked at all yet into how bots actually post to the blockchain; so far I've only been fetching data from it. I'm sure that part is going to be more difficult because of the encryption keys and such involved, but based on what I'm finding so far, it should still be something I'm capable of figuring out eventually.

Anyway, I'll be "live-blogging" the development of this thing for those that may be interested. (Those interested in my usual silly fare, please bear with me.) And as I go along, I'd love to hear feedback from others interested in this project or in learning how to build applications that interact with Steemit. So please give me a follow if you're interested in this sort of thing. (Yes, I just follow-begged. What a hypocrite.)

(Image (and the code therein) of my own creation.)

Sort:  

I got a lot of encouragement from this post. I am not a programmer, but I am into programming since BASIC, too. I am starting from scratch with Python, with the intention of being more proficient in the blockchain world. I have been an accountant for 3 decades (and I´m on my way to getting an old-age physics degree). Since blockchain has a lot to do with accounting, I guess that is somehow an advantage for me. But moving arroung in Steemit one gets the impression that if you don´t know how to programme in blockchain you are missing 80% of the action.

Best of lucks with the small project, and the big one. I´m sure @pappa-prepper will love it.

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63271.81
ETH 2568.70
USDT 1.00
SBD 2.80