summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2011-12-21 23:29:35 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2011-12-21 23:31:35 +0100
commitd45c5f5eeba4bcdcc75c7991d4a1f8c390a76d01 (patch)
tree5db7e8242a413c32605222b11b02478992ccd2cf /data
parent498a240496b65b897572e3fde3ef19b296e9c003 (diff)
twitter: preliminary status htmlinfo filter
This allows the link info published by URL in the new /#!/ format to be more meaningful than the warning about missing JavaScript support caused by the new "web 2.0" Twitter site.
Diffstat (limited to 'data')
-rw-r--r--data/rbot/plugins/twitter.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/data/rbot/plugins/twitter.rb b/data/rbot/plugins/twitter.rb
index e4c228da..8725ac2c 100644
--- a/data/rbot/plugins/twitter.rb
+++ b/data/rbot/plugins/twitter.rb
@@ -39,6 +39,29 @@ class TwitterPlugin < Plugin
:default => 3, :validate => Proc.new { |v| v > 0 && v <= 10},
:desc => "Maximum number of status updates shown by 'twitter friends status'")
+ def twitter_filter(s)
+ loc = Utils.check_location(s, Regexp.new('twitter\.com/#!/.*/status/\d+'))
+ return nil unless loc
+ id = loc.first.match(/\/status\/(\d+)/)[1]
+ xml = @bot.httputil.get('http://api.twitter.com/1/statuses/show.xml?id=' + id)
+ return nil unless xml
+ root = REXML::Document.new(xml).root
+ status = {
+ :date => (Time.parse(root.elements["created_at"].text) rescue "<unknown>"),
+ :id => (root.elements["id"].text rescue "<unknown>"),
+ :text => (root.elements["text"].text.ircify_html rescue "<error>"),
+ :source => (root.elements["source"].text rescue "<unknown>"),
+ :user => (root.elements["user/name"].text rescue "<unknown>"),
+ :user_nick => (root.elements["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]}",
+ :content => "#{status[:text]} (#{status[:nicedate]} via #{status[:source]})"
+ }
+ end
+
def initialize
super
@@ -52,6 +75,8 @@ class TwitterPlugin < Plugin
val
end
end
+
+ @bot.register_filter(:twitter, :htmlinfo) { |s| twitter_filter(s) }
end
def report_oauth_missing(m, failed_action)