]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Update threat plugin to new DHS site layout, and make it more robust
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 19 Oct 2006 21:52:10 +0000 (21:52 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 19 Oct 2006 21:52:10 +0000 (21:52 +0000)
data/rbot/plugins/threat.rb

index ae7091010de2ef4852dc2dc423beef6842f9756f..3784dafeaa80727899cce145e97dbdd5f5dc8602 100644 (file)
@@ -16,36 +16,39 @@ class ThreatPlugin < Plugin
   end
 
   def privmsg(m)
   end
 
   def privmsg(m)
-       color = ""
+    color = ""
     red = "\x0304" # severe
     red = "\x0304" # severe
-       orange = "\x0307" # high
-       yellow = "\x0308" # elevated
-       blue = "\x0312" # guarded
-       green = "\x0303" # low
-       black = "\x0301" # default
-
-       page = @bot.httputil.get URI.parse("http://www.dhs.gov/dhspublic/")
-       if page =~ / <img.*dhs\/images\/dhs-advisory-(.*).gif.*/
+    orange = "\x0307" # high
+    yellow = "\x0308" # elevated
+    blue = "\x0312" # guarded
+    green = "\x0303" # low
+    black = "\x0301" # default
+
+    page = @bot.httputil.get URI.parse("http://www.dhs.gov/")
+
+    if page =~ /\"Current National Threat Level is (.*?)\"/
       state = $1
       state = $1
-    end
-    case state
+      case state
       when "severe"
       when "severe"
-               color = red
+        color = red
       when "high"
       when "high"
-               color = orange
+        color = orange
       when "elevated"
       when "elevated"
-               color = yellow
+        color = yellow
       when "guarded"
       when "guarded"
-               color = blue
+        color = blue
       when "low"
       when "low"
-               color = green
-       else
-         color = black
-       end
-
-       m.reply color + "Today " + m.sourcenick + " the threat level is " + state.capitalize
+        color = green
+      else
+        color = black
+      end
+
+      m.reply color + "Today " + m.sourcenick + " the threat level is " + state.capitalize
+    else
+      m.reply "I was unable to retrieve the threat level"
+    end
 
 
-       return
+    return
   end
 
 end
   end
 
 end