X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fquotes.rb;h=a18f1ebac5b2d645f72ed57fa0c060af980f34f8;hb=10ae83bef9c81cef32639b07d2a30f9ebfdc6440;hp=257bf88007a77b3e99aa28110c6ff044168bb894;hpb=eb6fc83e7a46a23ce8ffa7750ae62dcb0574769b;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/quotes.rb b/data/rbot/plugins/quotes.rb index 257bf880..a18f1eba 100644 --- a/data/rbot/plugins/quotes.rb +++ b/data/rbot/plugins/quotes.rb @@ -8,11 +8,15 @@ define_structure :Quote, :num, :date, :source, :quote class QuotePlugin < Plugin + def dirname + 'quotes' + end + def initialize super @lists = Hash.new @changed = Hash.new - Dir["#{@bot.botclass}/quotes/*"].each {|f| + Dir[datafile '*'].each {|f| next if File.directory?(f) channel = File.basename(f) @lists[channel] = Array.new if(!@lists.has_key?(channel)) @@ -27,13 +31,13 @@ class QuotePlugin < Plugin end def save - Dir.mkdir("#{@bot.botclass}/quotes") if(!FileTest.directory?("#{@bot.botclass}/quotes")) + Dir.mkdir(datafile) unless FileTest.directory? datafile @lists.each {|channel, quotes| begin if @changed[channel] debug "Writing new quotefile for channel #{channel} ..." - Utils.safe_save("#{@bot.botclass}/quotes/#{channel}") {|file| - quotes.compact.each {|q| + Utils.safe_save(datafile channel) {|file| + quotes.compact.each {|q| file.puts "#{q.num} | #{q.date} | #{q.source} | #{q.quote}" } } @@ -61,7 +65,7 @@ class QuotePlugin < Plugin def addquote(source, channel, quote) @lists[channel] = Array.new if(!@lists.has_key?(channel)) - num = @lists[channel].length + num = @lists[channel].length @lists[channel][num] = Quote.new(num, Time.new, source.fullform, quote) @changed[channel] = true return num @@ -276,6 +280,7 @@ plugin.map "whenquote :channel :num", :action => :cmd_whenquote, :requirements = plugin.map "searchquote :channel *reg", :action => :cmd_searchquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN }, :auth_path => '!quote::other::view::search!' plugin.map "countquote :channel [*reg]", :action => :cmd_countquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN }, :auth_path => '!quote::other::view::count!' plugin.map "topicquote :channel [:num]", :action => :cmd_topicquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN, :num => /^\d+$/ }, :auth_path => '!quote::other::topic!' +plugin.map "lastquote :channel", :action => :cmd_lastquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN }, :auth_path => '!quote::other::view::last!' plugin.default_auth('edit', false) # Prevent random people from removing quotes plugin.default_auth('edit::add', true) # But allow them to add them