1 class KarmaPlugin < Plugin
5 # this plugin only wants to store ints!
14 @registry.set_default(0)
16 # import if old file format found
17 if(File.exist?("#{@bot.botclass}/karma.rbot"))
18 puts "importing old karma data"
19 IO.foreach("#{@bot.botclass}/karma.rbot") do |line|
20 if(line =~ /^(\S+)<=>([\d-]+)$/)
23 @registry[item] = karma
26 File.delete("#{@bot.botclass}/karma.rbot")
30 def help(plugin, topic="")
31 "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."
34 if(m.kind_of?(PrivMessage) && m.public?)
35 # in channel message, the kind we are interested in
36 if(m.message =~ /(\+\+|--)/)
37 string = m.message.sub(/\W(--|\+\+)(\(.*?\)|[^(++)(\-\-)\s]+)/, "\2\1")
39 while(string.sub!(/(\(.*?\)|[^(++)(\-\-)\s]+)(\+\+|--)/, ""))
45 key.sub!(/^\((.*)\)$/, "\1")
47 next unless(key.length > 0)
48 next if(key == m.sourcenick)
59 if (m.plugin == "karmastats")
61 max = @registry.values.max
62 min = @registry.values.min
63 best = @registry.to_hash.index(max)
64 worst = @registry.to_hash.index(min)
65 m.reply "#{@registry.length} votes. Best: #{best} (#{max}); Worst: #{worst} (#{min})"
70 m.reply "incorrect usage: " + m.plugin
73 if(m.params =~ /^(?:for\s+)?(\S+?)\??$/)
75 karma = @registry[thing]
77 m.reply "karma for #{thing}: #{@registry[thing]}"
79 m.reply "#{thing} has neutral karma"
84 plugin = KarmaPlugin.new
85 plugin.register("karma")
86 plugin.register("karmastats")