summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/threat.rb
blob: ae7091010de2ef4852dc2dc423beef6842f9756f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Security threat level plugin for rbot
# by Robin Kearney (robin@riviera.org.uk)
#
# inspired by elliots fascination with the us
# threat level.
#
# again a dirty hack but it works, just...
#

require 'uri/common'

class ThreatPlugin < Plugin

  def help(plugin, topic="")
    "threat => prints out the current threat level as reported by http://www.dhs.gov/"
  end

  def privmsg(m)
	color = ""
    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.*/
      state = $1
    end
    case state
      when "severe"
		color = red
      when "high"
		color = orange
      when "elevated"
		color = yellow
      when "guarded"
		color = blue
      when "low"
		color = green
	else
	  color = black
	end

	m.reply color + "Today " + m.sourcenick + " the threat level is " + state.capitalize

	return
  end

end
plugin = ThreatPlugin.new
plugin.register("threat")