Devblog #5: introducing storybot for steemLore

in #utopian-io6 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.

It has been a while since my last update on this project. I apologise to anyone following me on this. There have been some setbacks that were really demotivating and as I said in previous posts, there are so many interesting things to do and it is really hard to not get distracted.

Today I'd like to present you storybot, the backbone of the steemLore project.

what is storybot

My storybot is a steem bot written in Python. It's purpose is to automatically respond to user interactions. Therefor it has to read data from the blockchain and post comments etc. accordingly.

Until now I used a modification of deutschbot, a bot for german curation. I came across some shortcomings and wanted a clean start so I began all over again. I am still using some bits and pieces from it but basically I have rewritten most of the parts from scratch.

With steemLore I want to tell interactive stories. The storybot will be the Narrator, advancing the plot when necessary conditions are met.

how it works

The basic idea is to have a Narrator class that starts storytelling by a discord command. Responses can be made through actions on the Steem blockchain as well as through a Discord webhook.

no actual UML

By starting the bot the Narrator class will initialise the StoryIndex which will build a list of stories. StoryIndex can be asked what stories it has. When start_narration is called, StoryIndex is asked for a story with a specific title and will hand it to the Narrator if available.

def start_narration(self, title=None):
    if title is not None:
        new_narration = self.index.get_story(title)  

        if new_narration is not None:  
            self.narrations.append(new_narration)  
            new_narration.start()  
            self.process_actions(new_narration)

    self.update_narrations()

After that update_narrations will update all running narrations in a timed loop. A Story update will check if conditions are met and decide which actions to take.

def update_narrations(self):
    for narration in self.narrations:
        narration.update()
        self.process_actions(narration)

    if len(self.narrations) > 0:
        time.sleep(self.sleeptime)
        self.update_narrations()

After the update the Narrator will process these actions.

def process_actions(self, narration):  
    actions = narration.get_actions()  
    for action in actions:  
        self.post_to_webhooks(narration, action)  

        if action['type'] == 'post':  
            postid = steemi_post(action['value'])  
            narration.set_postid(postid)  
  
        if action['type'] == 'comment':  
            postid = steemi_comment(narration.get_postid(), action['value'])  
            narration.add_comment(postid)  
  
        if action['type'] == 'upvote':  
            steemi_vote_up(action['value'])  
  
        if action['type'] == 'getvotes':  
            votes = steemi_get_votes(action['value'])  
            narration.add_votes(action['value'], votes)  
  
        if action['type'] == 'end':  
            self.narrations.remove(narration)

See the full source on GitHub.

using storybot

You can use storybot by adding your own story with basic python knowledge and without caring of interaction with the steem blockchain.

Create a new Story using the teststory as a template.
Change class name and import it to the index.py

Now you can start editing start, which will be executed once in the beginning, and update, which will be executed once every cycle.

You can add actions to perform desired tasks on the steem blockchain such as post or vote. Use self.add_action(type, value).

These are the action types you can currently use:

  • post - sets up the root post of Story
  • comment - create a comment on the root post
  • upvote - votes up a post or comment
  • getvotes - receive votes on the root post or comment
  • end - removes the story from the list of active stories

future development

Right now storybot will create a post and post further chapters in its comments. It is meant to easily add new stories, therefore it needs to detect these stories and add them to the index.

Additionally storybot should be able to handle multiple stories at once. Most of the functions are already designed for that but right now there is no functionality that is able to start a second story while already processing another one or pick up one already started.

  • find interrupted narrations and pick them up
  • detect stories in a directory and add them to the index
  • listen for commands while running

See you on steem.




Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved. According to Utopian Rules "The repository must contain a readme file with usage and install instructions", please write the Install Instructions.

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

Thanks, added install instructions.

Please let me know if there is any other problem.

Hey @derasmo I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x