X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fpoll.rb;h=45744b197b86438f4908d4ca6e0c29686b06e4cf;hb=7b792bea7a644309623d67b5d49528ae13da3e7b;hp=79f663f155df7e9c3e83ccf9797fd06d63e37310;hpb=c320012ebd38fe5498cfa8435fa3724729334ec9;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/poll.rb b/data/rbot/plugins/poll.rb index 79f663f1..45744b19 100644 --- a/data/rbot/plugins/poll.rb +++ b/data/rbot/plugins/poll.rb @@ -67,6 +67,7 @@ class ::Poll @voters[voter] = choice return _("recorded your vote for %{choice}: %{value}") % { + :choice => choice, :value => @answers[choice][:value] } else @@ -87,7 +88,7 @@ class ::Poll end def options - options = _("options are: ") + options = _("options are: ").dup @answers.each { |letter, info| options << "#{Bold}#{letter}#{NormalText}) #{info[:value]} " } @@ -117,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) @@ -201,7 +214,7 @@ class PollPlugin < Plugin command = _("poll vote %{id} ") % { :id => poll.id } - instructions = _("you have %{duration}, vote with ") + instructions = _("you have %{duration}, vote with ").dup instructions << _("%{priv} or %{public}") m.reply instructions % { :duration => "#{Bold}#{target_duration}#{Bold}", @@ -223,7 +236,9 @@ class PollPlugin < Plugin return if poll == nil poll.stop! - @bot.say(poll.channel, _("let's find the answer to: %{q}") % { + dest = poll.channel ? poll.channel : poll.author + + @bot.say(dest, _("let's find the answer to: %{q}") % { :q => "#{Bold}#{poll.question}#{Bold}" }) @@ -255,7 +270,7 @@ class PollPlugin < Plugin end end - @bot.say poll.channel, poll.outcome + @bot.say dest, poll.outcome # Now that we're done, move it to the archives archives = @registry[:archives] @@ -312,7 +327,7 @@ class PollPlugin < Plugin return end - to_reply = _("poll #%{id} was asked by %{bold}%{author}%{bold} in %{bold}%{channel}%{bold} %{started}.") + to_reply = _("poll #%{id} was asked by %{bold}%{author}%{bold} in %{bold}%{channel}%{bold} %{started}.").dup options = '' outcome = '' if poll.running @@ -320,19 +335,20 @@ class PollPlugin < Plugin if poll.voters.has_key? m.sourcenick to_reply << _(" Be patient, it'll end %{end}") else - to_reply << _(" You have until %{poll.ends_at} to vote if you haven't!") + to_reply << _(" You have until %{end} to vote if you haven't!") options << " #{poll.options}" end else outcome << " #{poll.outcome}" end - m.reply (to_reply % { + m.reply((to_reply % { :bold => Bold, - :id => poll.id, :author => poll.author, :channel => poll.channel, + :id => poll.id, :author => poll.author, + :channel => (poll.channel ? poll.channel : _("private")), :started => poll.started, :end => poll.ends_at - }) + options + outcome + }) + options + outcome) end def help(plugin,topic="")