Devblog #3: getting a tiny bit serious

in #utopian-io3 years ago (edited)

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

Sort:  

Wieder sehr interessant zu lesen und deinen Fortschritt zu verfolgen.

Und mach dir mal über den unordentlichen Code keine Sorgen. Er tut zunächst was er soll und kann ja von dir jederzeit noch angepasst werden.

Die Richtung, in die das Ganze geht, sieht sehr gut aus!

Freut mich,
dass es gefällt.

Um ehrlich zu sein hilft mir das Schreiben auch mich selber zu sortieren.
Normalerweise wäre ich dazu zu Faul, fühle mich aber hier verpflichtet immer mal wieder einen kleinen Statusbericht abzuliefern.

Das kann ich mir sehr gut vorstellen, dass das ein schöner positiver Nebeneffekt ist. Mal Gedanken und Pläne zu sortieren ist manchmal ganz hilfreich, bevor weiter gecodet wird.

Your contribution cannot be approved because it does not follow the Utopian Rules.


Hi, you're doing a nice work, but your post does not fit with the blog post category. You're sharing some development updates and according to your series (update 1 and update 2) your project is still in a very early stage of development, and you next posts will be about some development updates too. Consider to continue your series in the development category.


You can contact us on Discord.
[utopian-moderator]

This is an ambitious project! I'd love to have a bot like this! I was looking to implement some weekly point/stats contests on my blog. With trivia questions, upvotes, resteems and comments all counting toward a weekly total. But, I'm not a developer. Anyway, cool! I don't know of anything that can grant benefits post/post creation, but SteemPlus browser add on, allows it to be done at the point of post creation. Not sure if any code there would help, but I'm sure it's open source. I'll be trying to follow this and see what's working, because, I'd love to be able to track those stats I mentioned and reward followers based on them. Great post! I was just stopping by to say hi, thanks for your recent support, and leave you a little upvote and comment. Stop by for more stories and contests any time! @markrmorrisjr

Thanks for stopping by.
Happy to see people like the idea.

I see this as a kind of interactive storydriven game, where every post is a little chapter.
There will be standard ones that repeat continously but I love to have some unique events in there with an awesome story.

So maybe you want to provide one of these stories when everything gets started.
But it's still really early and it will take me at least a couple more weeks to finish the basics.

When this is done I can look into the statistics you mentioned. Maybe some others have interest in this too.

I think a good, customizable, contest bot would be amazingly useful. Here is one specific, being able to sort out particular responses in comments, such as the prompt numbers in my you choose the story contest. It's tedious to have to go through and sort and count that. If the price of steem rises soon, I'd have some funds to help support that development.

Just wanted to let you know, I couldn‘t stop doing this.

See the post about something I called Eval-O-Tron.

Also there is @cuby’s project SteemitEva that started right about the same time doing something close to this. So we might join forces.

AAAAAHHHHH!!!! THAT IS SO COOL! Even in this format, it will save a ton of time. I just need to make sure that everyone uses numbers, instead of typing out the name of the number.

Makes me really happy to get this kind of response on something I have created.

Feel free to suggest stuff you want in there. It may take only a couple of minutes to add.

For this particular application, I think you've nailed it. If it could search for two "keywords" at once, I could type in 1 and one, etc, to get a count, that's about the only thing. In my dream world, it could create a list of the users that chose that prompt LOL, but that's easy enough to do. This would make it possible to do a larger contest a lot quicker.

Done.

Use ";" as a seperator between keywords.

"one; 1"

edit
Forgot to mention, you may need to remove cached JavaScript. I force a complete reload of the page with CTRL-F5 on Windows using FireFox.

Awesome! I'll take a look at these, because right now, I've only got about 40 votes on average, but that's doubled this week, and when it gets up to 200 I have no idea how I'll even be able to respond! LOL So, anything would be a big help.