X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=data%2Frbot%2Fplugins%2Fkarma.rb;h=060e743ec9687bd02406f9b6220f8fec97eeb189;hb=52c9564c96dbf95e5c883e41940527f2394ba55a;hp=eecfbe26644629a88a5e417a76f4fabe1a68fdd9;hpb=ba0a7761f4aa50deccadac1cebfe3dce18ec3b17;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/karma.rb b/data/rbot/plugins/karma.rb index eecfbe26..060e743e 100644 --- a/data/rbot/plugins/karma.rb +++ b/data/rbot/plugins/karma.rb @@ -14,16 +14,17 @@ class KarmaPlugin < Plugin @registry.set_default(0) # import if old file format found - if(File.exist?("#{@bot.botclass}/karma.rbot")) + oldkarma = @bot.path 'karma.rbot' + if File.exist? oldkarma log "importing old karma data" - IO.foreach("#{@bot.botclass}/karma.rbot") do |line| + IO.foreach(oldkarma) do |line| if(line =~ /^(\S+)<=>([\d-]+)$/) item = $1 karma = $2.to_i @registry[item] = karma end end - File.delete("#{@bot.botclass}/karma.rbot") + File.delete oldkarma end end @@ -54,13 +55,13 @@ class KarmaPlugin < Plugin @registry[thing] = params[:val].to_i karma(m, params) end - + def help(plugin, topic="") "karma module: Listens to everyone's chat. ++/-- => increase/decrease karma for , karma for ? => show karma for , 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? + def message(m) + return unless m.public? && m.message.match(/\+\+|--/) arg = nil op = nil ac = Hash.new @@ -71,7 +72,7 @@ class KarmaPlugin < Plugin if (tok =~ /^(?:--)(.*[^-].*)$/) || (tok =~ /^(.*[^-].*)(?:--)$/) op, arg = '--', $1 next - elsif (tok =~ /^(?:\+\+)(.*[^+].*)$/) || (tok =~ /^(.*[^+].*)(?:\+\+)$/) + elsif (tok =~ /^(?:\+\+)(.*[^+].*)$/)||(tok =~ /^(.*[^+].*)(?:\+\+)$/) op, arg = '++', $1 next end @@ -94,7 +95,7 @@ class KarmaPlugin < Plugin ac.each do |k, v| next if v == 0 @registry[k] += (v > 0 ? 1 : -1) - m.reply @bot.lang.get("thanks") if k == @bot.nick + m.reply @bot.lang.get("thanks") if k == @bot.nick && v > 0 end end end