Class: Cinch::Plugins::TwitterWatch
- Inherits:
-
Object
- Object
- Cinch::Plugins::TwitterWatch
- Includes:
- Cinch::Plugin
- Defined in:
- lib/cinch/plugins/twitterwatch/version.rb,
lib/cinch/plugins/twitterwatch/cache.rb,
lib/cinch/plugins/twitterwatch.rb
Overview
Cinch Plugin to post twitter statuses
Defined Under Namespace
Classes: Cache
Constant Summary collapse
- VERSION =
'1.0.2'
Instance Method Summary collapse
- #check_for_tweet(w) ⇒ Object
- #check_watched ⇒ Object
- #format_tweet(url) ⇒ Object
-
#initialize(*args) ⇒ TwitterWatch
constructor
A new instance of TwitterWatch.
- #tweet_text(user, status) ⇒ Object
Constructor Details
#initialize(*args) ⇒ TwitterWatch
Returns a new instance of TwitterWatch.
13 14 15 16 17 |
# File 'lib/cinch/plugins/twitterwatch.rb', line 13 def initialize(*args) super @client = twitter_client @watched = build_watchers end |
Instance Method Details
#check_for_tweet(w) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/cinch/plugins/twitterwatch.rb', line 30 def check_for_tweet(w) # Just check the last tweet, if they are posting more than once # every timer tick we don't want to spam the channel. debug "Checking Tweets for #{w.nick} (#{w.tweet_cache.count} cached)" tweet = @client.user(w.nick).status status = w.tweet_unless_cached(tweet.id) Channel(w.channel).msg(tweet_text(w.nick, status)) unless status.nil? end |
#check_watched ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cinch/plugins/twitterwatch.rb', line 19 def check_watched return unless @watched @watched.each { |w| check_for_tweet(w) } rescue Twitter::Error::NotFound debug 'You have set an invalid or protected user ' + 'to watch, please correct this error' rescue Twitter::Error::TooManyRequests debug 'Trottled checking user; sleeping 60 seconds.' sleep 60 end |
#format_tweet(url) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/cinch/plugins/twitterwatch.rb', line 39 def format_tweet(url) # Parse the url and get the relevant data user, status = parse_twitter_url(url) # Return blank if we didn't get a good user and status return if user.nil? || status.nil? tweet(user, status) end |
#tweet_text(user, status) ⇒ Object
49 50 51 52 53 |
# File 'lib/cinch/plugins/twitterwatch.rb', line 49 def tweet_text(user, status) # Scrub the tweet for returns so we don't have multilined responses. status.gsub!(/[\n]+/, ' ') if status.match(/\n/) "@#{user} tweeted \"#{status}\"" end |