X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fpoints.rb;h=21157f3d00af7cf26b15d9592337aa7d1029082e;hb=6cf365c49ce5fbe24c0a4ff0663550390b501fea;hp=1a1464e545e7643282693651303cc2105126c2ca;hpb=2700d5d2817671329261b22f8edc3a27b1f52595;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/points.rb b/data/rbot/plugins/points.rb index 1a1464e5..21157f3d 100644 --- a/data/rbot/plugins/points.rb +++ b/data/rbot/plugins/points.rb @@ -30,14 +30,26 @@ class PointsPlugin < Plugin def stats(m, params) if (@registry.length) - max = @registry.values.max - min = @registry.values.min - best = @registry.to_hash.index(max) - worst = @registry.to_hash.index(min) + max = @registry.values.max || "zero" + min = @registry.values.min || "zero" + best = @registry.to_hash.key(max) || "nobody" + worst = @registry.to_hash.key(min) || "nobody" m.reply "#{@registry.length} items. Best: #{best} (#{max}); Worst: #{worst} (#{min})" end end + def dump(m, params) + if (@registry.length) + msg = "Points dump: " + msg << @registry.to_hash.sort_by { |k, v| v }.reverse. + map { |k,v| "#{k}: #{v}" }. + join(", ") + m.reply msg + else + m.reply "nobody has any points yet!" + end + end + def points(m, params) thing = params[:key] thing = m.sourcenick unless thing @@ -57,7 +69,7 @@ class PointsPlugin < Plugin end def help(plugin, topic="") - "points module: Keeps track of internet points, infusing your pointless life with meaning. Listens to everyone's chat. ++/-- => increase/decrease points for , points for ? => show points for , pointstats => show stats. Points are a community rating system - only in-channel messages can affect points and you cannot adjust your own." + "points module: Keeps track of internet points, infusing your pointless life with meaning. Listens to everyone's chat. ++/-- => increase/decrease points for , points for ? => show points for , pointstats => show best/worst, pointsdump => show everyone's points. Points are a community rating system - only in-channel messages can affect points and you cannot adjust your own." end def message(m) @@ -96,6 +108,7 @@ class PointsPlugin < Plugin next if v == 0 @registry[k] += (v > 0 ? 1 : -1) m.reply @bot.lang.get("thanks") if k == @bot.nick && v > 0 + m.reply "#{k} now has #{@registry[k]} points!" end end end @@ -108,3 +121,4 @@ plugin.map 'pointstats', :action => 'stats' plugin.map 'points :key', :defaults => {:key => false} plugin.map 'setpoints :key :val', :defaults => {:key => false}, :requirements => {:val => /^-?\d+$/}, :auth_path => 'edit::set!' plugin.map 'points for :key' +plugin.map 'pointsdump', :action => 'dump'