class Cinch::Plugins::TwitterStatus
Cinch
Plugin to post twitter statuses
Versioning info
Constants
- VERSION
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/cinch/plugins/twitterstatus.rb, line 16 def initialize(*args) super @client = twitter_client end
Public Instance Methods
format_tweet(url)
click to toggle source
# File lib/cinch/plugins/twitterstatus.rb, line 31 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_text(user, status) end
listen(m)
click to toggle source
# File lib/cinch/plugins/twitterstatus.rb, line 21 def listen(m) Cinch::Toolbox.extract_urls(m.message).each do |url| next unless url.match(%r(^https?://mobile|w{3}?\.?twitter\.com/)) msg = format_tweet(url) m.reply msg unless msg.nil? end rescue Twitter::Error::NotFound, Twitter::Error::Forbidden debug 'User posted an invalid twitter status' end
tweet_text(user, status)
click to toggle source
# File lib/cinch/plugins/twitterstatus.rb, line 41 def tweet_text(user, status) # Scrub the tweet for returns so we don't have multilined responses. status = status.gsub(/[\n]+/, ' ') if status.match(/\n/) "@#{user} tweeted \"#{status}\"" end
Private Instance Methods
parse_twitter_url(url)
click to toggle source
# File lib/cinch/plugins/twitterstatus.rb, line 49 def parse_twitter_url(url) tweet_id = url[%r{statuse?s?/(\d+)/?}, 1] user = url[%r{/?#?!?/([^\/]+)/statuse?s?}, 1] [user, @client.status(tweet_id).text] end
twitter_client()
click to toggle source
# File lib/cinch/plugins/twitterstatus.rb, line 55 def twitter_client Twitter::REST::Client.new do |c| c.consumer_key = config[:consumer_key] c.consumer_secret = config[:consumer_secret] c.access_token = config[:access_token] c.access_token_secret = config[:access_secret] end end