X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ftube.rb;h=1380550286e82cefb74db79e56f3cb825f55834f;hb=940264d1718b5a32d34ac82276a29f0cc1a51941;hp=77ca5227e9391b2c73fdc6893a5acdb9d0df1e5e;hpb=21949774b91eaec6ecde4eaa8ad121e2c0a36b87;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/tube.rb b/data/rbot/plugins/tube.rb index 77ca5227..13805502 100644 --- a/data/rbot/plugins/tube.rb +++ b/data/rbot/plugins/tube.rb @@ -1,69 +1,50 @@ #Tube Status Enquiry plugin for rbot #Plugin by Colm Linehan -require 'rexml/document' -require 'uri/common' - class TubePlugin < Plugin - include REXML def help(plugin, topic="") - "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" - end - def privmsg(m) - if m.params && m.params =~ /^stations$/ - check_stations m - elsif m.params && m.params =~ /^(.*)$/ - line = $1.downcase.capitalize - check_tube m, line - end + "tube [district|circle|metropolitan|central|jubilee|bakerloo|waterlooandcity|hammersmithandcity|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" end - def check_tube(m, line) - begin - tube_page = @bot.httputil.get(URI.parse("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml"), 1, 1) - rescue URI::InvalidURIError, URI::BadURIError => e - m.reply "Cannot contact Tube Service Status page" - return - end - unless tube_page - m.reply "Cannot contact Tube Service Status page" - return - end - next_line = false - tube_page.each_line {|l| - next if l == "\r\n" - next if l == "\n" - if (next_line) - if (l =~ /^ \s*(.*)<\/td><\/tr>/i) - m.reply $1.split(/<[^>]+>| /i).join(" ") - return - else - 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." - return - end + def tube(m, params) + line = params[:line] + tube_page = @bot.httputil.get('http://www.tfl.gov.uk/tfl/livetravelnews/realtime/tube/default.html') + unless tube_page + m.reply "Cannot contact Tube Service Status page" + return end - next_line = true if (l =~ /class="#{line}"/i) + next_line = false + tube_page.each_line {|l| + next if l == "\r\n" + next if l == "\n" + if (next_line) + if (l =~ /^

\s*(.*)<\/p>/i) + m.reply $1.split(/<[^>]+>| /i).join(" ") + return + elsif l =~ /ul|h3|"message"/ + next + else + 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/livetravelnews/realtime/tube/default.html for more details." + return + end + end + next_line = true if (l =~ /li class="#{line}"/i) } - m.reply "No Problems on the #{line} line." + m.reply "No Problems on the #{line} line." end - def check_stations(m) - begin - tube_page = @bot.httputil.get(URI.parse("http://www.tfl.gov.uk/tfl/service_rt_tube.shtml")) - rescue URI::InvalidURIError, URI::BadURIError => e - m.reply "Cannot contact Tube Service Status page" - return - end + def check_stations(m, params) + tube_page = @bot.httputil.get('http://www.tfl.gov.uk/tfl/service_rt_tube.shtml') unless tube_page m.reply "Cannot contact Tube Service Status page" return end stations_array = Array.new tube_page.each_line {|l| - if (l =~ / (.*)<\/b><\/td><\/tr>\s*/i) - stations_array.push $1 - end - } + if (l =~ / (.*)<\/b><\/td><\/tr>\s*/i) + stations_array.push $1 + end + } if stations_array.empty? m.reply "There are no station-specific announcements" return @@ -74,4 +55,5 @@ class TubePlugin < Plugin end end plugin = TubePlugin.new -plugin.register("tube") +# plugin.map 'tube stations', :action => 'check_stations' +plugin.map 'tube :line'