How to Write a Vote Bot in Ruby
Now that Radiator supports transaction signing, I thought I'd combine it with the existing streaming capability. So this is a simple bot that mirrors other users and votes on the same things (posts and comments). It only upvotes if the original vote is an upvote.
To use this Radiator bot:
Linux
$ sudo apt-get install ruby-full git openssl libssl1.0.0 libssl-dev
$ gem install bundler
$ bundle config git.allow_insecure true
macOS
$ gem install bundler
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, make a project folder:
$ mkdir radiator
$ cd radiator
Create a file named Gemfile
containing:
source 'https://rubygems.org'
gem 'radiator', github: 'inertia186/radiator'
Then run the command:
$ bundle install
Create a file named tail_voters.rb
containing:
require 'rubygems'
require 'bundler/setup'
Bundler.require
wif = 'Your Posting Wif'
voter = 'your-account'
list = ['inertia', 'fyrstikken']
url = 'https://steemd.steemit.com'
stream = Radiator::Stream.new(url: url)
puts "Watching for votes by: #{list}"
stream.operations do |operation|
begin
op_key = operation.keys.first
op_value = operation.values.first
print '.'
next unless op_key == :vote
next unless list.include? op_value.voter
next unless op_value.weight > 0
author = op_value.author
permlink = op_value.permlink
puts "\nVoting on: #{author}/#{permlink}"
tx = Radiator::Transaction.new(wif: wif, url: url)
vote = {
type: :vote,
voter: voter,
author: author,
permlink: permlink,
weight: 10000
}
op = Radiator::Operation.new(vote)
tx.operations << op
tx.process(true)
rescue => e
puts e.inspect
end
end
Then run it:
$ ruby tail_voters.rb
The above example would vote for anything inertia
and fyrstikken
vote for.
Good job. Bots are evils ;)
Great to see more bot code open source 😆
If you'd like to contribute this to the Steem FOSSbot project, let me know, I would love to make you a collaborator, or "repost" this myself as a repo. 🙂