module AutovoiceCandidates
AutovoiceCandidates — gather unvoiced active chatters eligible for +v. Public: gather Depends: AiChannelLog, ChannelTrust, RoomReader, Normalize Tests: test/lib/autovoice_candidates_test.rb
Constants
- LOOKBACK_SEC
Public Instance Methods
Source
# File lib/autovoice/candidates.rb, line 82 def activity_by_nick(entries, now:) entries.each_with_object({}) do |entry, memo| nick = Normalize.nick(entry[:nick]) key = nick.downcase at = parse_entry_time(entry[:at]) || now snippet = entry[:text].to_s.strip existing = memo[key] if existing.nil? || at >= existing[:last_at] memo[key] = { snippet: snippet, last_at: at } end end end
Source
# File lib/autovoice/candidates.rb, line 96 def eligible_users(users, bot_nicks:) Array(users).reject do |user| nick = Normalize.nick(user[:nick]) user[:voiced] || user[:opped] || ChannelTrust.bot_nick?(nick, bot_nicks: bot_nicks) end end
Source
# File lib/autovoice/candidates.rb, line 18 def gather(users:, network:, channel:, now: Time.now, store: RabbotDb, bot_nicks: ChannelTrust.persona_bot_nicks, channel_obj: nil, since: nil) entries = recent_log_entries( network: network, channel: channel, now: now, store: store, channel_obj: channel_obj, bot_nicks: bot_nicks, since: since ) return [] if entries.empty? activity = activity_by_nick(entries, now: now) return [] if activity.empty? eligible_users(users, bot_nicks: bot_nicks).filter_map do |user| nick = Normalize.nick(user[:nick]) info = activity[nick.downcase] next unless info { nick: nick, snippet: info[:snippet], last_at: info[:last_at] } end.sort_by { |entry| -entry[:last_at].to_f } end
Source
# File lib/autovoice/candidates.rb, line 104 def parse_entry_time(value) return value if value.is_a?(Time) RabbotDb.parse_time(value) end
Source
# File lib/autovoice/candidates.rb, line 47 def recent_log_entries(network:, channel:, now:, store:, channel_obj:, bot_nicks:, since: nil) cutoff = now - LOOKBACK_SEC AiChannelLog.entries(network: network, channel: channel, store: store).select do |entry| next false if entry[:is_command] next false if entry[:from_bot] next false unless trusted_entry?( entry: entry, network: network, channel: channel, channel_obj: channel_obj, bot_nicks: bot_nicks ) at = parse_entry_time(entry[:at]) next false unless at && at >= cutoff next false if since && at <= since true end end
Source
# File lib/autovoice/candidates.rb, line 69 def trusted_entry?(entry:, network:, channel:, channel_obj:, bot_nicks:) nick = entry[:nick] user = Struct.new(:nick).new(nick) ChannelTrust.trusted_context_nick?( nick: nick, channel: channel_obj || channel, user: user, network: network, bot_nicks: bot_nicks ) end