X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fgames%2Fquiz.rb;h=b139c66a2fad25eb2ec8c9c0e31900ce2f0307a3;hb=452e323bfdb73d6b93ab96f5fc417891e4aa8f53;hp=e1e544f4c9f1b2b244cef94ad7ba21d03db6e877;hpb=bd03e04c880ec9f755cfb9702adf2d4178077889;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/games/quiz.rb b/data/rbot/plugins/games/quiz.rb index e1e544f4..b139c66a 100644 --- a/data/rbot/plugins/games/quiz.rb +++ b/data/rbot/plugins/games/quiz.rb @@ -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 ) @@ -258,13 +274,17 @@ class QuizPlugin < Plugin # Returns new Quiz instance for channel, or existing one + # Announce errors if a message is passed as second parameter # - def create_quiz( channel ) + def create_quiz(channel, m=nil) unless @quizzes.has_key?( channel ) @quizzes[channel] = Quiz.new( channel, @registry ) end if @quizzes[channel].has_errors + m.reply _("Sorry, the quiz database for %{chan} seems to be corrupt") % { + :chan => channel + } if m return nil else return @quizzes[channel] @@ -274,11 +294,8 @@ class QuizPlugin < Plugin def say_score( m, nick ) chan = m.channel - q = create_quiz( chan ) - if q.nil? - m.reply "Sorry, the quiz database for #{chan} seems to be corrupt" - return - end + q = create_quiz( chan, m ) + return unless q if q.registry.has_key?( nick ) score = q.registry[nick].score @@ -299,7 +316,17 @@ class QuizPlugin < Plugin def help( plugin, topic="" ) if topic == "admin" - "Quiz game aministration commands (requires authentication): 'quiz autoask ' => enable/disable autoask mode. 'quiz autoask delay ' => delay next quiz by seconds when in autoask mode. 'quiz transfer [score] [jokers]' => transfer [score] points and [jokers] jokers from to (default is entire score and all jokers). 'quiz setscore ' => set 's score to . 'quiz setjokers ' => set 's number of jokers to . 'quiz deleteplayer ' => delete one player from the rank table (only works when score and jokers are set to 0). 'quiz cleanup' => remove players with no points and no jokers." + _("Quiz game aministration commands (requires authentication): ") + [ + _("'quiz autoask ' => enable/disable autoask mode"), + _("'quiz autoask delay