class Veto
Constants
- BOT_OPTION_REPLY_PATTERN
- DEFAULT_SOURCES
- STEVE_WARNING
- STYLE_TITLE
Public Class Methods
Source
# File plugins/veto.rb, line 83 def self.audit_log(network:, channel:, store: RabbotDb) VetoStore.audit_log(network: network, channel: channel, store: store) end
Source
# File plugins/veto.rb, line 47 def self.bot_option_reply?(text) text.to_s.strip.match?(BOT_OPTION_REPLY_PATTERN) end
Source
# File plugins/veto.rb, line 51 def self.clean_experiment(text) text.to_s.gsub(/[\x00-\x1f]/, " ").squeeze(" ").strip[0, 280] end
Source
# File plugins/veto.rb, line 38 def self.experiment_proposal?(text) stripped = text.to_s.strip return false if stripped.empty? return false if stripped.start_with?("!") return false if bot_option_reply?(stripped) BuildProposalFilter.staging_candidate?(stripped) end
Source
# File plugins/veto.rb, line 30 def self.experiment_source?(nick, sources: DEFAULT_SOURCES) Array(sources).any? { |source| source.to_s.casecmp?(nick.to_s) } end
Source
# File plugins/veto.rb, line 94 def self.format_approved(source:, experiment:) header = IrcFormat.report_header(tag: "VETO", title: "approved", style: STYLE_TITLE) body = "#{source}: #{experiment}" footer = IrcFormat.muted(STEVE_WARNING) [header, body, footer].join("\n") end
Source
# File plugins/veto.rb, line 113 def self.format_no_pending "No pending experiment to veto" end
Source
# File plugins/veto.rb, line 101 def self.format_rejected(source:, experiment:, vetor:) header = IrcFormat.report_header(tag: "VETO", title: "rejected", style: STYLE_TITLE) body = "#{vetor} vetoed #{source}'s experiment: #{experiment}" [header, body].join("\n") end
Source
# File plugins/veto.rb, line 117 def self.format_status(pending) remaining = remaining_seconds(pending) state = pending[:vetoed] ? "vetoed" : "#{remaining}s remaining" header = IrcFormat.report_header(tag: "BUILD", title: "pending idea", style: STYLE_TITLE) body = "#{pending[:source]}: #{pending[:experiment] || pending[:idea]}" footer = IrcFormat.report_footer(state) [header, body, footer].join("\n") end
Source
# File plugins/veto.rb, line 107 def self.format_veto_ack(vetor:) header = IrcFormat.report_header(tag: "VETO", title: "rejected", style: STYLE_TITLE) body = "#{vetor} rejected the pending experiment" [header, body].join("\n") end
Source
# File plugins/veto.rb, line 87 def self.format_vote_open(source:, experiment:, window_sec:) header = IrcFormat.report_header(tag: "VETO", title: "Lab safety vote", style: STYLE_TITLE) body = experiment.to_s footer = IrcFormat.report_footer("from #{source}", "!veto within #{window_sec}s") [header, body, footer].join("\n") end
Source
# File plugins/veto.rb, line 71 def self.load_pending(network:, channel:, store: RabbotDb) VetoStore.load_pending(network: network, channel: channel, store: store) end
Source
# File plugins/veto.rb, line 75 def self.mark_vetoed(network:, channel:, vetor:, store: RabbotDb) VetoStore.mark_vetoed(network: network, channel: channel, vetor: vetor, store: store) end
Source
# File plugins/veto.rb, line 62 def self.outcome_for(pending) pending[:vetoed] ? :rejected : :approved end
Source
# File plugins/veto.rb, line 79 def self.record_outcome(network:, channel:, entry:, outcome:, store: RabbotDb) VetoStore.record_outcome(network: network, channel: channel, entry: entry, outcome: outcome, store: store) end
Source
# File plugins/veto.rb, line 55 def self.remaining_seconds(pending, now: Time.now) return 0 unless pending elapsed = now - pending[:staged_at] [pending[:veto_window_sec].to_i - elapsed.to_i, 0].max end
Source
# File plugins/veto.rb, line 66 def self.save_pending(network:, channel:, entry:, staged_at:, veto_window_sec:, store: RabbotDb) VetoStore.save_pending(network: network, channel: channel, entry: entry, staged_at: staged_at, veto_window_sec: veto_window_sec, store: store) end
Source
# File plugins/veto.rb, line 34 def self.veto_command?(message) message.to_s.strip.match?(/\A!veto\z/i) end
Public Instance Methods
Source
# File plugins/veto.rb, line 126 def execute(m) return unless m.channel return unless BotIdentity.room_reader_bot?(bot) pending = self.class.mark_vetoed( network: bot.config.server, channel: m.channel.name, vetor: m.user.nick ) flood_safe_reply(m, pending ? self.class.format_veto_ack(vetor: m.user.nick) : self.class.format_no_pending) end