]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/karma.rb
weather plugin: refactor HTML cleanup code
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / karma.rb
index 824ffa956445e3f98ef375a7286c63d0df57232b..eac8d8738845b401d6847647c0e852d3e62359f0 100644 (file)
@@ -15,7 +15,7 @@ class KarmaPlugin < Plugin
 
     # import if old file format found
     if(File.exist?("#{@bot.botclass}/karma.rbot"))
-      puts "importing old karma data"
+      log "importing old karma data"
       IO.foreach("#{@bot.botclass}/karma.rbot") do |line|
         if(line =~ /^(\S+)<=>([\d-]+)$/)
           item = $1
@@ -25,7 +25,6 @@ class KarmaPlugin < Plugin
       end
       File.delete("#{@bot.botclass}/karma.rbot")
     end
-
   end
 
   def stats(m, params)
@@ -49,11 +48,17 @@ class KarmaPlugin < Plugin
       m.reply "#{thing} has neutral karma"
     end
   end
-  
+
+  def setkarma(m, params)
+    thing = (params[:key] || m.sourcenick).to_s
+    @registry[thing] = params[:val].to_i
+    karma(m, params)
+  end
   
   def help(plugin, topic="")
     "karma module: Listens to everyone's chat. <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)
     return unless m.kind_of?(PrivMessage) && m.public?
     # in channel message, the kind we are interested in
@@ -69,9 +74,12 @@ class KarmaPlugin < Plugin
         key.sub!(/^\((.*)\)$/, "\1")
         key.gsub!(/\s+/, " ")
         next unless(key.length > 0)
-        next if(key == m.sourcenick)
+        next if(key.downcase == m.sourcenick.downcase)
         if(change == "++")
           @registry[key] += 1
+          if key =~ /^#{@bot.nick}$/i
+            @bot.say m.replyto, @bot.lang.get("thanks")
+          end
         elsif(change == "--")
           @registry[key] -= 1
         end
@@ -79,7 +87,12 @@ class KarmaPlugin < Plugin
     end
   end
 end
+
 plugin = KarmaPlugin.new
+
+plugin.default_auth( 'edit', false )
+
 plugin.map 'karmastats', :action => 'stats'
 plugin.map 'karma :key', :defaults => {:key => false}
+plugin.map 'setkarma :key :val', :defaults => {:key => false}, :requirements => {:val => /^-?\d+$/}, :auth_path => 'edit::set!'
 plugin.map 'karma for :key'