From: Giuseppe Bilotta Date: Wed, 7 Mar 2007 21:15:05 +0000 (+0000) Subject: quiz plugin: don't crash when the answer is entirely made of sepators X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=d9e9ad0dec4695bae68543cf89768da6f2b905f8;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git quiz plugin: don't crash when the answer is entirely made of sepators --- diff --git a/data/rbot/plugins/quiz.rb b/data/rbot/plugins/quiz.rb index 9a0c5e10..63383262 100644 --- a/data/rbot/plugins/quiz.rb +++ b/data/rbot/plugins/quiz.rb @@ -92,7 +92,8 @@ end class Quiz attr_accessor :registry, :registry_conf, :questions, :question, :answers, :canonical_answer, :answer_array, - :first_try, :hint, :hintrange, :rank_table, :hinted, :has_errors + :first_try, :hint, :hintrange, :rank_table, :hinted, :has_errors, + :all_seps def initialize( channel, registry ) if !channel @@ -140,6 +141,9 @@ class Quiz @hintrange = nil @hinted = false + # True if the answers is entirely done by separators + @all_seps = false + # We keep this array of player stats for performance reasons. It's sorted by score # and always synced with the registry player stats hash. This way we can do fast # rank lookups, without extra sorting. @@ -507,6 +511,15 @@ class QuizPlugin < Plugin end q.answer_array << ch } + q.all_seps = false + # It's possible that an answer is entirely done by separators, + # in which case we'll hide everything + if q.answer_array == q.hint + q.hint.map! { |ch| + "^" + } + q.all_seps = true + end q.hinted = false # Generate array of unique random range @@ -555,7 +568,7 @@ class QuizPlugin < Plugin begin index = q.hintrange.pop # New hint char until the char isn't a "separator" (space etc.) - end while is_sep(q.answer_array[index]) + end while is_sep(q.answer_array[index]) and not q.all_seps q.hint[index] = q.answer_array[index] end m.reply "Hint: #{q.hint}"