1 class PointsPlugin < Plugin
5 # this plugin only wants to store ints!
14 @registry.set_default(0)
16 # import if old file format found
17 oldpoints = @bot.path 'points.rbot'
18 if File.exist? oldpoints
19 log "importing old points data"
20 IO.foreach(oldpoints) do |line|
21 if(line =~ /^(\S+)<=>([\d-]+)$/)
24 @registry[item] = points
33 max = @registry.values.max
34 min = @registry.values.min
35 best = @registry.to_hash.index(max)
36 worst = @registry.to_hash.index(min)
37 m.reply "#{@registry.length} items. Best: #{best} (#{max}); Worst: #{worst} (#{min})"
43 thing = m.sourcenick unless thing
45 points = @registry[thing]
47 m.reply "points for #{thing}: #{@registry[thing]}"
49 m.reply "#{thing} has zero points"
53 def setpoints(m, params)
54 thing = (params[:key] || m.sourcenick).to_s
55 @registry[thing] = params[:val].to_i
59 def help(plugin, topic="")
60 "points module: Keeps track of internet points, infusing your pointless life with meaning. Listens to everyone's chat. <thing>++/<thing>-- => increase/decrease points for <thing>, points for <thing>? => show points for <thing>, pointstats => show stats. Points are a community rating system - only in-channel messages can affect points and you cannot adjust your own."
64 return unless m.public? && m.message.match(/\+\+|--/)
68 m.message.split.each_with_index do |tok, i|
69 tok.sub!(/[:,]$/, '') if i == 0
70 catch :me_if_you_can do
71 if m.channel.users[tok].nil?
72 if (tok =~ /^(?:--)(.*[^-].*)$/) || (tok =~ /^(.*[^-].*)(?:--)$/)
75 elsif (tok =~ /^(?:\+\+)(.*[^+].*)$/)||(tok =~ /^(.*[^+].*)(?:\+\+)$/)
81 if (tok =~ /^--+$/) || (tok =~ /^\+\++$/)
90 ac[arg] += (op == '--' ? -1 : 1) unless arg.downcase == m.sourcenick.downcase
97 @registry[k] += (v > 0 ? 1 : -1)
98 m.reply @bot.lang.get("thanks") if k == @bot.nick && v > 0
103 plugin = PointsPlugin.new
105 plugin.default_auth( 'edit', false )
107 plugin.map 'pointstats', :action => 'stats'
108 plugin.map 'points :key', :defaults => {:key => false}
109 plugin.map 'setpoints :key :val', :defaults => {:key => false}, :requirements => {:val => /^-?\d+$/}, :auth_path => 'edit::set!'
110 plugin.map 'points for :key'