]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/games/quiz.rb
seen: show what user said or did before leaving
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / quiz.rb
index 37602fba7b62cfc1f394fcdf17d0ad4f58d3cc9d..ca2abf470948427dec7de7603c5b17c855d7b152 100644 (file)
@@ -184,10 +184,11 @@ class QuizPlugin < Plugin
   # (in quiz/) or web pages.
   #
   def fetch_data( m )
-    # Read the winning messages file 
+    # Read the winning messages file
     @win_messages = Array.new
-    if File.exists? "#{@bot.botclass}/quiz/win_messages"
-      IO.foreach("#{@bot.botclass}/quiz/win_messages") { |line| @win_messages << line.chomp }
+    winfile = datafile 'win_messages'
+    if File.exists? winfile
+      IO.foreach(winfile) { |line| @win_messages << line.chomp }
     else
       warning( "win_messages file not found!" )
       # Fill the array with a least one message or code accessing it would fail
@@ -212,13 +213,13 @@ class QuizPlugin < Plugin
           m.reply "Failed to download questions from #{p}, ignoring sources"
         end
       else
-        path = "#{@bot.botclass}/quiz/#{p}"
+        path = datafile p
         debug "Fetching from #{path}"
 
         # Local data
         begin
-          datafile = File.new( path, File::RDONLY )
-          data << "\n\n" << datafile.read
+          file = File.new( path, File::RDONLY )
+          data << "\n\n" << file.read
         rescue
           m.reply "Failed to read from local database file #{p}, skipping."
         end
@@ -338,7 +339,7 @@ class QuizPlugin < Plugin
         end
       end
 
-      # If less than all other players' scores, append to table 
+      # If less than all other players' scores, append to table
       unless inserted
         i += 1 unless q.rank_table.empty?
         q.rank_table << [nick, stats]
@@ -360,9 +361,7 @@ class QuizPlugin < Plugin
 
   # Reimplemented from Plugin
   #
-  def listen( m )
-    return unless m.kind_of?(PrivMessage)
-
+  def message(m)
     chan = m.channel
     return unless @quizzes.has_key?( chan )
     q = @quizzes[chan]
@@ -371,7 +370,7 @@ class QuizPlugin < Plugin
 
     message = m.message.downcase.strip
 
-    nick = m.sourcenick.to_s 
+    nick = m.sourcenick.to_s
 
     # Support multiple alternate answers and cores
     answer = q.answers.find { |ans| ans.valid?(message) }
@@ -706,7 +705,7 @@ class QuizPlugin < Plugin
       score = player[1].score
       ar << "#{i + 1}. #{unhilight_nick( nick )} (#{score})"
     end
-    m.reply ar.join(" | ")
+    m.reply ar.join(" | "), :split_at => /\s+\|\s+/
   end
 
 
@@ -932,9 +931,23 @@ class QuizPlugin < Plugin
 
   end
 
-end
-
+  def stop(m, params)
+    unless m.public?
+      m.reply 'you must be on some channel to use this command'
+      return
+    end
+    if @quizzes.delete m.channel
+      @ask_mutex.synchronize do
+        t = @waiting.delete(m.channel)
+        @bot.timer.remove t if t
+      end
+      m.okay
+    else
+      m.reply(_("there is no active quiz on #{m.channel}"))
+    end
+  end
 
+end
 
 plugin = QuizPlugin.new
 plugin.default_auth( 'edit', false )
@@ -952,6 +965,7 @@ 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'
+plugin.map 'quiz stop', :action => :stop
 
 # Admin commands
 plugin.map 'quiz autoask :enable',  :action => 'cmd_autoask', :auth_path => 'edit'