Dicebot Dev Post #2steemCreated with Sketch.

in #steemit9 years ago

nocturnal-code.png

On my last post, I discussed my motivations for wanting to write a Steemit bot. The bot will respond to requests to posts or comments requesting the bot to roll dice (eg, @dicebot 3d6) with a post with the results of a virtual dice roll.

As of that post, I had been using a REST client (Rested, which is free and, uh, worth every penny) to experiment making queries to the Steemit server, but hadn't actually written any code. Well, now I have code! It's still pretty early and not very good, but it works. Right now, it simply pulls available blocks from Steemit every minute, loops through until it finds comments (and according to this API, both original posts and replies to posts are "comments"), and prints a link to them in the terminal. Here's some sample output:

> .build/debug/Dicebot
Head block is 14064799
Getting block 14064799
https://steemit.com/@barber78/re-nzfxtrader-re-barber78-disney-moonlandings-20170728t005855943z
Done with block 14064799
Getting block 14064800
Sleeping!
Getting block 14064800
https://steemit.com/@offgridlife/thursday-sunset-lake-superior
https://steemit.com/@gniksivart/re-duckmast3r-re-gniksivart-steemwhales-frozen-2017727t193916493z-20170728t005856956z
https://steemit.com/@steemvalve/re-madstacks-steemit-roulette-giveaway-18-try-your-luck-to-win-100-sbd-payout-20170728t005902730z
https://steemit.com/@onlimono/re-bonyjo-re-onlimono-re-bonyjo-re-onlimono-a-little-different-view-of-bcc-and-viabtc-or-bcc-viabtc-20170728t005805855z
https://steemit.com/@jiva34/5ta4me-colorchallenge-thursday-green
https://steemit.com/@planetfreewill/re-jerrybanfield-first-florida-steemit-meetup-on-august-10-2017-in-sarasota-20170728t005903723z
Done with block 14064800
Getting block 14064801
https://steemit.com/@nicnicy/re-sixexgames-re-sixexgames-re-nicnicy-free-steem-dollars-followers-minnows-faucet-july-27-20170728t005907198z
https://steemit.com/@khj1225/3
Done with block 14064801
Getting block 14064802
https://steemit.com/@adilsontsilva/nunca-guarde-em-exchanges-e-sites-de-mineracao
https://steemit.com/@papa-pepper/steem-pocalypse-survival-game-season-5-day-7-round-1-400-sbd-prize-pool-so-far
Done with block 14064802

The "Sleeping!" line is where the bot tried to get a block, only to find that block had not been created yet. So it slept for 60 seconds and tried to get that block again.

The code is not my best work; it has a lot of duplication and no comments. (The code has likely improved since this posting; check out the "dev-post-2" tag if you want to see the code as it was as I'm writing this.) Also, there's probably a better way to do the JSON parsing than the cast-heavy method I'm using now; at least, the Foundation docs suggest it. But I'm using Swift 3.1 and perhaps that stuff isn't available until Swift 4. More research is needed.

Ah, yes, Swift. Yep, it's my current go-to language, so that's what I'm using; that and I still want to deepen my experience with it and with the hosting platform I eventually intend to use, IBM Bluemix. This is kind of a dumb thing to do because there are already great Steemit communication libraries in Ruby, Python, JavaScript and possibly other langs. But, well, frankly, I don't really like Python or Ruby. Ruby in particular looks like a love child between Perl and AppleScript. I like my typical C-style languages with lots of curly braces (and JavaScript counts as one, but I can't just deal with its unusual prototype/inheritance stuff), and besides, what I've done is so simple that I'm not really losing that much time by not using a pre-built library.

So far, anyway. I still haven't experimented with posting yet; that comes next. And maybe that will be unbelievably hard. I'll have a try at it tomorrow, most likely.

Also, I should try to figure out how to handle the case where someone edits their post… both what that looks like in the blockchain, and what the bot needs to do in that case. Any suggestions?

Sort:  

Hi, Nocturnal. I sent you a comment in Discord.

Okay. I won't be able to hop on there for a while, but I'll try to have a look in a few hours. Wonder if it has anything to do with comment posting being even more difficult than I was afraid it would be… :P

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.087
BTC 59353.76
ETH 1567.70
USDT 1.00
SBD 0.42