summaryrefslogtreecommitdiff
path: root/rbot/plugins/karma.rb
diff options
context:
space:
mode:
Diffstat (limited to 'rbot/plugins/karma.rb')
-rw-r--r--rbot/plugins/karma.rb93
1 files changed, 46 insertions, 47 deletions
diff --git a/rbot/plugins/karma.rb b/rbot/plugins/karma.rb
index 1bed175a..148427a5 100644
--- a/rbot/plugins/karma.rb
+++ b/rbot/plugins/karma.rb
@@ -27,60 +27,59 @@ class KarmaPlugin < Plugin
end
end
+
+ 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)
+ m.reply "#{@registry.length} items. Best: #{best} (#{max}); Worst: #{worst} (#{min})"
+ end
+ end
+
+ def karma(m, params)
+ thing = params[:key]
+ thing = m.sourcenick unless thing
+ thing = thing.to_s
+ karma = @registry[thing]
+ if(karma != 0)
+ m.reply "karma for #{thing}: #{@registry[thing]}"
+ else
+ m.reply "#{thing} has neutral karma"
+ end
+ end
+
+
def help(plugin, topic="")
- "karma module: <thing>++/<thing>-- => increase/decrease karma for <thing>, karma for <thing>? => show karma for <thing>. Karma is a community rating system - only in-channel messages can affect karma and you cannot adjust your own."
+ "karma module: <thing>++/<thing>-- => increase/decrease karma for <thing>, karma for <thing>? => show karma for <thing>, karmastats => show stats. Karma is a community rating system - only in-channel messages can affect karma and you cannot adjust your own."
end
def listen(m)
- if(m.kind_of?(PrivMessage) && m.public?)
- # in channel message, the kind we are interested in
- if(m.message =~ /(\+\+|--)/)
- string = m.message.sub(/\W(--|\+\+)(\(.*?\)|[^(++)(\-\-)\s]+)/, "\2\1")
- seen = Hash.new
- while(string.sub!(/(\(.*?\)|[^(++)(\-\-)\s]+)(\+\+|--)/, ""))
- key = $1
- change = $2
- next if seen[key]
- seen[key] = true
+ return unless m.kind_of?(PrivMessage) && m.public?
+ # in channel message, the kind we are interested in
+ if(m.message =~ /(\+\+|--)/)
+ string = m.message.sub(/\W(--|\+\+)(\(.*?\)|[^(++)(\-\-)\s]+)/, "\2\1")
+ seen = Hash.new
+ while(string.sub!(/(\(.*?\)|[^(++)(\-\-)\s]+)(\+\+|--)/, ""))
+ key = $1
+ change = $2
+ next if seen[key]
+ seen[key] = true
- key.sub!(/^\((.*)\)$/, "\1")
- key.gsub!(/\s+/, " ")
- next unless(key.length > 0)
- next if(key == m.sourcenick)
- if(change == "++")
- @registry[key] += 1
- elsif(change == "--")
- @registry[key] -= 1
- end
+ key.sub!(/^\((.*)\)$/, "\1")
+ key.gsub!(/\s+/, " ")
+ next unless(key.length > 0)
+ next if(key == m.sourcenick)
+ if(change == "++")
+ @registry[key] += 1
+ elsif(change == "--")
+ @registry[key] -= 1
end
end
end
end
- def privmsg(m)
- if (m.plugin == "karmastats")
- if (@registry.length)
- max = @registry.values.max
- min = @registry.values.min
- best = @registry.to_hash.index(max)
- worst = @registry.to_hash.index(min)
- m.reply "#{@registry.length} votes. Best: #{best} (#{max}); Worst: #{worst} (#{min})"
- return
- end
- end
- unless(m.params)
- m.reply "incorrect usage: " + m.plugin
- return
- end
- if(m.params =~ /^(?:for\s+)?(\S+?)\??$/)
- thing = $1
- karma = @registry[thing]
- if(karma != 0)
- m.reply "karma for #{thing}: #{@registry[thing]}"
- else
- m.reply "#{thing} has neutral karma"
- end
- end
- end
end
plugin = KarmaPlugin.new
-plugin.register("karma")
-plugin.register("karmastats")
+plugin.map 'karmastats', :action => 'stats'
+plugin.map 'karma :key', :defaults => {:key => false}
+plugin.map 'karma for :key'