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)
60 m.reply "incorrect usage: " + m.plugin
63 if(m.params =~ /^(?:for\s+)?(\S+?)\??$/)
65 karma = @registry[thing]
67 m.reply "karma for #{thing}: #{@registry[thing]}"
69 m.reply "#{thing} has neutral karma"
74 plugin = KarmaPlugin.new
75 plugin.register("karma")