module FandomTriviaSources
Constants
- EXCLUDED_BOT_IDS
Public Instance Methods
Source
# File lib/fandom_trivia_sources.rb, line 43 def all_fandom_profiles(bots_dir:, root:) profiles = [] each_bot_config(bots_dir) do |raw| profile = load_fandom_profile(raw, root: root) profiles << profile if profile end profiles.uniq end
Source
# File lib/fandom_trivia_sources.rb, line 105 def bot_nicks(raw) nicks = [] nicks << raw["nick"] if raw["nick"] nicks << raw["preferred_nick"] if raw["preferred_nick"] nicks.concat(Array(raw["nicks"])) nicks.compact.map(&:to_s).reject(&:empty?).uniq end
Source
# File lib/fandom_trivia_sources.rb, line 18 def build_nick_index(bots_dir:, root:) index = {} each_bot_config(bots_dir) do |raw| profile = load_fandom_profile(raw, root: root) next unless profile bot_nicks(raw).each do |nick| key = RabbotDb.normalize_nick(nick).downcase next if key.empty? index[key] = profile end end index end
Source
# File lib/fandom_trivia_sources.rb, line 69 def channel_profile_candidates(channel_users, bot_nicks, index) return [] if channel_users.nil? present_nicks = DirectchatPlan.channel_bots(channel_users, bot_nicks) fandom_profiles = profiles_for_nicks(present_nicks, index: index) representatives_by_wiki(fandom_profiles) end
Source
# File lib/fandom_trivia_sources.rb, line 14 def default_bots_dir(root:) File.join(root, "config", "bots") end
Source
# File lib/fandom_trivia_sources.rb, line 61 def discover_profiles(channel_users: nil, bot_nicks:, bots_dir:, root:) index = build_nick_index(bots_dir: bots_dir, root: root) channel_profiles = channel_profile_candidates(channel_users, bot_nicks, index) return channel_profiles unless channel_profiles.empty? all_fandom_profiles(bots_dir: bots_dir, root: root) end
Source
# File lib/fandom_trivia_sources.rb, line 77 def each_bot_config(bots_dir) return unless File.directory?(bots_dir) Dir.glob(File.join(bots_dir, "*.yml")).sort.each do |path| next if EXCLUDED_BOT_IDS.include?(File.basename(path, ".yml")) raw = YAML.safe_load_file(path, aliases: false) next unless raw.is_a?(Hash) yield raw end rescue StandardError nil end
Source
# File lib/fandom_trivia_sources.rb, line 92 def load_fandom_profile(raw, root:) profile_path = raw["profile_path"].to_s.strip return nil if profile_path.empty? expanded = File.expand_path(profile_path, root) profile = CharacterProfile.load(expanded) return profile if FandomTrivia.fandom_source?(profile) nil rescue StandardError nil end
Source
# File lib/fandom_trivia_sources.rb, line 34 def profiles_for_nicks(nicks, index:) nicks.filter_map do |nick| key = RabbotDb.normalize_nick(nick).downcase next if key.empty? index[key] end.uniq end
Source
# File lib/fandom_trivia_sources.rb, line 52 def representatives_by_wiki(profiles) profiles.each_with_object({}) do |profile, grouped| host = FandomTrivia.wiki_host(profile.source_url) next if host.empty? grouped[host] ||= profile end.values end