]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
twitter: fixes the htmlfilter used by url plugin
authorMatthias Hecker <apoc@sixserv.org>
Thu, 14 Nov 2013 14:49:52 +0000 (14:49 +0000)
committerMatthias Hecker <apoc@sixserv.org>
Thu, 14 Nov 2013 14:51:55 +0000 (14:51 +0000)
data/rbot/plugins/twitter.rb

index e661e63326a76daa4b4a071dc75ab6649256844a..16813c60118e1eb8d16ddbbb5dc5550e783cf0a4 100644 (file)
@@ -39,25 +39,25 @@ class TwitterPlugin < Plugin
     :desc => "Maximum number of status updates shown by 'twitter [home|mentions|retweets] status'")
 
   def twitter_filter(s)
-    loc = Utils.check_location(s, Regexp.new('twitter\.com/#!/.*/status/\d+'))
+    loc = Utils.check_location(s, Regexp.new('twitter\.com/(#!/)?.*/status/\d+'))
     return nil unless loc
     id = loc.first.match(/\/status\/(\d+)/)[1]
 
-    response = @app_access_token.get('/1.1/statuses/show/'+id).body
+    response = @app_access_token.get('/1.1/statuses/show/'+id+'.json').body
     begin
-      tweet = JSON.parse(response).first
+      tweet = JSON.parse(response)
       status = {
         :date => (Time.parse(tweet["created_at"]) rescue "<unknown>"),
-        :id => (tweet["id"].text rescue "<unknown>"),
+        :id => (tweet["id_str"] rescue "<unknown>"),
         :text => (tweet["text"].ircify_html rescue "<error>"),
-        :source => (tweet["source"].text rescue "<unknown>"),
+        :source => (tweet["source"].ircify_html rescue "<unknown>"),
         :user => (tweet["user"]["name"] rescue "<unknown>"),
         :user_nick => (tweet["user"]["screen_name"] rescue "<unknown>")
         # TODO other entries
       }
       status[:nicedate] = String === status[:date] ? status[:date] : Utils.timeago(status[:date])
       return {
-        :title => "#{status[:user]}/#{status[:id]}",
+        :title => "@#{status[:user_nick]}: #{status[:text]}",
         :content => "#{status[:text]} (#{status[:nicedate]} via #{status[:source]})"
       }
     rescue