class Quake
Constants
- REFRESH_INTERVAL_SEC
Public Class Methods
Source
# File plugins/quake.rb, line 20 def self.command_pattern /quake(?:\s+(.+))?$/i end
Source
# File plugins/quake.rb, line 74 def self.dispatch_command(args_text, user: nil, fetch: nil, store: Game.default_store, network: nil, channel: nil, db_store: RabbotDb) parsed = parse_command(args_text) return { error: parsed[:error] } if parsed[:error] return { reply: help_reply } if parsed[:action] == :help case parsed[:action] when :recent events = QuakeFeed.fetch_recent(fetch: fetch) { reply: QuakeFeed.format_recent(events) } when :watch unless network && channel return { error: "Watch must be configured in a channel." } end text = QuakeWatch.configure(network: network, channel: channel, action: parsed[:action], min_mag: parsed[:min_mag]) { reply: text } when :roulette unless network && channel return { error: "Richter Roulette must be played in a channel." } end if parsed[:roulette_action] == :status return { reply: QuakeRoulette.format_status(network: network, channel: channel, store: db_store) } end events = QuakeFeed.fetch_recent(fetch: fetch) result = QuakeRoulette.place_bet( user: user.to_s.strip.empty? ? "player" : user.to_s, band: parsed[:band], range: parsed[:range], amount: parsed[:amount], network: network, channel: channel, events: events, store: store, db_store: db_store ) return { error: result[:error] } if result[:error] { reply: result[:message] } else { error: usage_message } end end
Source
# File plugins/quake.rb, line 62 def self.help_reply lines = [ IrcFormat.report_header(tag: "QUAKE", title: "AU-region earthquakes", style: QuakeFeed::STYLE_TITLE), "!quake recent โ latest events", "!quake watch on|off [min_mag] โ auto-post alerts in channel", "!quake roulette 3-4 [amount] โ bet on next quake magnitude band", "!quake roulette status โ pending bets", IrcFormat.report_footer("USGS ยท AU region") ] lines.join("\n") end
Source
# File plugins/quake.rb, line 31 def self.parse_command(text) args = text.to_s.strip return { action: :recent } if args.empty? parts = args.split(/\s+/) case parts[0].downcase when "help" { action: :help } when "recent", "list" { action: :recent } when "watch" parsed = QuakeWatch.parse_watch_args(parts[1..]) return parsed if parsed[:error] { action: :watch, **parsed } when "roulette" parsed = QuakeRoulette.parse_args(parts[1..]) return parsed if parsed[:error] { action: :roulette, roulette_action: parsed[:action], band: parsed[:band], range: parsed[:range], amount: parsed[:amount] }.compact else { error: usage_message } end end
Source
# File plugins/quake.rb, line 27 def self.usage_message "Usage: !quake recent | watch on|off [min_mag] | roulette <band> [amount] | roulette status" end
Public Instance Methods
Source
# File plugins/quake.rb, line 132 def execute(m, args_text = nil) result = self.class.dispatch_command( args_text, user: m.user.nick, 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/quake.rb, line 119 def poll_feed return unless bot QuakeWatch.poll_channels(bot).each do |entry| bot.Channel(entry[:channel]).send(entry[:text]) end QuakeRoulette.poll_settle(bot).each do |entry| bot.Channel(entry[:channel]).send(entry[:text]) end rescue StandardError nil end