end
def save
Dir.mkdir("#{@bot.botclass}/quotes") if(!FileTest.directory?("#{@bot.botclass}/quotes"))
- Dir.mkdir("#{@bot.botclass}/quotes/new") if(!FileTest.directory?("#{@bot.botclass}/quotes/new"))
@lists.each {|channel, quotes|
begin
debug "Writing new quotefile for channel #{channel} ..."
- File.open("#{@bot.botclass}/quotes/new/#{channel}", "w") {|file|
+ Utils.safe_save("#{@bot.botclass}/quotes/#{channel}") {|file|
quotes.compact.each {|q|
file.puts "#{q.num} | #{q.date} | #{q.source} | #{q.quote}"
}
}
- debug "Officializing quotefile for channel #{channel} ..."
- File.rename("#{@bot.botclass}/quotes/new/#{channel}",
- "#{@bot.botclass}/quotes/#{channel}")
rescue => e
error "failed to write quotefile for channel #{channel}!\n#{$!}"
error "#{e.class}: #{e}"
case command
when (/^addquote\s+(.+)/)
if(@bot.auth.allow?("addquote", m.source, m.replyto))
- num = addquote(m.source, m.target, $1)
+ num = addquote(m.source, m.target.to_s, $1)
m.reply "added the quote (##{num})"
end
when (/^getquote$/)
if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target)
+ quote, total = getquote(m.source, m.target.to_s)
if(quote)
m.reply "[#{quote.num}] #{quote.quote}"
else
when (/^getquote\s+(\d+)$/)
num = $1.to_i
if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target, num)
+ quote, total = getquote(m.source, m.target.to_s, num)
if(quote)
m.reply "[#{quote.num}] #{quote.quote}"
else
when (/^whenquote\s+(\d+)$/)
num = $1.to_i
if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target, num)
+ quote, total = getquote(m.source, m.target.to_s, num)
if(quote)
m.reply "quote #{quote.num} added on #{quote.date}"
else
when (/^whoquote\s+(\d+)$/)
num = $1.to_i
if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target, num)
+ quote, total = getquote(m.source, m.target.to_s, num)
if(quote)
m.reply "quote #{quote.num} added by #{quote.source}"
else
end
when (/^topicquote$/)
if(@bot.auth.allow?("topicquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target)
+ quote, total = getquote(m.source, m.target.to_s)
if(quote)
@bot.topic m.target, "[#{quote.num}] #{quote.quote}"
else
when (/^topicquote\s+(\d+)$/)
num = $1.to_i
if(@bot.auth.allow?("topicquote", m.source, m.replyto))
- quote, total = getquote(m.source, m.target, num)
+ quote, total = getquote(m.source, m.target.to_s, num)
if(quote)
@bot.topic m.target, "[#{quote.num}] #{quote.quote}"
else
when (/^delquote\s+(\d+)$/)
num = $1.to_i
if(@bot.auth.allow?("delquote", m.source, m.replyto))
- if(delquote(m.target, num))
+ if(delquote(m.target.to_s, num))
m.okay
else
m.reply "quote not found!"
when (/^searchquote\s+(.*)$/)
reg = $1
if(@bot.auth.allow?("getquote", m.source, m.replyto))
- quote, total = searchquote(m.source, m.target, reg)
+ quote, total = searchquote(m.source, m.target.to_s, reg)
if(quote)
m.reply "[#{quote.num}] #{quote.quote}"
else
when (/^countquote(?:\s+(.*))?$/)
reg = $1
if(@bot.auth.allow?("getquote", m.source, m.replyto))
- total = countquote(m.source, m.target, reg)
+ total = countquote(m.source, m.target.to_s, reg)
if(reg && reg.length > 0)
m.reply "#{total} quotes match: #{reg}"
else