Devblog #3: getting a tiny bit serious

By @derasmo2/20/2018utopian-io

Postheader Logo

Welcome to the new part of my development blog.

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.

First of all thanks to everyone hwo supported me on the introduction post. The author rewards will help in the future of this project.

I've been lazy this weekend but the last two days I returned working on the bot and just finished it for some testing. Full source can be obtained on GitHub.

talk to me

Before putting the bot out in the world I wanted some discord integration so I know whats happening while it does what it does. I had some issues understanding how python handles some things. Well still don't understand it and just changed the approach. Now I can start the bot in the background without missing the console output. This is the new code for the testrun:

def start_game(self):

    #settings
    duration_hours = 0
    duration_minutes = 0
    duration_seconds = 5

    limit = 2

    # 1. create post
    title = 'testing a bot'
    body = 'This post is auto generated and ment for testing pupose. You can read in more detail what it\'s all about in the [introdutction post](https://steemit.com/@derasmo/vorstellung-von-mir-und-meiner-projektidee). All rewards go to @deutschbot, because I use his code, @markus.light, because he volunteered, and @reeceypie, because @ocd resteemed a post I liked.'

    permlink = 'testing-a-bot-bot-bot'

    beneficiaries = [
        {'account': '@deutschbot', 'weight': 2500},
        {'account': '@markus.light', 'weight': 3750},
        {'account': '@reeceypie', 'weight': 3750}
    ]

    permlink = self.post(title, body, self.bot_account, permlink=permlink, beneficiaries=beneficiaries)

    # 2. catch upvotes and create comments
    postid = "@" + self.bot_account + "/" + permlink;
    start = time.time()
    duration = duration_hours * 360 + duration_minutes * 60 + duration_seconds

    voters = []
    permlinks ={}

    while time.time() < start + duration:
        if len(voters) < limit :
            votes = self.s.get_active_votes(self.bot_account, permlink)

            if len(votes) > 0 :
                # sort votes by time and cut off above limit
                v_votes = self.get_valid_votes(votes, limit)

                for vote in v_votes:
                    if vote['voter'] not in voters:

                        if len(voters) < 1:
                            comment_body = vote['voter'] + 'is collecting for @mack-bot. In Addition to the users mentioned in the post @mack-bot will receive a share. Please vote if you want them to win.'
                            comment_beneficiaries = [
                                                        {'account': '@deutschbot', 'weight': 2500},
                                                        {'account': '@markus.light', 'weight': 2500},
                                                        {'account': '@reeceypie', 'weight': 2500},
                                                        {'account': '@mack-bot', 'weight': 2500}
                                                    ]
                        else:
                            comment_beneficiaries = [
                                                        {'account': '@deutschbot', 'weight': 2500},
                                                        {'account': '@markus.light', 'weight': 2500},
                                                        {'account': '@reeceypie', 'weight': 2500},
                                                        {'account': '@spaminator', 'weight': 2500}
                                                    ]
                            comment_body = '@' + vote['voter'] + 'is collecting for @spaminator. In Addition to the users mentioned in the post @spaminator will receive a share. Please vote if you want them to win.'

                        self.post_to_webhooks( vote['voter'] + ' joined the game.')
                        voters.append(vote['voter'])
                        permlink = 'testing-a-bot-bot-bot-comment-' + len(voters)
                        permlinks[vote['voter']] = self.post('', comment_body, self.bot_account, reply_identifier=postid, beneficiaries=comment_beneficiaries)

        time.sleep(5)

    # 3. post summary
    results = {}
    for voter in voters:
        votes = self.s.get_active_votes(self.bot_account, permlinks[voter])
        results[voter] = len(votes)

    results_body = self.evaluate(results)
    self.post_to_webhooks(results_body)
    self.post('', results_body, self.bot_account, reply_identifier=postid)

The code is a little bit messy and will need to be rewritten or at least cleaned up. But there will be lots of changes in the next couple of days so I don't care about it too much. I added "beneficiaries" and will for this testrun give all curation rewards to the accounts mentioned in the respective post body. If everything works as I understood it. But thats what this is for. See how things work.

The post_to_webhooks() is responsible for sending messages to discord. There is a difference in Discord Apps and Webhooks. Took me a while to understand that the webhooks do not control the Discord App but the Webhook, which is not actually a "User" in the channel like the app is, but more like a pipe to the channel itself. So the App is for listening on the channel, the webhook for output to the discord.

fingers crossed

The bot started its first round and can be followed on this post. The agenda still is:

  1. create a post on command - check
  2. catch upvotes on this post and create a comment with upvoters name
  3. create another comment after a given time displaying upvote informations of comments created in the last step

I hardcoded the permlinks so if anything goes wrong I can restart the bot without him creating a new post. In future versions the bot should pick up unresolved entry posts and continue them.

Hope everything runs smooth and as expected. It's a pretty simple task but still. It's the first time I'm running the program with actually posting to steem so I don't know what I might have missed.

coming tasks

Next step is to think about how the game will proceed and evaluate what's possible and where I don't come up with a solution yet. Have a lot of ideas, the best ones might already be forgotten, so I better write them down to everyone, including myself.

Already setup an environment for frontend development as well. I'm using Joomla! on XAMPP which I edit with Eclipse (Php Neon, to be precise - but that doesn't really matter). I already did a couple of projects in Joomla! so that will be an easy one. Coming closer to the point where I will need someone with serious abilitys in graphical web design.

See you on steem.

update

There we go first problems appeared. Steem needs at least one Tag. Function post() initializes tags with tags=None. But that's because tags can also be submitted in the JSON part. The Error thrown when not having a tag indicates something is wrong with the permlink which doesn't help at all locating the error.

update 2

There seems to be an issue with the python API which prevents setting the beneficiaries. Might have to send the rewards manually if I can't get it to work. If you can help me fixing this please tell me in the comments or on discord (@DerAsmo#9548).




Posted on Utopian.io - Rewarding Open Source Contributors

4

comments