From f30f9f04a197f8cabb58139628318a0b2f88c295 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 5 Mar 2007 22:45:10 +0000 Subject: quiz plugin: new cleanup command to remove players with 0 points and 0 jokers --- data/rbot/plugins/quiz.rb | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'data/rbot') diff --git a/data/rbot/plugins/quiz.rb b/data/rbot/plugins/quiz.rb index 7e2c0f83..9a0c5e10 100644 --- a/data/rbot/plugins/quiz.rb +++ b/data/rbot/plugins/quiz.rb @@ -291,7 +291,7 @@ class QuizPlugin < Plugin def help( plugin, topic="" ) if topic == "admin" - "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)." + "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). 'quiz cleanup' => remove players with no points and no jokers." 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. 'quiz refresh' => refresh the question pool for this channel." + (urls.empty? ? "" : "\nYou can add new questions at #{urls.join(', ')}") @@ -791,7 +791,7 @@ class QuizPlugin < Plugin destplayer = PlayerStats.new(0,0,0) end - if sourceplayer == destplayer + if sourceplayer.object_id == destplayer.object_id m.reply "Source and destination are the same, I'm not going to touch them" return end @@ -898,6 +898,27 @@ class QuizPlugin < Plugin q.registry[nick] = player m.reply "Jokers for player #{nick} set to #{val}." end + + + def cmd_cleanup(m, params) + chan = m.channel + q = create_quiz( chan ) + if q.nil? + m.reply "Sorry, the quiz database for #{chan} seems to be corrupt" + return + end + + null_players = [] + q.registry.each { |nick, player| + null_players << nick if player.jokers == 0 and player.score == 0 + } + debug "Cleaning up by removing #{null_players * ', '}" + null_players.each { |nick| + cmd_del_player(m, :nick => nick) + } + + end + end @@ -926,3 +947,4 @@ plugin.map 'quiz transfer :source :dest :score :jokers', :action => 'cmd_transfe plugin.map 'quiz deleteplayer :nick', :action => 'cmd_del_player', :auth_path => 'edit' plugin.map 'quiz setscore :nick :score', :action => 'cmd_set_score', :auth_path => 'edit' plugin.map 'quiz setjokers :nick :jokers', :action => 'cmd_set_jokers', :auth_path => 'edit' +plugin.map 'quiz cleanup', :action => 'cmd_cleanup', :auth_path => 'edit' -- cgit v1.2.3