module ClockPoll
ClockPoll — poll enabled channels and emit at most one tick per claimed minute. Public: poll_channel, poll_channels Depends: ClockStore, ClockTick, RabbotDb Tests: test/plugins/clock_test.rb, test/lib/clock_poll_test.rb
Public Instance Methods
Source
# File lib/clock/poll.rb, line 15 def poll_channel(network:, channel_name:, state:, bot:, now: Time.now, store: RabbotDb, reply_to: nil, tick_may_send: nil) return { state: state, text: nil, target: nil } unless state["enabled"] channel = bot.channels.find { |entry| entry.name.casecmp?(channel_name.to_s) } target = reply_to || channel return { state: state, text: nil, target: nil } unless target if channel && target == channel && tick_may_send && !tick_may_send.call(channel, state) return { state: state, text: nil, target: nil } end tz = ClockTick.channel_timezone(network: network, channel: channel_name, store: store, now: now) minute = ClockTick.minute_key(now, utc_offset: tz[:offset]) claim = ClockStore.claim_minute!( network: network, channel: channel_name, minute: minute, store: store ) return { state: claim[:state], text: nil, target: nil } unless claim[:claimed] text = ClockTick.build_tick_message( now: now, utc_offset: tz[:offset], lines: claim[:state]["lines"] ) { state: claim[:state], text: text, target: target } end
Source
# File lib/clock/poll.rb, line 44 def poll_channels(bot, store: RabbotDb, now: Time.now, tick_may_send: nil) return [] unless bot messages = [] network = bot.config.server bot.config.channels.each do |channel_name| state = ClockStore.load_state(network: network, channel: channel_name, store: store) next unless state["enabled"] result = poll_channel( network: network, channel_name: channel_name, state: state, bot: bot, now: now, store: store, tick_may_send: tick_may_send ) next unless result[:text] messages << { channel: channel_name, text: result[:text] } end messages end