summaryrefslogtreecommitdiff
path: root/data/rbot/plugins
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-01-21 14:22:39 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-01-21 14:22:39 +0000
commit6e8e503ede5f3a1a55826c94a87a6be9a5daed0e (patch)
treea8114cfa957215c8cd6471297a5a466e737f73f2 /data/rbot/plugins
parent2b50a3fe6ccea7a4adc5665a02aa9901430a86b9 (diff)
quotefiles are now only saved only if they were changed
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r--data/rbot/plugins/nickserv.rb2
-rw-r--r--data/rbot/plugins/quotes.rb23
2 files changed, 19 insertions, 6 deletions
diff --git a/data/rbot/plugins/nickserv.rb b/data/rbot/plugins/nickserv.rb
index 1e419af4..0e5f2e8a 100644
--- a/data/rbot/plugins/nickserv.rb
+++ b/data/rbot/plugins/nickserv.rb
@@ -157,7 +157,7 @@ class NickServPlugin < Plugin
def listen(m)
return unless(m.kind_of? NoticeMessage)
- if (m.sourcenick == ns_nick && m.message =~ @ident_request)
+ if (m.sourcenick.downcase == ns_nick.downcase && m.message =~ @ident_request)
debug "nickserv asked us to identify for nick #{@bot.nick}"
do_identify
end
diff --git a/data/rbot/plugins/quotes.rb b/data/rbot/plugins/quotes.rb
index 5b496471..aae70592 100644
--- a/data/rbot/plugins/quotes.rb
+++ b/data/rbot/plugins/quotes.rb
@@ -6,6 +6,7 @@ class QuotePlugin < Plugin
def initialize
super
@lists = Hash.new
+ @changed = Hash.new
Dir["#{@bot.botclass}/quotes/*"].each {|f|
next if File.directory?(f)
channel = File.basename(f)
@@ -16,18 +17,24 @@ class QuotePlugin < Plugin
@lists[channel][num] = Quote.new(num, $2, $3, $4)
end
}
+ @changed[channel] = false
}
end
def save
Dir.mkdir("#{@bot.botclass}/quotes") if(!FileTest.directory?("#{@bot.botclass}/quotes"))
@lists.each {|channel, quotes|
begin
- debug "Writing new quotefile for channel #{channel} ..."
- Utils.safe_save("#{@bot.botclass}/quotes/#{channel}") {|file|
- quotes.compact.each {|q|
- file.puts "#{q.num} | #{q.date} | #{q.source} | #{q.quote}"
+ if @changed[channel]
+ debug "Writing new quotefile for channel #{channel} ..."
+ Utils.safe_save("#{@bot.botclass}/quotes/#{channel}") {|file|
+ quotes.compact.each {|q|
+ file.puts "#{q.num} | #{q.date} | #{q.source} | #{q.quote}"
+ }
}
- }
+ @changed[channel] = false
+ else
+ debug "Not writing quotefile for channel #{channel} (unchanged)"
+ end
rescue => e
error "failed to write quotefile for channel #{channel}!\n#{$!}"
error "#{e.class}: #{e}"
@@ -35,10 +42,15 @@ class QuotePlugin < Plugin
end
}
end
+ def cleanup
+ @lists.clear
+ @changed.clear
+ end
def addquote(source, channel, quote)
@lists[channel] = Array.new if(!@lists.has_key?(channel))
num = @lists[channel].length
@lists[channel][num] = Quote.new(num, Time.new, source, quote)
+ @changed[channel] = true
return num
end
def getquote(source, channel, num=nil)
@@ -60,6 +72,7 @@ class QuotePlugin < Plugin
if(@lists[channel][num])
@lists[channel][num] = nil
@lists[channel].pop if num == @lists[channel].length - 1
+ @changed[channel] = true
return true
end
return false