Last active
May 17, 2020 19:21
-
-
Save inertia186/4b448709022a9744dbfe7fe9c3dd3f99 to your computer and use it in GitHub Desktop.
Communities Moderation Automation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"tts": "Bot", | |
"steem-plus": "Bot", | |
"steem-ua": "Bot", | |
"steemitboard": "Bot", | |
"trendotoken": "Bot", | |
"stem.curate": "Notification", | |
"steemstem": "Notification", | |
"randowhale": "Notification", | |
"discovery-it": "Notification", | |
"esteemapp": "Notification", | |
"beerlover": "Notification", | |
"pocket-pi": "Notification", | |
"resteemsupport": "Notification", | |
"c-squared": "Notification", | |
"tipu": "Notification", | |
"freevoter": "Notification", | |
"helpiecake": "Notification", | |
"coffeea.token": "Notification", | |
"irmao-joao": "Spammer", | |
"humanity-doctor": "Spammer", | |
"hero777": "Spammer", | |
"be-good-always": "Spammer", | |
"theoldpath": "Spammer", | |
"captain-whale": "Spammer", | |
"church-of-god": "Spammer", | |
"churchofgod": "Spammer", | |
"city-of-truth": "Spammer", | |
"gangstalking": "Spammer", | |
"pode": "Spammer", | |
"esecholo": "Spammer", | |
"hiroyamagishi": "Spammer", | |
"angdatingdaan": "Spammer", | |
"stopthemarkymark": "Spammer", | |
"lasseehlers": "Flat-Earther", | |
"marcos-708": "Spammer", | |
"kiraxoy": "Spammer", | |
"mark123": "Spammer" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
abort "Usage: ruby #{__FILE__} <community>" if ARGV.empty? | |
#JSON[`curl -s --data '{"jsonrpc":"2.0", "method":"bridge.account_notifications", "params":{"account":"#{account}","limit":100}, "id":1}' https://api.openhive.network`] | |
community = ARGV[0] | |
all_comments = HiveSQL::Comment.joins(:community_record).community(community) | |
roles = HiveSQL::CommunityRole.community(community).account(all_comments.select(:author)).where.not(title: '') | |
comments_without_roles = all_comments.where.not(author: roles.select(:account)) | |
puts "Authors found: #{all_comments.distinct.count(:author)}" | |
puts "Authors without titles: #{comments_without_roles.distinct.count(:author)}" | |
puts comments_without_roles.distinct.pluck(:author) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'hive-ruby', require: 'hive' | |
gem 'radiator' | |
gem 'highline' | |
gem 'hive_sql' | |
gem 'awesome_print' | |
gem 'pry' | |
gem 'rb-readline' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: https://rubygems.org/ | |
specs: | |
activemodel (5.2.4.1) | |
activesupport (= 5.2.4.1) | |
activerecord (5.2.4.1) | |
activemodel (= 5.2.4.1) | |
activesupport (= 5.2.4.1) | |
arel (>= 9.0) | |
activerecord-sqlserver-adapter (5.2.0) | |
activerecord (~> 5.2.0) | |
tiny_tds | |
activesupport (5.2.4.1) | |
concurrent-ruby (~> 1.0, >= 1.0.2) | |
i18n (>= 0.7, < 2) | |
minitest (~> 5.1) | |
tzinfo (~> 1.1) | |
arel (9.0.0) | |
awesome_print (1.8.0) | |
base58 (0.2.3) | |
bindata (2.4.7) | |
bitcoin-ruby (0.0.20) | |
eventmachine | |
ffi | |
scrypt | |
coderay (1.1.2) | |
concurrent-ruby (1.1.6) | |
connection_pool (2.2.2) | |
domain_name (0.5.20190701) | |
unf (>= 0.0.5, < 1.0.0) | |
eventmachine (1.2.7) | |
ffi (1.12.2) | |
ffi-compiler (1.0.1) | |
ffi (>= 1.0.0) | |
rake | |
hashie (3.6.0) | |
highline (2.0.3) | |
hive-ruby (1.0.0.pre.1) | |
base58 (~> 0.2, >= 0.2.3) | |
bindata (~> 2.4, >= 2.4.4) | |
bitcoin-ruby (~> 0.0, >= 0.0.18) | |
ffi (~> 1.9, >= 1.9.23) | |
hashie (~> 3.5, >= 3.5.7) | |
json (~> 2.1, >= 2.1.0) | |
logging (~> 2.2, >= 2.2.0) | |
hive_sql (1.0.0.pre.2) | |
activerecord (>= 4, < 6) | |
activerecord-sqlserver-adapter (>= 4, < 6) | |
activesupport (>= 4, < 6) | |
awesome_print (~> 1.7, >= 1.7.0) | |
nokogiri (~> 1.8) | |
rest-client (~> 2.0) | |
tiny_tds (~> 2.1) | |
http-accept (1.7.0) | |
http-cookie (1.0.3) | |
domain_name (~> 0.5) | |
i18n (1.8.2) | |
concurrent-ruby (~> 1.0) | |
json (2.3.0) | |
little-plugger (1.1.4) | |
logging (2.2.2) | |
little-plugger (~> 1.1) | |
multi_json (~> 1.10) | |
method_source (0.9.2) | |
mime-types (3.3.1) | |
mime-types-data (~> 3.2015) | |
mime-types-data (3.2019.1009) | |
mini_portile2 (2.4.0) | |
minitest (5.14.0) | |
multi_json (1.14.1) | |
net-http-persistent (3.1.0) | |
connection_pool (~> 2.2) | |
netrc (0.11.0) | |
nokogiri (1.10.8) | |
mini_portile2 (~> 2.4.0) | |
pry (0.12.2) | |
coderay (~> 1.1.0) | |
method_source (~> 0.9.0) | |
radiator (0.4.7) | |
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) | |
rake (13.0.1) | |
rb-readline (0.5.5) | |
rest-client (2.1.0) | |
http-accept (>= 1.7.0, < 2.0) | |
http-cookie (>= 1.0.2, < 2.0) | |
mime-types (>= 1.16, < 4.0) | |
netrc (~> 0.8) | |
scrypt (3.0.7) | |
ffi-compiler (>= 1.0, < 2.0) | |
thread_safe (0.3.6) | |
tiny_tds (2.1.2) | |
tzinfo (1.2.6) | |
thread_safe (~> 0.1) | |
unf (0.1.4) | |
unf_ext | |
unf_ext (0.0.7.6) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
awesome_print | |
highline | |
hive-ruby | |
hive_sql | |
pry | |
radiator | |
rb-readline | |
BUNDLED WITH | |
2.1.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
communities = HiveSQL::Community.all.includes(:admin_roles) | |
communities = communities.query(ARGV.join(' '), include_roles: true) if ARGV.any? | |
communities.order(TS: :asc).each do |community| | |
admin = community.admin_roles.first.account rescue '???' | |
puts "https://hive.blog/created/#{community.name}: \"#{community.title}\" by #{admin}" | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
#abort "Usage: ruby #{__FILE__} [community]" if ARGV.empty? | |
community = ARGV[0] | |
ops = HiveSQL::Tx::Custom::Community.op('flagPost') | |
ops = ops.community(community) if !!community | |
ops.find_each do |op| | |
puts "#{op.required_posting_auths}: #{op.payload['notes']} (#{op.payload['community']})" | |
puts "\thttps://hive.blog/@#{op.payload['account']}/#{op.payload['permlink']}" | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
#abort "Usage: ruby #{__FILE__} [community]" if ARGV.empty? | |
community = ARGV[0] | |
ops = HiveSQL::Tx::Custom::Community.op('mutePost') | |
ops = ops.community(community) if !!community | |
ops.find_each do |op| | |
puts "#{op.required_posting_auths}: #{op.payload['notes']} (#{op.payload['community']})" | |
puts "\thttps://hive.blog/@#{op.payload['account']}/#{op.payload['permlink']}" | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
#abort "Usage: ruby #{__FILE__} [community]" if ARGV.empty? | |
community = ARGV.join(' ') | |
roles = HiveSQL::CommunityRole.includes(:community_record) | |
roles = if !!community && (community =~ /hive.*/) | |
roles.community(community) | |
elsif !!community | |
roles.query(community) | |
else | |
roles | |
end | |
roles.each do |role| | |
print "#{role.account}: #{role.role}" | |
print " - \"#{role.title}\"" unless role.title.to_s.empty? | |
puts " (#{role.community} #{role.community_record.title})" | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
#abort "Usage: ruby #{__FILE__} [community]" if ARGV.empty? | |
community = ARGV.join(' ') | |
subscribers = HiveSQL::CommunitySubscriber.includes(:community_record) | |
subscribers = if !!community && (community =~ /hive.*/) | |
subscribers.community(community) | |
elsif !!community | |
subscribers.query(community) | |
else | |
subscribers | |
end | |
subscribers.each do |subscriber| | |
print "#{subscriber.subscriber}: " | |
print subscriber.community | |
puts " (#{subscriber.community_record.title})" | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
#abort "Usage: ruby #{__FILE__} [community]" if ARGV.empty? | |
community = ARGV[0] | |
roles = HiveSQL::CommunityRole.where.not(title: '') | |
roles = roles.community(community) if !!community | |
roles.each do |role| | |
puts "#{role.community} #{role.account}: #{role.title}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
abort "#{__FILE__} <slug> <title> <notes>" if ARGV.length < 2 | |
cli = HighLine.new | |
moderator_name = cli.ask 'Moderator: ' | |
wif = cli.ask 'Posting WIF: ' do |q| | |
q.echo = '*' | |
end | |
pretend = !wif || wif.size == 0 | |
api = Hive::Api.new | |
options = {chain: :steem, url: 'https://api.openhive.network'} | |
options = options.merge(wif: wif) unless pretend | |
tx = Radiator::Transaction.new(options) | |
ops = [] | |
slug = ARGV[0] | |
title = ARGV[1] | |
notes = ARGV[2] | |
author, permlink = slug.split('/') | |
author = author.split('@').last | |
api.get_accounts([author]) do |accounts| | |
abort "Cannot find author: #{author}" if accounts.empty? | |
end | |
comment = HiveSQL::Comment.joins(:community_record).find_by_author_and_permlink(author, permlink) | |
if comment.nil? || !(comment.category =~ /hive-.*/) | |
abort "Umoderated content: #{slug}" | |
end | |
community = comment.category | |
mods = HiveSQL::CommunityRole.community(community).account(moderator_name) | |
moderator_role = mods.pluck(:role).last | |
unless %w(mod admin).include? moderator_role | |
abort "Not a mod of #{community}: #{moderator_name}" | |
end | |
existing_titles = HiveSQL::Tx::Custom::Community.op('setUserTitle').community(community).account(author) | |
if existing_titles.any? | |
has_titles = [author] - existing_titles.map{|op| op.payload['account']} | |
puts "Already set title for: #{author}" | |
else | |
data = [:setUserTitle, {community: community, account: author, title: title}] | |
set_user_title = { | |
type: :custom_json, | |
required_auths: [], | |
required_posting_auths: [moderator_name], | |
id: 'community', | |
json: data.to_json | |
} | |
puts set_user_title.to_json | |
ops << set_user_title | |
end | |
existing_roles = HiveSQL::CommunityRole.community(community).account(author) | |
if existing_roles.any? | |
puts "Already set role: #{author}" | |
else | |
data = [:setRole, {community: community, account: author, role: 'muted'}] | |
set_role = { | |
type: :custom_json, | |
required_auths: [], | |
required_posting_auths: [moderator_name], | |
id: 'community', | |
json: data.to_json | |
} | |
puts set_role.to_json | |
ops << set_role | |
end | |
existing_mutes = HiveSQL::Tx::Custom::Community.op('mutePost').community(community).account(author) | |
community_content = HiveSQL::Comment.joins(:community_record).community(community).author(author) | |
if existing_mutes.any? | |
puts "Already muted content: #{author} (mutes: #{existing_mutes.count}, content: #{community_content.count})" | |
if existing_mutes.count != community_content.count | |
puts "Existing mutes:" | |
existing_mutes.find_each do |m| | |
puts m.payload | |
end | |
puts "Community content (note, may include content from when after role was set):" | |
community_content.find_each do |c| | |
puts "https://hive.blog/@#{c.author}/#{c.permlink}" | |
end | |
end | |
else | |
community_content.find_each do |c| | |
data = [:mutePost, {community:community, account: c.author, permlink: c.permlink, notes: notes}] | |
mute_post = { | |
type: :custom_json, | |
required_auths: [], | |
required_posting_auths: [moderator_name], | |
id: 'community', | |
json: data.to_json | |
} | |
puts mute_post.to_json | |
ops << mute_post | |
end | |
end | |
ops.each_slice(5) do |slice| | |
tx.operations = slice | |
ap tx.process(!pretend) | |
end | |
exit if ops.size == 0 # Did nothing, don't update community-mutes. | |
community_mutes = File.open('community-mutes.json') do |f| | |
JSON[f.read] | |
end | |
community_mutes = File.open('community-mutes.json', 'w') do |f| | |
community_mutes[author] = title | |
f.write JSON.pretty_generate community_mutes | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
cli = HighLine.new | |
account_name = cli.ask 'Account: ' | |
wif = cli.ask 'Active WIF: ' do |q| | |
q.echo = '*' | |
end | |
url = 'https://api.openhive.network' | |
tx = Radiator::Transaction.new(wif: wif, url: url) | |
community = ARGV[0] | |
slug = ARGV[1] | |
slug = slug.split('@').last | |
author = slug.split('/')[0] | |
permlink = slug.split('/')[1..-1].join('/') | |
data = [ | |
:pinPost, { | |
community: community, | |
account: author, | |
permlink: permlink | |
} | |
] | |
pin = { | |
type: :custom_json, | |
required_auths: [], | |
required_posting_auths: [account_name], | |
id: 'community', | |
json: data.to_json | |
} | |
puts pin.to_json | |
tx.operations << pin | |
puts tx.process(true) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
abort "#{__FILE__} <community> <account(s)> <title> [force]" if ARGV.length < 3 | |
cli = HighLine.new | |
moderator_name = cli.ask 'Account: ' | |
wif = cli.ask 'Posting WIF: ' do |q| | |
q.echo = '*' | |
end | |
pretend = !wif || wif.size == 0 | |
options = {chain: :steem, url: 'https://anyx.io'} | |
options = options.merge(wif: wif) unless pretend | |
tx = Radiator::Transaction.new(options) | |
community = ARGV[0] | |
accounts = ARGV[1].split(',') | |
title = ARGV[2] | |
force = (ARGV[3] || 'false').downcase == 'true' | |
mods = HiveSQL::CommunityRole.community(community).account(moderator_name) | |
moderator_role = mods.pluck(:role).last | |
unless %w(mod admin).include? moderator_role | |
abort "Not a mod of #{community}: #{moderator_name}" | |
end | |
existing_titles = HiveSQL::Tx::Custom::Community.op('setUserTitle').community(community).account(accounts) | |
if existing_titles.any? | |
has_titles = accounts - existing_titles.map{|op| op.payload['account']} | |
if force | |
puts "Changing title for: #{accounts - has_titles}" | |
sleep 3 | |
else | |
abort "Already set title for: #{accounts - has_titles}" | |
end | |
end | |
accounts.each do |account| | |
data = [:setUserTitle, {community: community, account: account, title: title}] | |
set_user_title = { | |
type: :custom_json, | |
required_auths: [], | |
required_posting_auths: [moderator_name], | |
id: 'community', | |
json: data.to_json | |
} | |
puts set_user_title.to_json | |
tx.operations << set_user_title | |
end | |
ap tx.process(!pretend) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
abort "#{__FILE__} <community>" if ARGV.length < 1 | |
mutes = File.open('community-mutes.json') do |f| | |
JSON[f.read] | |
end | |
cli = HighLine.new | |
moderator_name = if !!ENV['MODERATOR_NAME'] | |
ENV['MODERATOR_NAME'] | |
else | |
cli.ask 'Moderator: ' | |
end | |
wif = if !!ENV['POSTING_WIF'] | |
ENV['POSTING_WIF'] | |
else | |
cli.ask 'Posting WIF: ' do |q| | |
q.echo = '*' | |
end | |
end | |
pretend = !wif || wif.size == 0 | |
api = Hive::Api.new | |
options = {chain: :steem, url: 'https://api.openhive.network'} | |
options = options.merge(wif: wif) unless pretend | |
tx = Radiator::Transaction.new(options) | |
ops = [] | |
community = ARGV[0] | |
existing_titles = HiveSQL::Tx::Custom::Community.op('setUserTitle').community(community).account(mutes.keys) | |
has_titles = existing_titles.map{|op| op.payload['account']} | |
puts "Already set title for: #{has_titles & mutes.keys}" | |
mutes.each do |author, title| | |
next if has_titles.include? author | |
data = [:setUserTitle, {community: community, account: author, title: title}] | |
set_user_title = { | |
type: :custom_json, | |
required_auths: [], | |
required_posting_auths: [moderator_name], | |
id: 'community', | |
json: data.to_json | |
} | |
puts set_user_title.to_json | |
ops << set_user_title | |
end | |
existing_roles = HiveSQL::CommunityRole.community(community).account(mutes.keys) | |
has_roles = existing_roles.pluck(:account) | |
puts "Already set roles for: #{has_roles & mutes.keys}" | |
mutes.keys.each do |mute| | |
next if has_roles.include? mute | |
data = [:setRole, {community: community, account: mute, role: 'muted'}] | |
set_role = { | |
type: :custom_json, | |
required_auths: [], | |
required_posting_auths: [moderator_name], | |
id: 'community', | |
json: data.to_json | |
} | |
puts set_role.to_json | |
ops << set_role | |
end | |
ops.each_slice(5) do |slice| | |
tx.operations = slice | |
ap tx.process(!pretend) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#export MODERATOR_NAME= | |
#export POSTING_WIF= | |
for community in hive-165317 hive-121361 hive-134561 hive-163521 hive-174796 hive-101863 hive-180170 hive-174461 hive-196481 hive-139531 | |
do | |
echo "https://hive.blog/created/$community" | |
#ruby setup_community.rb $community | |
ruby find_muted_authors.rb $community | |
done | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require | |
cli = HighLine.new | |
account_name = cli.ask 'Account: ' | |
wif = cli.ask 'Active WIF: ' do |q| | |
q.echo = '*' | |
end | |
url = 'https://api.openhive.network' | |
tx = Radiator::Transaction.new(wif: wif, url: url) | |
community = ARGV[0] | |
slug = ARGV[1] | |
slug = slug.split('@').last | |
author = slug.split('/')[0] | |
permlink = slug.split('/')[1..-1].join('/') | |
data = [ | |
:unpinPost, { | |
community: community, | |
account: author, | |
permlink: permlink | |
} | |
] | |
pin = { | |
type: :custom_json, | |
required_auths: [], | |
required_posting_auths: [account_name], | |
id: 'community', | |
json: data.to_json | |
} | |
puts pin.to_json | |
tx.operations << pin | |
puts tx.process(true) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment