X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fquiz.rb;h=7e2c0f83b1c201251e3093798de6fa1a4d900699;hb=edd1cf77be07ae507014574141e920ad23eb164d;hp=9a550ea8b9e4a9aecb9c2f705b218c891c8fc91c;hpb=b68c1f63783c2b5bbbec4aa7796aca83fa860f90;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/quiz.rb b/data/rbot/plugins/quiz.rb index 9a550ea8..7e2c0f83 100644 --- a/data/rbot/plugins/quiz.rb +++ b/data/rbot/plugins/quiz.rb @@ -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 # Author:: Jocke Andersson # Author:: Giuseppe Bilotta # Author:: Yaohan Chen # -# (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 ' => 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)." 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 ' => show top 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 ' => show top 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'