class Rba
Constants
- POLL_INTERVAL_SEC
Public Class Methods
Source
# File plugins/rba.rb, line 21 def self.command_pattern /rba(?:\s+(.+))?$/i end
Source
# File plugins/rba.rb, line 67 def self.dispatch_command(args_text, user: nil, fetch: nil, time: Time.now, 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 :cash result = RbaRates.fetch_cash_csv(fetch: fetch) { reply: RbaRates.format_cash(result) } when :pair result = RbaRates.lookup_pair(parsed[:pair], fetch: fetch) { reply: RbaRates.format_pair(result) } when :rumble if parsed[:rumble_action] == :settle unless network && channel return { error: "Rate Rumble settle must be run in a channel." } end result = RbaRumble.settle( network: network, channel: channel, time: time, store: store, db_store: db_store, fetch: fetch ) else unless network && channel return { error: "Rate Rumble must be played in a channel." } end result = RbaRumble.place_bet( user: user.to_s.strip.empty? ? "player" : user.to_s, pick: parsed[:pick], amount: parsed[:amount], network: network, channel: channel, time: time, store: store, db_store: db_store ) end return { error: result[:error] } if result[:error] { reply: result[:message] } else { error: usage_message } end end
Source
# File plugins/rba.rb, line 55 def self.help_reply lines = [ IrcFormat.report_header(tag: "RBA", title: "Reserve Bank of Australia", style: RbaRates::STYLE_TITLE), "!rba audusd | eur | jpy | gbp | nzd | twi — latest exchange rate", "!rba cash — target cash rate", "!rba rumble hold|cut|hike [amount] — Rate Rumble before 14:30 AEST (auto-settles after)", "!rba rumble settle — settle today's bets manually", IrcFormat.report_footer("RBA statistics", "Reserve Bank of Australia") ] lines.join("\n") end
Source
# File plugins/rba.rb, line 32 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 "cash", "rate" { action: :cash } when "rumble" parsed = RbaRumble.parse_rumble_args(parts[1..]) return parsed if parsed[:error] { action: :rumble, rumble_action: parsed[:action], pick: parsed[:pick], amount: parsed[:amount] }.compact else pair = parts.join(" ") return { error: usage_message } if pair.empty? { action: :pair, pair: pair } end end
Source
# File plugins/rba.rb, line 28 def self.usage_message "Usage: !rba audusd | eur | jpy | twi | cash | rumble hold|cut|hike [amount]" end
Public Instance Methods
Source
# File plugins/rba.rb, line 127 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/rba.rb, line 117 def poll_rumble return unless bot RbaRumble.poll_settle(bot).each do |entry| bot.Channel(entry[:channel]).send(entry[:text]) end rescue StandardError nil end