This blog post will be about a little gaming project I came up with. You can read in more detail what it's all about in the introduction post.
So I came up with this little idea and have no clue what I am doing here and where to start. But I have a RaspberryPi lying around and setting one up never is a bad idea, right? Well haven't worked on Linux for quite a while and getting steem-python running has been tedious. When you solve an error to get more errors multiple times in a row for something trivial like package installation you just start to wonder if its worth the effort.
I can't remember having anything done in Python yet and it most likely wouldn't have changed if I had a choice. But Steem Developers Portal gives me the choice between JavaScript and Python. So I chose Python because I want a script running on a Server and JavaScript is for client, right?
So I want to have this bot that does stuff on steem when people do stuff on steem. I needed a Bot for Steem to learn how things are done and found deutschbot. It has discord support and could do what I want in some minor changes. Still needed some functions that weren't used in the bot so I had to crawl through everything on the python-steem documentation which was annoyingly boring and I think their page is really inconvenient to use. Had to lookup some argument descriptions on post()-function a couple of times. You should try and maybe tell me what I'm doing wrong.
For starters I want a bot that does the following:
Pretty straight forward post(title, body, author, permlink=None, ...). What bugged me with this was I expected to get a new unique identifier when creating a post and it's not that easy. A post can be identified by @author/permlink. Permlink will be build from title. Two posts with the same title will have the same permlink. When someone creates a new post with a permlink he already uses this older post will be "edited" and only the new one will be shown on steemit. Meaning I'll have to do some sort of permlink creation if I want unique handles for my posts and be sure nothing gets mixed up.
The function get_active_votes() gives me all the votes on a post. Creating a comment just takes the post() function with an additional reply_identifier which is @author/permlink from first step.
Nothing new here, get_active_votes() on the comments and write everything in a new comment.
So I'll end up doing something like this
var permlink = create_unique_permlink();
post(title, body, author, permlink);
var postid = "@" + autor + "/" + permlink;
var start = now;
var duration = x;
var limit = y;
var voters = array();
var permlinks = array();
while(now < start + duration)
{
var votes = get_active_votes(author, permlink);
if(voters.size < limit)
{
foreach(votes as vote)
{
if(vote['voter'] not in voters)
{
voters[] = vote['voter'];
permlinks[vote['voter']] = create_unique_permlink();
post(title, body, author, permlink, postid);
}
}
}
wait(zZzzZZZ);
}
var results = array();
foreach(voters as voter)
{
var votes = get_active_votes(author, permlinks[voter]);
results[voter] = get_score(votes);
}
var bodyResult = evaluate(results);
post(title, bodyResult, author, create_unique_permlink());
This doesn't look too complicated. I guess I'll do that and report back when it's up and running.
See you on steem.