Skip to content

Instantly share code, notes, and snippets.

Last active February 26, 2018 21:20
What would you like to do?
Mr. Krabs (`mrkrabs.rb`) is a self-voting bot. The goal is to self-vote using certain rules. See:
Mr. Krabs is a self-voting bot that uses rules you set like posts having 60 votes or 6 days old.
  • Title: mrkrabs.rb - Self Voting Bot
  • Tags: radiator ruby steem steemdev curation
  • Notes:

Mr. Krabs is a reimplementation of Dr. Phil, but instead of voting for new articles, it self-votes for posts and comments you write, after certain rules are met. By default, it votes for posts that reach 60 votes or is 6 days old. The default for comments is 6 votes or 6 days old.


  • YAML config.
    • voting_rules
      • vote_weight a static percentage (like 100.00 %)
      • history_limit used to set how far back to look in account history.
      • enable_comments option to vote for post replies (default false).
      • min_post_age allows you to only upvote once a post has reached a certain age
      • min_comment_age allows you to only upvote once a comment has reached a certain age
      • min_post_votes allows you to only upvote once a post has reached a certain number of votes
      • min_comment_votes allows you to only upvote once a comment has reached a certain number of votes
      • poll_time how often to check for new content (in seconds)
    • accounts List of accounts to vote on, e.g: account wif
      • Or use accounts: accounts.txt
        • The format for the file is just: account wif (no leading dash, separated by space)


The goal is to vote after the rules have been met. Setting 60 votes or 6 hours will have Mr. Krabs vote in either situation, whichever happens first.


To use this Radiator bot:

$ sudo apt-get update
$ sudo apt-get install ruby-full git openssl libssl1.0.0 libssl-dev
$ sudo apt-get upgrade
$ gem install bundler
$ gem install bundler

You can try the system version of ruby, but if you have issues with that, use this how-to, and come back to this installation at Step 4:

I've tested it on various versions of ruby. The oldest one I got it to work was:

ruby 2.0.0p645 (2015-04-13 revision 50299) [x86_64-darwin14.4.0]


First, clone this gist and install the dependencies:

$ git clone mrkrabs
$ cd mrkrabs
$ bundle install

Then run it:

$ ruby mrkrabs.rb

Mr. Krabs will now do it's thing. Check here to see an updated version of this bot:


Typically, you can upgrade to the latest version by this command, from the original directory you cloned into:

$ git pull

Usually, this works fine as long as you haven't modified anything. If you get an error, try this:

$ git stash --all
$ git pull --rebase
$ git stash pop

If you're still having problems, I suggest starting a new clone.


Problem: What does this error mean?
mrkrabs.yml:1: syntax error, unexpected ':', expecting end-of-input
Solution: You ran ruby mrkrabs.yml but you should run ruby mrkrabs.rb.

Problem: Everything looks ok, but every time Mr. Krabs tries to vote, I get this error:
Unable to vote with <account>.  Invalid version
Solution: You're trying to vote with an invalid key.

Make sure the .yml file voter items have the account name, followed by a space, followed by the account's WIF posting key. Also make sure you have removed the example accounts (social and bad.account are just for testing).

Problem: The node I'm using is down.

Is there a list of nodes?

Solution: Yes, see:

*Image Source: [](*

See my previous Ruby How To posts in: /f/ruby

Get in touch!

If you're using Mr. Krabs, I'd love to hear from you. Drop me a line and tell me what you think! I'm @inertia on STEEM and SteemSpeak.


I don't believe in intellectual "property". If you do, consider Mr. Krabs as licensed under a Creative Commons CC0 License.

source ''
gem 'radiator'
gem 'awesome_print'
awesome_print (1.8.0)
bitcoin-ruby (0.0.15)
connection_pool (2.2.1)
ffi (1.9.21)
hashie (3.5.7)
json (2.1.0)
little-plugger (1.1.4)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
multi_json (1.13.1)
net-http-persistent (3.0.0)
connection_pool (~> 2.2)
radiator (0.3.15)
awesome_print (~> 1.7, >= 1.7.0)
bitcoin-ruby (~> 0.0, >= 0.0.11)
ffi (~> 1.9, >= 1.9.18)
hashie (~> 3.5, >= 3.5.5)
json (~> 2.0, >= 2.0.2)
logging (~> 2.2, >= 2.2.0)
net-http-persistent (>= 2.5.2)
:vote_weight: 100.0 %
:history_limit: 2000
:enable_comments: false
:min_post_age: 518400 # 6 days
:min_comment_age: 518400
:min_post_votes: 60
:min_comment_votes: 6
:poll_time: 600 # polls accounts every 10 minutes
- social 5JrvPrQeBBvCRdjv29iDvkwn3EQYZ9jqfAHzrCyUvfbEbRkrYFC
- bad.account 5XXXBadWifXXXdjv29iDvkwn3EQYZ9jqfAHzrCyUvfbEbRkrYFC
:chain: golos
# Mr. Krabs (mrkrabs) watches account posts/comments to self-vote with rules.
# See:
require 'rubygems'
require 'bundler/setup'
require 'yaml'
# require 'irb'
defined? Thread.report_on_exception and Thread.report_on_exception = true
MAX_AGE = 60 * 60 * 24 * 6.5
@config_path = __FILE__.sub(/\.rb$/, '.yml')
unless File.exist? @config_path
puts "Unable to find: #{@config_path}"
def parse_accounts(accounts)
case accounts
when String
raise "Not found: #{accounts}" unless File.exist? accounts
hash = {}, 'r').each do |line|
key, value = line.split(' ')
hash[key] = value if !!key && !!hash
when Array
a ={ |v| v.split(' ')}.flatten.each_slice(2)
return a.to_h if a.respond_to? :to_h
hash = {}
accounts.each_with_index do |e|
key, val = e.split(' ')
hash[key] = val
else; raise "Unsupported accounts: #{accounts}"
@config = YAML.load_file(@config_path)
rules = @config[:voting_rules]
@voting_rules = {
vote_weight: (((rules[:vote_weight] || '100.0 %').to_f) * 100).to_i,
history_limit: rules[:history_limit].to_i,
enable_comments: rules[:enable_comments],
min_post_age: rules[:min_post_age].to_i,
min_comment_age: rules[:min_comment_age].to_i,
min_post_votes: rules[:min_post_votes].to_i,
min_comment_votes: rules[:min_comment_votes].to_i,
poll_time: rules[:poll_time].to_i,
@voting_rules =*@voting_rules.keys).new(*@voting_rules.values)
@accounts = parse_accounts(@config[:accounts])
@options = @config[:chain_options]
@options[:logger] =\.rb$/, '.log'))
@api = nil
def vote(account_name, wif, content)
slug = "#{}/#{content.permlink}"
puts "Found content, ready for self-vote: #{slug}"
tx = wif)
tx.operations << {
type: :vote,
voter: account_name,
permlink: content.permlink,
weight: @voting_rules.vote_weight
ap tx.process(true)
def content_type(op)
op.parent_author == '' ? :post : :comment
def content_age(trx)
content_created = Time.parse(trx.timestamp + 'Z') - content_created
def skip?(trx, account_name)
type, op = trx.op
return true unless type == 'comment'
return true if content_age(trx) > MAX_AGE
return true unless == account_name
def can_vote?(content, trx, account_name)
return false if == '' # content proably deleted
active_votes = content.active_votes
vote_size = active_votes.size
content_age = content_age(trx)
return false if account_name
case content_type(content)
when :post
return true if vote_size >= @voting_rules.min_post_votes
return content_age >= @voting_rules.min_post_age
when :comment
return false if !@voting_rules.enable_comments
return true if vote_size >= @voting_rules.min_comment_votes
return content_age >= @voting_rules.min_comment_age
puts "Now polling every #{@voting_rules.poll_time / 60} minutes ..."
loop do
@api ||=
@accounts.each do |account_name, wif|
puts "Looking for content by #{account_name} ..."
@api.get_account_history(account_name, -1, @voting_rules.history_limit) do |history, error|
ap(error) and break unless error.nil?
history.each do |idx, trx|
type, op = trx.op
next if skip?(trx, account_name)
@api.get_content(, op.permlink) do |content, error|
ap(error) and break unless error.nil?
if can_vote?(content, trx, account_name)
vote(account_name, wif, content)
sleep @voting_rules.poll_time
rescue => e
@api = nil
ap({error: "Unable to poll on current node. Retrying in 5 seconds. Error: #{e}", backtrace: e.backtrace})
sleep 5
:vote_weight: 100.0 %
:history_limit: 10000
:enable_comments: false
:min_post_age: 518400 # 6 days
:min_comment_age: 518400
:min_post_votes: 60
:min_comment_votes: 6
:poll_time: 600 # polls accounts every 10 minutes
- social 5JrvPrQeBBvCRdjv29iDvkwn3EQYZ9jqfAHzrCyUvfbEbRkrYFC
- bad.account 5XXXBadWifXXXdjv29iDvkwn3EQYZ9jqfAHzrCyUvfbEbRkrYFC
:chain: steem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment