How to Automatically Ignore Accounts Created By ... Someone

Words
145
Reading
1 min
Listen
Play
9y

Some people like to create a bunch of accounts. And some people like to preemptively mute them. Here's a way to do that.

This assumes that the same person creates the accounts you want to mute. But this approach can be modified to work with other criteria like reputation instead.


As always, we use Radiator with bundler. You can get bundler with this command:

$ gem install bundler

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

ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin14.0]

First, make a project folder:

$ mkdir radiator
$ cd radiator

Create a file named Gemfile containing:

source 'https://rubygems.org'
gem 'radiator'
gem 'steem_api'
gem 'awesome_print'

Then run the command:

$ bundle install

Create a file named auto_mute_created_by.rb containing:

require 'rubygems'
require 'bundler/setup'

Bundler.require

if ARGV.size < 1 || ENV['ACCOUNT_NAME'].nil? || ENV['WIF'].nil?
  puts "Usage: ACCOUNT_NAME=name WIF=wif ruby #{__FILE__}  [broadcast]"
  exit
end

creator_account_name = ARGV[0]
broadcast = ARGV[1] == 'true'
account_name = ENV['ACCOUNT_NAME']
wif = ENV['WIF']
tx = Radiator::Transaction.new(wif: wif)
api = Radiator::FollowApi.new
ignoring = []
count = -1

until count == ignoring.size
  count = ignoring.size
  response = api.get_following(account_name, ignoring.last, 'ignore', 100)
  ignoring += response.result.map(&:following)
  ignoring = ignoring.uniq
end

accounts = SteemApi::Tx::AccountCreate.where(creator: creator_account_name)
accounts = accounts.where.not(new_account_name: ignoring)

puts "Ignoring accounts: #{accounts.count}"

accounts.find_each do |account|
  data = [:follow, {
      follower: account_name,
      following: account.new_account_name,
      what: ['ignore']
    }
  ]

  tx.operations << {
    type: :custom_json,
    id: 'follow',
    required_auths: [],
    required_posting_auths: [account_name],
    json: data.to_json
  }
end

result = tx.process(broadcast)

if result.class == Radiator::Transaction
  puts 'Not broadcasted.'
  exit
end

ap result

Then run it (here we're using social and its wif, which is public, but you can use your own):

$ ACCOUNT_NAME=social WIF=5JrvPrQeBBvCRdjv29iDvkwn3EQYZ9jqfAHzrCyUvfbEbRkrYFC ruby auto_mute_created_by.rb noganoo true

The expected output will be something like this:

Ignoring accounts: 35
{
    "result" => {
               "id" => "e567d344d4f0ba2d4419380f1fb618c98c0a1c03",
        "block_num" => 19128228,
          "trx_num" => 14,
          "expired" => false
    },
        "id" => 1
}

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