module ArchdigGame
Constants
- PLUGIN
- STYLE_TITLE
Public Instance Methods
Source
# File lib/archdig_game.rb, line 57 def day_key(time: Time.now) time.utc.strftime("%Y-%m-%d") end
Source
# File lib/archdig_game.rb, line 72 def ensure_topic(data, day_index:) data = data.dup data["topic_index"] ||= day_index data["submissions"] ||= {} data end
Source
# File lib/archdig_game.rb, line 135 def format_header(title) IrcFormat.report_header(tag: "DIG", title: title, style: STYLE_TITLE) end
Source
# File lib/archdig_game.rb, line 121 def format_top(data) board = leaderboard(data) lines = [format_header("Today's digs")] if board.empty? lines << "No submissions yet." else board.each_with_index do |(nick, entry), index| lines << "#{index + 1}. #{nick} — #{entry['score']}/10 — #{entry['text']}" end end lines << IrcFormat.report_footer("#{board.length} entries") lines.join("\n") end
Source
# File lib/archdig_game.rb, line 116 def leaderboard(data) subs = data["submissions"] || {} subs.sort_by { |_, v| [-v["score"].to_i, v["text"].to_s] } end
Source
# File lib/archdig_game.rb, line 61 def load_day(network:, channel:, day:, store: RabbotDb) GameStore.load(plugin: PLUGIN, network: network, channel: channel, key: "day:#{day}", store: store) || { "topic_index" => nil, "submissions" => {} } end
Source
# File lib/archdig_game.rb, line 39 def parse_command(text) parts = text.to_s.strip.split(/\s+/) return { action: :topic } if parts.empty? case parts[0].downcase when "help" { action: :help } when "submit" return { error: usage_message } if parts.length < 2 { action: :submit, text: parts[1..].join(" ") } when "top", "leaderboard" { action: :top } else { error: usage_message } end end
Source
# File lib/archdig_game.rb, line 68 def save_day(network:, channel:, day:, data:, store: RabbotDb) GameStore.save(plugin: PLUGIN, network: network, channel: channel, key: "day:#{day}", game: data, store: store) end
Source
# File lib/archdig_game.rb, line 106 def score_submission(text, day_index:) base = 3 base += 1 if text.length > 40 base += 1 if text.match?(/\b(19|20)\d{2}\b/) base += 1 if text.split.length >= 6 base += [text.length % 3, 2].min base += day_index % 2 [base, 10].min end
Source
# File lib/archdig_game.rb, line 88 def submit(data:, user:, text:, day_index:) data = ensure_topic(data, day_index: day_index) entry = text.to_s.strip return { error: "Submission cannot be empty." } if entry.empty? submissions = data["submissions"].dup key = GameStore.norm_nick(user) return { error: "You already submitted today." } if submissions[key] score = score_submission(entry, day_index: day_index) submissions[key] = { "text" => entry, "score" => score } data["submissions"] = submissions { data: data, message: "#{format_header('Submitted')} \nScore: #{score}/10 — rarity + nostalgia heuristic" } end
Source
# File lib/archdig_game.rb, line 79 def topic_message(day_index:) topic = ArchdigTopics.topic_for_day(day_index) lines = [format_header("Daily dig")] lines << "Topic: #{topic}" lines << "Submit your best example with !archdig submit <text>" lines << IrcFormat.report_footer("channel archaeologist") lines.join("\n") end
Source
# File lib/archdig_game.rb, line 35 def usage_message "Usage: !archdig | !archdig submit <example> | !archdig top" end