Created
April 2, 2011 13:50
-
-
Save jugyo/899506 to your computer and use it in GitHub Desktop.
keyword
This file contains hidden or 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
# keyword plugin | |
# ==== | |
# | |
# config example: | |
# | |
# Earthquake.config[:keyword] = { | |
# :pattern => /ruby|rails|earthquake/i, | |
# :ignore => %w(jugyo yukihiro_matz), | |
# :filter => true, | |
# :notify => true | |
# } | |
# | |
Earthquake.init do | |
_ = config[:keyword] ||= {} | |
_[:ignore] ||= [] | |
_[:notify] = true if _[:notify].nil? | |
_[:filter] = false if _[:filter].nil? | |
# to filter | |
output_filter do |item| | |
next unless _[:pattern] && item["text"] | |
words = item["text"].scan(_[:pattern]) | |
unless words.empty? | |
item["_highlights"] ||= [] | |
item["_highlights"] += words | |
true | |
else | |
if item["_stream"] | |
if _[:filter] && _[:ignore].exclude?(item["user"]["screen_name"]) | |
false | |
else | |
true | |
end | |
else | |
true | |
end | |
end | |
end | |
# to notify | |
output do |item| | |
next unless _[:pattern] && _[:notify] && item["_stream"] && item["text"] | |
text = item["text"].u | |
if text =~ _[:pattern] && item["user"]["screen_name"] != twitter.info["screen_name"] | |
notify text, :title => item["user"]["screen_name"] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test comment