From 3fba86655eaf3fefd4068360234a42e34a013388 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 21 Sep 2012 13:56:43 +0200 Subject: poll: restart/close polls that were running On init, we need to see if there were polls running, and put them up again (if there's still time) or announce their results (otherwise). --- data/rbot/plugins/poll.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'data/rbot/plugins') diff --git a/data/rbot/plugins/poll.rb b/data/rbot/plugins/poll.rb index 33e2b4d8..4dc28e69 100644 --- a/data/rbot/plugins/poll.rb +++ b/data/rbot/plugins/poll.rb @@ -118,6 +118,18 @@ class PollPlugin < Plugin init_reg_entry :running, Hash.new init_reg_entry :archives, Hash.new init_reg_entry :last_poll_id, 0 + running = @registry[:running] + now = Time.now + running.each do |id, poll| + duration = poll.ends_at - Time.now + if duration > 0 + # keep the poll running + @bot.timer.add_once(duration) { count_votes(poll.id) } + else + # the poll expired while the bot was out, end it + count_votes(poll.id) + end + end end def authors_running_count(victim) -- cgit v1.2.3