Created
May 15, 2012 03:58
-
-
Save jugyo/2699021 to your computer and use it in GitHub Desktop.
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
# exclude plugin | |
# ==== | |
# | |
Earthquake.init do | |
_ = config[:exclude] ||= {} | |
_[:enable] ||= true | |
_[:file] ||= File.join(config[:dir], 'exclude') | |
_[:users] ||= File.exists?(_[:file]) ? File.read(_[:file]).split(/\n/) : [] | |
command :exclude do | |
puts(_[:users].map { |i| i.c(color_of(i)) }.join(' ')) | |
end | |
command :exclude do |m| | |
users = _extract_users(m[1]) | |
_[:users] += users | |
_[:users].uniq! | |
_[:users].sort! | |
_store_to_exclude(_[:users], _[:file]) | |
puts "exclude: #{users.join(', ')}".c(:info) | |
end | |
command :unexclude do |m| | |
users = _extract_users(m[1]) | |
_[:users] -= users | |
_store_to_exclude(_[:users], _[:file]) | |
puts "unexclude: #{users.join(', ')}".c(:info) | |
end | |
command :edit_exclude do | |
editor = ENV["EDITOR"] || 'vim' | |
system "#{editor} #{_[:file]}" | |
end | |
output_filter do |item| | |
next true unless _[:enable] && item["text"] && item["_stream"] | |
!_[:users].include?(item["user"]["screen_name"]) | |
end | |
def self._extract_users(arg) | |
arg.split(/\s/).map {|i| i.sub(/^@/, '')} | |
end | |
def self._store_to_exclude(users, filename) | |
File.open(filename, 'w') do |file| | |
file << users.join("\n") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment