]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
quiz: stop quizzes and timers on cleanup
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 3 Feb 2011 11:53:34 +0000 (12:53 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 3 Feb 2011 11:53:34 +0000 (12:53 +0100)
This prevents spurious timers from running after a rescan

data/rbot/plugins/games/quiz.rb

index f16d057fa2ec98f431c93b8a5b351dd01024fc06..b139c66a2fad25eb2ec8c9c0e31900ce2f0307a3 100644 (file)
@@ -175,6 +175,22 @@ class QuizPlugin < Plugin
     @ask_mutex = Mutex.new
   end
 
+  def cleanup
+    @ask_mutex.synchronize do
+      # purge all waiting timers
+      @waiting.each do |chan, t|
+        @bot.timer.remove t.first
+        @bot.say chan, _("stopped quiz timer")
+      end
+      @waiting.clear
+    end
+    chans = @quizzes.keys
+    @quizzes.clear
+    chans.each do |chan|
+      @bot.say chan, _("quiz stopped")
+    end
+  end
+
   # Function that returns whether a char is a "separator", used for hints
   #
   def is_sep( ch )