module AutovoicePoll
AutovoicePoll — periodic auto-voice polling for enabled channels. Public: poll_channel, poll_channels, channel_users Depends: AutovoiceStore, AutovoiceCandidates, AutovoiceSelect, AutovoiceReport Tests: test/lib/autovoice_poll_test.rb
Public Instance Methods
Source
# File lib/autovoice/poll.rb, line 85 def channel_users(channel) Array(channel.user_list).map do |user| { nick: user.nick, voiced: channel.voiced?(user), opped: channel.opped?(user) } end end
Source
# File lib/autovoice/poll.rb, line 95 def find_channel(bot, channel_name) bot.channels.find { |entry| entry.name.casecmp?(channel_name.to_s) } end
Source
# File lib/autovoice/poll.rb, line 16 def poll_channel(network:, channel_name:, bot:, now: Time.now, store: RabbotDb, force: false, runner: nil, bot_nicks: nil, lag_ms: 0) return nil unless AutovoiceStore.enabled?(network: network, channel: channel_name, store: store) state = AutovoiceStore.load_state(network: network, channel: channel_name, store: store) return nil unless AutovoiceStore.due_for_run?(state, now: now, force: force) return nil unless AutovoiceStore.should_attempt_award?(state, now: now, force: force) channel = find_channel(bot, channel_name) return nil unless channel return nil unless channel.opped?(bot) users = channel_users(channel) since = force ? nil : AutovoiceStore.activity_cutoff(state) candidates = AutovoiceCandidates.gather( users: users, network: network, channel: channel_name, now: now, store: store, channel_obj: channel, bot_nicks: bot_nicks, since: since ) return nil if candidates.empty? pick = AutovoiceSelect.pick( candidates: candidates, channel: channel_name, network: network, runner: runner ) return nil unless pick count = AutovoiceStore.increment_total!(store: store) updated = AutovoiceStore.mark_run!(state, now: now) AutovoiceStore.save_state(network: network, channel: channel_name, state: updated, store: store) { nick: pick[:nick], count: count, flair: pick[:flair], lag_ms: lag_ms, server: network, channel: channel, channel_name: channel_name } end
Source
# File lib/autovoice/poll.rb, line 65 def poll_channels(bot, store: RabbotDb, now: Time.now, force: false, runner: nil, bot_nicks: nil, lag_ms: 0) return [] unless bot network = bot.config.server Array(bot.config.channels).filter_map do |channel_name| poll_channel( network: network, channel_name: channel_name, bot: bot, now: now, store: store, force: force, runner: runner, bot_nicks: bot_nicks, lag_ms: lag_ms ) end end