]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
quiz plugin: don't crash when the answer is entirely made of sepators
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 7 Mar 2007 21:15:05 +0000 (21:15 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 7 Mar 2007 21:15:05 +0000 (21:15 +0000)
data/rbot/plugins/quiz.rb

index 9a0c5e10d7df636bf29e259646bf0d37a4a4c54d..6338326223964176eb8479c3a7963fec15a7b358 100644 (file)
@@ -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}"