Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

change !swineflu, !links

  • Loading branch information...
commit fa4c017989103b091a965192ca967d2c2eea2bfe 1 parent 9fe9bb6
lian authored May 05, 2009

Showing 1 changed file with 20 additions and 8 deletions. Show diff stats Hide diff stats

  1. 28  fatbot.rb
28  fatbot.rb
@@ -14,6 +14,7 @@
14 14
 
15 15
 # require 'sequel'
16 16
 # DB = Sequel.sqlite('irc.db')
  17
+$link_store ||= []
17 18
 
18 19
 configure do |c|
19 20
   c.nick     = "dubtron"
@@ -77,21 +78,32 @@ def ops?(nick)
77 78
 # swine flu report (USA only for now)
78 79
 # the CDC has a nice report with latest US stats, but not global
79 80
 on :channel, /^\!(swineflu|pigflu).*/ do
80  
-  url, shorturl = "http://www.cdc.gov/h1n1flu/index.htm", "http://bit.ly/eeat8"
81  
-  agent = WWW::Mechanize.new # TODO: use a global agent & set user-agent to FATBOT YEAH
82  
-  page = agent.get(url)
83  
-  totals = (page/'.mSyndicate strong')
84  
-  puts "no totals data!" and return if totals.nil? or totals[1].nil? or totals[2].nil?
85  
-  text = "#{totals[0].content}: #{totals[2].content}, #{totals[3].content} -- http://www.cdc.gov/h1n1flu/"
  81
+  url, shorturl, totals = "http://www.cdc.gov/h1n1flu/index.htm", "http://bit.ly/eeat8", []
  82
+  begin
  83
+    agent = WWW::Mechanize.new; page = agent.get(url)
  84
+    totals = (page/'.mSyndicate strong')[ 0..3 ].collect { |i| i.innerText }
  85
+    raise "no totals" if totals.size < 3
  86
+  rescue Exception => e
  87
+    text = (e.message == "no totals") ? "no totals data! #{totals.inspect}" : "Exception: #{e.message}"
  88
+  else
  89
+    text = "#{totals.first}: #{totals[2..3].join(", ")} -- http://www.cdc.gov/h1n1flu/"
  90
+  end
86 91
   msg channel, text
87  
-end 
  92
+end
88 93
 
89 94
 
90 95
 # do URL detection & logging, idea vi sh1v
91 96
 on :channel, /http\:\/\/(.*)\s?/ do
92  
-  puts "URL: #{match[0]} by #{nick}"
  97
+  $link_store << { :url => match[0], :nick => nick, :date => Time.now }
  98
+  $link_store.shift if $link_store.size > 10
  99
+  puts "URL: #{match[0]} by #{nick} : #{$link_store.size}"
93 100
 end
94 101
 
  102
+on :channel, /^\!(links|bookmarks).*/ do
  103
+  msg channel, $link_store.collect { |l| "#{l[:url]} by #{l[:nick]}" }.join("\n")
  104
+end
  105
+
  106
+
95 107
 # lastly, do logging
96 108
 # from http://github.com/jamie/ircscribe/
97 109
 # on :channel, /.*/ do

0 notes on commit fa4c017

Please sign in to comment.
Something went wrong with that request. Please try again.