unexist.dev

Changeset 319:5ba198868927

Added twitter scraper
author unexist
date Tue, 27 Mar 2012 17:01:21 +0200
parents 9c252218c7d3
children 413e677cb417
files bot/cinch.rb
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/bot/cinch.rb	Mon Mar 26 16:19:36 2012 +0200
+++ b/bot/cinch.rb	Tue Mar 27 17:01:21 2012 +0200
@@ -17,6 +17,8 @@
 require "xmlrpc/client"
 require "uri"
 require "time"
+require "json"
+require "cgi"
 
 # Config
 if "aral" == Socket.gethostname
@@ -114,6 +116,7 @@
           when "warnings"  then :yellow
           when "retry"     then :blue
           when "exception" then :red
+          when "skipped"   then :blue
         end,
         status
       )
@@ -472,6 +475,14 @@
             ]
           when "subforge.org", "subtle.de"
             m.reply "Title: %s (at %s)" % [ title, uri.host ]
+          when "twitter.com"
+            if link =~ /!\/.+?\/status\/(\d+)$/
+              json      = @agent.get("https://twitter.com/statuses/show/#{$1}.json").body
+              tweet     = JSON.parse(json)
+              unescaped = CGI.unescapeHTML(tweet["text"])
+
+              m.reply "@%s: %s" % [ tweet["user"]["screen_name"], unescaped ]
+            end
           else
             # Check if we know it
             u = Uri.first(:uri => link, :channel => m.channel.name)