class Aec
Public Class Methods
Source
# File plugins/aec.rb, line 18 def self.command_pattern /aec(?:\s+(.+))?$/i end
Source
# File plugins/aec.rb, line 57 def self.dispatch_command(args_text, user: nil, fetch: nil, network: nil, channel: nil, 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 :seat result = AecResults.fetch_seat(parsed[:name], fetch: fetch) { reply: AecResults.format_seat(result) } when :tally if parsed[:tally_action] == :settle return { error: "Tally settle must be run in a channel." } unless network && channel result = AecTally.settle( network: network, channel: channel, seat: parsed[:seat], fetch: fetch, store: store, game_store: Game.default_store ) return { error: result[:error] } if result[:error] { reply: result[:message] } else return { error: "Tally Tip must be used in a channel." } unless network && channel text = AecTally.store_prediction( network: network, channel: channel, user: user.to_s, seat: parsed[:seat], swing: parsed[:swing], store: store ) { reply: text } end else { reply: help_reply } end end
Source
# File plugins/aec.rb, line 47 def self.help_reply [ IrcFormat.report_header(tag: "AEC", title: "Australian Electoral Commission", style: AecResults::STYLE_TITLE), "!aec seat <division> — division results", "!aec tally <seat> <swing%> — Tally Tip prediction", "!aec tally settle <seat> — compare to published results", IrcFormat.report_footer("Live FTP feed requires media registration") ].join("\n") end
Source
# File plugins/aec.rb, line 24 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 "seat" name = parts[1..].join(" ").strip return { error: "Usage: !aec seat <division>" } if name.empty? { action: :seat, name: name } when "tally" sub = AecTally.parse_tally_args(parts[1..]) return sub if sub[:error] { action: :tally, tally_action: sub[:action], seat: sub[:seat], swing: sub[:swing] }.compact else { action: :help } end end
Public Instance Methods
Source
# File plugins/aec.rb, line 99 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