Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created May 15, 2012 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugyo/2699021 to your computer and use it in GitHub Desktop.
Save jugyo/2699021 to your computer and use it in GitHub Desktop.
# 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