diff options
author | Matthias Hecker <apoc@sixserv.org> | 2013-11-14 15:51:26 +0000 |
---|---|---|
committer | Matthias Hecker <apoc@sixserv.org> | 2013-11-14 15:51:26 +0000 |
commit | a518b9d475ca8223c89cb036ee3841bab35e916b (patch) | |
tree | e8163220cbc31af67458573e782a04efd75236a8 /data | |
parent | c59034cc3fa2f36213dc198af372fec28219b659 (diff) |
twitter: filter ret.latest status if non specified
Diffstat (limited to 'data')
-rw-r--r-- | data/rbot/plugins/twitter.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/data/rbot/plugins/twitter.rb b/data/rbot/plugins/twitter.rb index 991b5bd3..3ed8e62c 100644 --- a/data/rbot/plugins/twitter.rb +++ b/data/rbot/plugins/twitter.rb @@ -38,14 +38,23 @@ class TwitterPlugin < Plugin :default => 3, :validate => Proc.new { |v| v > 0 && v <= 10}, :desc => "Maximum number of status updates shown by 'twitter [home|mentions|retweets] status'") + URL_PATTERN = %r{twitter\.com/([^/]+)(?:/status/(\d+))?} + def twitter_filter(s) - loc = Utils.check_location(s, Regexp.new('twitter\.com/(#!/)?.*/status/\d+')) + loc = Utils.check_location(s, URL_PATTERN) return nil unless loc - id = loc.first.match(/\/status\/(\d+)/)[1] - - response = @app_access_token.get('/1.1/statuses/show/'+id+'.json').body + matches = loc.first.match URL_PATTERN + if matches[2] # status id matched + id = matches[2] + url = '/1.1/statuses/show/%s.json' % id + else # no status id, get the latest status of that user + user = matches[1] + url = '/1.1/statuses/user_timeline.json?screen_name=%s&count=1&include_rts=true' % user + end + response = @app_access_token.get(url).body begin tweet = JSON.parse(response) + tweet = tweet.first if tweet.instance_of? Array status = { :date => (Time.parse(tweet["created_at"]) rescue "<unknown>"), :id => (tweet["id_str"] rescue "<unknown>"), |