1 #Tube Status Enquiry plugin for rbot
2 #Plugin by Colm Linehan
4 require 'rexml/document'
7 class TubePlugin < Plugin
9 def help(plugin, topic="")
10 "tube [district|circle|metropolitan|central|jubilee|bakerloo|waterloo_city|hammersmith_city|victoria|eastlondon|northern|piccadilly] => display tube service status for the specified line(Docklands Light Railway is not currently supported), tube stations => list tube stations (not lines) with problems"
13 if m.params && m.params =~ /^stations$/
15 elsif m.params && m.params =~ /^(.*)$/
16 line = $1.downcase.capitalize
21 def check_tube(m, line)
23 tube_page = @bot.httputil.get(URI.parse("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml"), 1, 1)
24 rescue URI::InvalidURIError, URI::BadURIError => e
25 m.reply "Cannot contact Tube Service Status page"
29 m.reply "Cannot contact Tube Service Status page"
33 tube_page.each_line {|l|
37 if (l =~ /^<tr valign=top> <td>\s*(.*)<\/td><\/tr>/i)
38 m.reply $1.split(/<[^>]+>| /i).join(" ")
41 m.reply "There are problems on the #{line} line, but I didn't understand the page format. You should check out http://www.tfl.gov.uk/tfl/service_rt_tube.shtml for more details."
45 next_line = true if (l =~ /class="#{line}"/i)
47 m.reply "No Problems on the #{line} line."
52 tube_page = @bot.httputil.get(URI.parse("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml"))
53 rescue URI::InvalidURIError, URI::BadURIError => e
54 m.reply "Cannot contact Tube Service Status page"
58 m.reply "Cannot contact Tube Service Status page"
61 stations_array = Array.new
62 tube_page.each_line {|l|
63 if (l =~ /<tr valign=top> <td valign="middle" class="Station"><b>(.*)<\/b><\/td><\/tr>\s*/i)
64 stations_array.push $1
67 if stations_array.empty?
68 m.reply "There are no station-specific announcements"
71 m.reply stations_array.join(", ")
76 plugin = TubePlugin.new
77 plugin.register("tube")