Introducing DelegatorBot 1.0

in #utopian-iolast year (edited)

Repository

https://github.com/artolabs/delegatorbot

delegator_bot_1.0_logo.png

DelegatorBot 1.0

DelegatorBot is a simple, yet powerful command line bot that uses delegations to determine who it upvotes, rather than bids. The concept is simple: those who delegate get an endless supply of upvotes (with limitations, of course) until they decide to undelegate (delegate zero). The bot can be configured to accept a certain amount of Steem Power as a delegation which will prompt it to follow that account. The bot can then be run to upvote, resteem and reply all of those it follows. DelegatorBot can also generate a daily report which details all of those who have delegated, how much they've delegated, as well as all of those it has upvoted, and the percentage of upvote they received.

There are currently two bots running live using DelegatorBot 1.0. Check them out!

@ArtTurtle

turtle_head_small.jpg

@Tommyknockers

tommyknocker_small.png

Installation

Please see the installation instructions.

Bot Algorithm

Obviously, as more people delegate to the bot the demand on vote power will increase. To compensate for the ever increasing number of upvotes the bot must make a failry simple algorithm is used. At the time of each vote, the bot looks at it's history of voting in the last three days and adds up all of the vote weights. So, for example, If the bot made 10 votes in the last three days, each at 100%, the total vote weight would be 1000%. Since it's best not to upvote more than 10 100% upvotes per day (1000%), One could say that 3000% is the maximum vote weight for three days. Knowing this, to calculate the current vote weight One can simple divide 3000 by the total vote weight actually used. For example, if the actual amount of vote weight used in the last three days is 4000%, then:

    (3000 / 4000) * 100 = 75%

The second part of the algorithm takes into account the idea that one delegator might post much more than other delegators. To make sure that nobody takes too much from anyone else, each delegator is given their first post of the day the maximum amount (as determined by the equation above). Each post after that gets a drastically reduced percentage based on the amount of time that has elapsed since their last post. If the amount of time has only been 21600 seconds (6 hours) then the vote weight will only be 3%. After that, the vote weight is further calculated by dividing the amount of time since the last post made (in seconds) by 86400 (the number of seconds in 24 hours). So, for example, if it's been 46700 seconds since the last post:

    75 * (46700 / 86400) = 40.54%

Lastly, the algorithm accounts for a number of other possibilities. For instance, if the bot's vote power goes below the vote power threshold set in the settings file (see the installation instructions) then all vote weights for all delegators are 10% until the vote power raises back above the threshold. Also, the bot can be given a "cap" or maximum it upvotes. In this case, the maximum is 60%.

        if votepower > self.cfg.vote_power_threshold:
            numofposts = self.db.upvote_stats(3)
            for i in range(0, numofposts-1):
                # for each post we total the vote weight used, not the actual number of posts
                total_vote_weight_used += self.db.dbresults[i][3]
            # then we adjust based on the total weight used in the last 3 days
            # 800 is 80% of 1000, which is 10 votes at 100% per day (10 x 100)
            print (str(numofposts) + " previous posts in the last 3 days with " + str(total_vote_weight_used) + " total vote weight.")
            # although 3 days of vote power would be 3000, we use half that amount
            # to account for new users and surges in use. This helps to guarantee vote
            # power doesn't get drained too much
            adj = (1500 / total_vote_weight_used * 100)
            sec_since_last_vote = self.db.already_voted_today(account)
            minutes_since_last_vote = sec_since_last_vote / 60
            print ("Base percentage: " + str(adj) + "%")
            if adj > 60:
                adj = 60
                print ("Adjusted to 60.")
            print ("Minutes since last upvote: " + str(minutes_since_last_vote))
            if sec_since_last_vote is not False and int(sec_since_last_vote) < 86400:
                # if we voted them in the last 24 hours we scale the vote
                # based on how long ago the last vote was.
                if int(sec_since_last_vote) < 21600:
                    adj = 3
                else:
                    adj *= sec_since_last_vote / 86400
                print(account + " already got a vote in the last 24 hours. Adjusting vote further: " + str(adj) + "%")
                return adj
            else:
                if adj < 10:
                    adj = 10
                return adj
        else:
            return 10

Using Delegator Bot

Once DelegatorBot is installed, and your PATH is configured, you can run the bot simply by typing runbot at the commandline, which will bring up the menu below. To use these command options, type the command runbot followed by the command option. For example, to have the bot upvote and resteem all those it's following simply enter in runbot run. Running DelegatorBot this way will cause it to use the settings.py file by default. If you'd like to have more than one bot, you can create seperate settings.py file with new names, which can be used at the commandline. So, if you copied the settings.py file to a new file called myfilename.py, you can now run that particular bot with the command runbot run myfilename.

menu.png

run

This command should be executed regularly so that the bot can find new posts created by delegators and give them an upvote and a reply as well as resstem them to the bot's page. As the bot gains more delegators this command can take some time to finish executing, so make sure to use a lockfile in cron or find a way to aviod collisions.

report

This should be run daily.

steemboost and sbdboost

These two commands can be used optionally to send bids to bid bots to "boost" the value of the daily report. You can set how much of either is sent, to which bid bots, as well as a maximum number of times to occur.

claim

The bot can be put into a cycle of of powering down, boosting and claiming.

balance

Prints the bot's STEEM, SBD, STEEM POWER balance to screen. Nothing more.

delegators

To have the bot upvote, resteem and reply, it must be following a steem account. This command causes it to run through it's recent history on the steem blockchain to see if there are any new delegations. If so it follows or unfollows based on the amount delegated. Essentially this means that any delegation below the minimum_delegation set in the settings file will cause the bot to stop following. To "undelegate" means to "delegate 0".

stoppers

Optionally, a delegator can have the bot stop following them without undelegating by using this option. They simply need to reply to one of the bot's recent replies to their own post with the single word STOP in all capital letters.

Setting up automation

Using the direct path to the runbot entry point, a cron job can be set up that looks something like this (using a virtual environment):

#   Stoppers
26,55 * * * * /usr/bin/flock -w 10 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot stoppers artturtle
28,58 * * * * /usr/bin/flock -w 10 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot stoppers tommyknockers

#   Run bot
0 * * * * /usr/bin/flock -w 10 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot run artturtle
30 * * * * /usr/bin/flock -w 10 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot run tommyknockers

#   Daily report
15 7 * * * /usr/bin/flock /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot report artturtle
15 6 * * * /usr/bin/flock /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot report tommyknockers

#   Steem Boost
20 */2 * * * /usr/bin/flock -w 20 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot steemboost artturtle
22 */2 * * * /usr/bin/flock -w 20 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot steemboost tommyknockers

#   SBD Boost
45 */4 * * * /usr/bin/flock -w 20 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot sbdboost artturtle
47 */4 * * * /usr/bin/flock -w 20 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot sbdboost tommyknockers

#   Claim
15 8 * * * /usr/bin/flock -w 20 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot claim artturtle
15 7 * * * /usr/bin/flock -w 20 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot claim tommyknockers

#   Delegators
45 */4 * * * /usr/bin/flock -w 20 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot delegators artturtle
47 */4 * * * /usr/bin/flock -w 20 /$HOME/$USER/cronlock/lockfile /$HOME/$USER/DelegatorBot/env/bin/runbot delegators tommyknockers

Technology Stack

DelegatorBot 1.0 is written in Python 3.5 and uses MySQL
Complete list of dependencies

Roadmap

Many improvements can be made. First on this list will be a more rugged exception system. As well as the ability to customize the post and reply templates as well as the vote weight algorithm for each bot.

Contact

Please contact Mike (Mike-A) on Discord
https://discord.gg/hTfBZS3

GitHub Account

https://github.com/artolabs

Sort:  
  • Good article, well structured with images, usage and output examples.
  • Good commit comments and code comments as well.
  • The intro image would look better if it was not as big.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Chat with us on Discord.

[utopian-moderator]

Thank you for your review, @helo! Keep up the good work!


Welcome to Steem @learnelectronics.

Do read A thumb rule for steemit minnows - 50:100:200:25 for starter tips.

Spend time reading Steem Blue Paper to know how Steem blockchain works and if you still have any queries ask them on our Ask me anything about Steemit post and we will try to answer that.

You can earn Steem rewards for reading and sharing your insights using our Highlights Extension

All the Best!!!

Hi and welcome here! When I started on steemit, my biggest problem was to find interesting people to interact with. So, to help newcomers getting started I created a directory with other interesting and or talented steemians to follow or interact with. Feel free to check it out at https://www.steemiandir.com I am sure it will help you find like-minded people. Enjoy your stay here and do not hesitate to contact me if you have any questions!

Welcome to Steem learnelectronics! Partiko is officially the fastest and most popular mobile app for Steem. Unlike other Steem apps, we take 0% cut of your earnings! You can also be rewarded with Partiko Points while using Partiko and exchange Partiko Points for upvotes!

Partiko for Android can be downloaded here on Google Play and the iOS version is available here on the App Store.

If you have more questions, feel free to join our Discord channel and ask @crypto.talk, we're always here to help!

Thank you so much for your interest!

Thank you learnelectronics! You've just received an upvote of 37% by artturtle!


Learn how I will upvote each and every one of your posts



Please come visit me to see my daily report detailing my current upvote power and how much I'm currently upvoting.

Hi @learnelectronics!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @learnelectronics!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Thank you learnelectronics! You've just received an upvote of 60% by tommyknockers!


Learn how I will upvote each and every one of your posts



Please come visit me to see my daily report detailing my current upvote power and how much I'm currently upvoting.