module RecipeHistory
Constants
- NO_HISTORY_MESSAGE
Public Instance Methods
Source
# File lib/recipe_history.rb, line 11 def last_history_entry(network:, channel:, store: RabbotDb) selectable_entries(network: network, channel: channel, store: store).last end
Source
# File lib/recipe_history.rb, line 70 def normalize_history_text(text) plain = AiChannelLog.strip_irc_codes(text).strip plain = AiChannelLog.plain_log_text(plain) if AiChannelLog.agent_answer_card?(plain) plain.sub(/\A(?:\[[^\]]+\]|ยซ[^ยป]+ยป)\s*/, "").strip end
Source
# File lib/recipe_history.rb, line 21 def parse_history_text(text) plain = normalize_history_text(text) parts = plain.split("|", 3).map(&:strip) if parts.length == 3 && parts.all? { |part| !part.empty? } return { title: parts[0], ingredients: parts[1], instructions: parts[2] } end if parts.length == 2 && parts.all? { |part| !part.empty? } return { title: parts[0], ingredients: parts[1], instructions: "" } end lines = plain.split("\n", -1).map(&:strip).reject(&:empty?) return { title: "", ingredients: "", instructions: "" } if lines.empty? if lines.length == 1 line = lines.first return { title: line, ingredients: "", instructions: line } end { title: lines.first, ingredients: "", instructions: lines.drop(1).join("\n") } end
Source
# File lib/recipe_history.rb, line 48 def plan_add_from_last_history(network:, channel:, store: RabbotDb) entry = last_history_entry(network: network, channel: channel, store: store) return { error: NO_HISTORY_MESSAGE } unless entry parsed = parse_history_text(entry[:text]) return { error: NO_HISTORY_MESSAGE } if parsed[:title].to_s.strip.empty? { title: parsed[:title], ingredients: parsed[:ingredients], instructions: parsed[:instructions], source_nick: entry[:nick] } end
Source
# File lib/recipe_history.rb, line 15 def selectable_entries(network:, channel:, store: RabbotDb) AiChannelLog.entries(network: network, channel: channel, store: store).reject do |entry| entry[:is_command] || entry[:from_bot] end end
Source
# File lib/recipe_history.rb, line 63 def source_label(source_nick) nick = source_nick.to_s.strip return "channel_history" if nick.empty? "channel_history:#{nick}" end