@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
@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?
+ def message(m)
+ return unless m.public? && m.message.match(/\+\+|--/)
arg = nil
op = nil
ac = Hash.new
if (tok =~ /^(?:--)(.*[^-].*)$/) || (tok =~ /^(.*[^-].*)(?:--)$/)
op, arg = '--', $1
next
- elsif (tok =~ /^(?:\+\+)(.*[^+].*)$/) || (tok =~ /^(.*[^+].*)(?:\+\+)$/)
+ elsif (tok =~ /^(?:\+\+)(.*[^+].*)$/)||(tok =~ /^(.*[^+].*)(?:\+\+)$/)
op, arg = '++', $1
next
end
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