]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/quiz.rb
Plugin header boilerplating.
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / quiz.rb
index 9a550ea8b9e4a9aecb9c2f705b218c891c8fc91c..7e2c0f83b1c201251e3093798de6fa1a4d900699 100644 (file)
@@ -1,30 +1,30 @@
 #-- vim:sw=2:et
 #++
 #
-# Plugin for the Ruby IRC bot (http://linuxbrit.co.uk/rbot/)
-#
-# A trivia quiz game. Fast paced, featureful and fun.
+# :title: Quiz plugin for rbot
 #
 # Author:: Mark Kretschmann <markey@web.de>
 # Author:: Jocke Andersson <ajocke@gmail.com>
 # Author:: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
 # Author:: Yaohan Chen <yaohan.chen@gmail.com>
 #
-# (c) 2006 Mark Kretschmann, Jocke Andersson, Giuseppe Bilotta
-# (c) 2007 Giuseppe Bilotta, Yaohan Chen
+# Copyright:: (C) 2006 Mark Kretschmann, Jocke Andersson, Giuseppe Bilotta
+# Copyright:: (C) 2007 Giuseppe Bilotta, Yaohan Chen
+#
+# License:: GPL v2
 #
-# Licensed under GPL V2.
+# A trivia quiz game. Fast paced, featureful and fun.
 
-# FIXME interesting fact: in the Quiz class, @registry.has_key? seems to be
-# case insensitive. Although this is all right for us, this leads to rank vs
-# registry mismatches. So we have to make the @rank_table comparisons case
-# insensitive as well. For the moment, redefine everything to downcase before
-# matching the nick.
+# FIXME:: interesting fact: in the Quiz class, @registry.has_key? seems to be
+#         case insensitive. Although this is all right for us, this leads to
+#         rank vs registry mismatches. So we have to make the @rank_table
+#         comparisons case insensitive as well. For the moment, redefine
+#         everything to downcase before matching the nick.
 #
-# TODO define a class for the rank table. We might also need it for scoring in
-# other games.
+# TODO:: define a class for the rank table. We might also need it for scoring
+#        in other games.
 #
-# TODO when Ruby 2.0 gets out, fix the FIXME 2.0 UTF-8 workarounds
+# TODO:: when Ruby 2.0 gets out, fix the FIXME 2.0 UTF-8 workarounds
 
 # Class for storing question/answer pairs
 QuizBundle = Struct.new( "QuizBundle", :question, :answer )
@@ -294,7 +294,7 @@ class QuizPlugin < Plugin
       "Quiz game aministration commands (requires authentication): 'quiz autoask <on/off>' => enable/disable autoask mode. 'quiz autoask delay <secs>' => delay next quiz by <secs> seconds when in autoask mode. 'quiz transfer <source> <dest> [score] [jokers]' => transfer [score] points and [jokers] jokers from <source> to <dest> (default is entire score and all jokers). 'quiz setscore <player> <score>' => set <player>'s score to <score>. 'quiz setjokers <player> <jokers>' => set <player>'s number of jokers to <jokers>. 'quiz deleteplayer <player>' => delete one player from the rank table (only works when score and jokers are set to 0)."
     else
       urls = @bot.config['quiz.sources'].select { |p| p =~ /^https?:\/\// }
-      "A multiplayer trivia quiz. 'quiz' => ask a question. 'quiz hint' => get a hint. 'quiz solve' => solve this question. 'quiz skip' => skip to next question. 'quiz joker' => draw a joker to win this round. 'quiz score [player]' => show score for [player] (default is yourself). 'quiz top5' => show top 5 players. 'quiz top <number>' => show top <number> players (max 50). 'quiz stats' => show some statistics. 'quiz fetch' => refetch questions from databases." + (urls.empty? ? "" : "\nYou can add new questions at #{urls.join(', ')}")
+      "A multiplayer trivia quiz. 'quiz' => ask a question. 'quiz hint' => get a hint. 'quiz solve' => solve this question. 'quiz skip' => skip to next question. 'quiz joker' => draw a joker to win this round. 'quiz score [player]' => show score for [player] (default is yourself). 'quiz top5' => show top 5 players. 'quiz top <number>' => show top <number> players (max 50). 'quiz stats' => show some statistics. 'quiz fetch' => refetch questions from databases. 'quiz refresh' => refresh the question pool for this channel." + (urls.empty? ? "" : "\nYou can add new questions at #{urls.join(', ')}")
     end
   end
 
@@ -493,7 +493,7 @@ class QuizPlugin < Plugin
     else
         q.canonical_answer = q.answers.first
     end
-    
+
     q.first_try = true
 
     # FIXME 2.0 UTF-8
@@ -562,7 +562,7 @@ class QuizPlugin < Plugin
       q.hinted = true
 
       # FIXME 2.0 UTF-8
-      if q.hintrange.length == 0
+      if q.hint == q.answer_array
         m.reply "#{Bold}#{Color}04BUST!#{Color}#{Bold} This round is over. #{Color}04Minus one point for #{nick}#{Color}."
 
         stats = nil
@@ -637,6 +637,14 @@ class QuizPlugin < Plugin
   end
 
 
+  def cmd_refresh( m, params )
+    q = create_quiz ( m.channel )
+    q.questions.clear
+    fetch_data ( m )
+    cmd_quiz( m, params )
+  end
+
+
   def cmd_top5( m, params )
     chan = m.channel
     q = create_quiz( chan )
@@ -906,6 +914,7 @@ plugin.map 'quiz joker',            :action => 'cmd_joker'
 plugin.map 'quiz score',            :action => 'cmd_score'
 plugin.map 'quiz score :player',    :action => 'cmd_score_player'
 plugin.map 'quiz fetch',            :action => 'cmd_fetch'
+plugin.map 'quiz refresh',          :action => 'cmd_refresh'
 plugin.map 'quiz top5',             :action => 'cmd_top5'
 plugin.map 'quiz top :number',      :action => 'cmd_top_number'
 plugin.map 'quiz stats',            :action => 'cmd_stats'