-
-
Save Phize/1528690 to your computer and use it in GitHub Desktop.
keyword plugin for Earthquake(Ruby based Twitter client)
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} | |
# | |
Earthquake.init do | |
_ = config[:keyword] ||= {} | |
_[:notify] = true if _[:notify].nil? | |
_[:filter] = false if _[:filter].nil? | |
output_filter do |item| | |
next if item["text"].nil? || item["user"]["id_str"] == twitter.info['id_str'] | |
next true if _[:pattern].nil? | |
words = item["text"].scan(_[:pattern]) | |
unless words.empty? | |
item["_highlights"] ||= [] | |
item["_highlights"] += words | |
true | |
else | |
_[:filter] && item["_stream"] ? false : true | |
end | |
end | |
output do |item| | |
next if item["text"].nil? || item["user"]["id_str"] == twitter.info['id_str'] | |
next unless !_[:pattern].nil? && _[: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