]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/threat.rb
[remote] server imho shouldnt be listen by default
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / threat.rb
1 # Security threat level plugin for rbot
2 # by Robin Kearney (robin@riviera.org.uk)
3 #
4 # inspired by elliots fascination with the us
5 # threat level.
6 #
7 # again a dirty hack but it works, just...
8 #
9
10 require 'uri/common'
11
12 class ThreatPlugin < Plugin
13
14   def help(plugin, topic="")
15     "threat => prints out the current threat level as reported by http://www.dhs.gov/"
16   end
17
18   def privmsg(m)
19     color = ""
20     red = "\x0304" # severe
21     orange = "\x0307" # high
22     yellow = "\x0308" # elevated
23     blue = "\x0312" # guarded
24     green = "\x0303" # low
25     black = "\x0301" # default
26
27     page = @bot.httputil.get("http://www.dhs.gov/index.shtm")
28
29     if page =~ /\"Current National Threat Level is (.*?)\"/
30       state = $1
31       case state
32       when "severe"
33         color = red
34       when "high"
35         color = orange
36       when "elevated"
37         color = yellow
38       when "guarded"
39         color = blue
40       when "low"
41         color = green
42       else
43         color = black
44       end
45
46       m.reply color + "Today " + m.sourcenick + " the threat level is " + state.capitalize
47     else
48       m.reply "I was unable to retrieve the threat level"
49     end
50
51     return
52   end
53
54 end
55 plugin = ThreatPlugin.new
56 plugin.register("threat")
57
58