class Qld
Constants
- POLL_INTERVAL_SEC
Public Class Methods
Source
# File plugins/qld.rb, line 25 def self.command_pattern /qld(?:\s+(.+))?$/i end
Source
# File plugins/qld.rb, line 91 def self.dispatch_command(args_text, fetch: nil, network: nil, channel: nil, store: RabbotDb, time: Time.now) parsed = parse_command(args_text) return { error: parsed[:error] } if parsed[:error] return { reply: help_reply } if parsed[:action] == :help case parsed[:action] when :traffic events = QldTraffic.fetch_events(fetch: fetch) filtered = QldTraffic.filter_events(events, query: parsed[:locality]) title = parsed[:locality].to_s.empty? ? "QLD traffic" : "QLD traffic ยท #{parsed[:locality]}" { reply: QldTraffic.format_events(filtered, title: title) } when :traffic_watch unless network && channel return { error: "Traffic watch must be configured in a channel." } end text = QldTrafficWatch.configure( network: network, channel: channel, action: parsed[:watch_action], types: parsed[:types], store: store ) { reply: text } when :stop stops = QldTranslinkGtfs.search_stops(parsed[:query], fetch: fetch) { reply: QldTranslinkDepartures.format_stops(stops, query: parsed[:query]) } when :departures result = QldTranslinkDepartures.lookup_departures(parsed[:query], fetch: fetch, time: time) return { error: result[:error] } if result[:error] { reply: QldTranslinkDepartures.format_departures( stop_name: result[:stop_name], rows: result[:rows] ) } when :alerts message = QldTranslinkRt.fetch_feed(region: QldConfig::DEFAULT_REGION, feed: QldTranslinkRt::FEED_ALERTS, fetch: fetch) alerts = QldTranslinkRt.parse_alerts(message, mode: parsed[:mode]) { reply: QldTranslinkDepartures.format_alerts(alerts) } when :warnings { reply: BomWarnings.lookup(state: "qld", fetch: fetch) } when :status traffic_ok = QldTraffic.reachable?(fetch: fetch) translink_ok = QldTranslinkRt.reachable?(fetch: fetch) lines = [ IrcFormat.report_header(tag: "QLD", title: "Service status", style: QldTraffic::STYLE_TITLE), "QLDTraffic: #{traffic_ok ? 'reachable' : 'unreachable'}", "TransLink GTFS-RT: #{translink_ok ? 'reachable' : 'unreachable'}", "BOM warnings: use !qld warnings", IrcFormat.report_footer("Queensland APIs") ] { reply: lines.join("\n") } else { error: usage_message } end end
Source
# File plugins/qld.rb, line 76 def self.help_reply [ IrcFormat.report_header(tag: "QLD", title: "Queensland services", style: QldTraffic::STYLE_TITLE), "!qld traffic [locality] โ QLDTraffic road events", "!qld traffic watch on|off [crash flooding hazard] โ auto-post new events", "!qld stop <name> โ find TransLink stops", "!qld departures <stop> โ real-time SEQ departures", "!qld alerts [train|bus|ferry|tram] โ TransLink service alerts", "!qld warnings โ BOM weather warnings for QLD", "!qld status โ API reachability", "Also: !warn qld ยท !bom qld <town> ยท !quake recent", IrcFormat.report_footer("TransLink ยท QLDTraffic ยท BOM") ].join("\n") end
Source
# File plugins/qld.rb, line 36 def self.parse_command(text) args = text.to_s.strip return { action: :help } if args.empty? parts = args.split(/\s+/) case parts[0].downcase when "help" { action: :help } when "traffic" if parts[1]&.casecmp("watch")&.zero? parsed = QldTrafficWatch.parse_watch_args(parts[2..]) return parsed if parsed[:error] return { action: :traffic_watch, watch_action: parsed[:action], types: parsed[:types] } end { action: :traffic, locality: parts[1..].join(" ").strip } when "stop" name = parts[1..].join(" ").strip return { error: "Usage: !qld stop <name>" } if name.empty? { action: :stop, query: name } when "departures", "deps" name = parts[1..].join(" ").strip return { error: "Usage: !qld departures <stop>" } if name.empty? { action: :departures, query: name } when "alerts" mode = parts[1].to_s.strip.downcase mode = nil if mode.empty? { action: :alerts, mode: mode } when "warnings", "warn" { action: :warnings } when "status" { action: :status } else { error: usage_message } end end
Source
# File plugins/qld.rb, line 32 def self.usage_message "Usage: !qld traffic [locality] | traffic watch on|off | stop <name> | departures <stop> | alerts [train|bus] | warnings | status" end
Public Instance Methods
Source
# File plugins/qld.rb, line 160 def execute(m, args_text = nil) result = self.class.dispatch_command( args_text, network: m.channel ? bot.config.server : nil, channel: m.channel&.name ) if result[:error] themed_flood_safe_reply(m, result[:error]) else themed_flood_safe_reply(m, result[:reply]) end end
Source
# File plugins/qld.rb, line 150 def poll_watch return unless bot QldTrafficWatch.poll_channels(bot).each do |entry| bot.Channel(entry[:channel]).send(entry[:text]) end rescue StandardError nil end