diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2012-09-21 13:56:43 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2012-09-21 13:56:43 +0200 |
commit | 3fba86655eaf3fefd4068360234a42e34a013388 (patch) | |
tree | eb26b05555333db46f19b78b083039cc7aced8ce /data/rbot | |
parent | 88d6fabb42b368a2f2ead801fb1773cdd1c710c3 (diff) |
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).
Diffstat (limited to 'data/rbot')
-rw-r--r-- | data/rbot/plugins/poll.rb | 12 |
1 files changed, 12 insertions, 0 deletions
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) |