X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fquotes.rb;h=a18f1ebac5b2d645f72ed57fa0c060af980f34f8;hb=16336b4a240a4265d1f2df1e30d7b68d3a924287;hp=50ca326ccc8c3325b4cff62d6ea5ce27bdc69a53;hpb=750ec27187e0b528e315657d020b68ba1bde8d90;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/quotes.rb b/data/rbot/plugins/quotes.rb index 50ca326c..a18f1eba 100644 --- a/data/rbot/plugins/quotes.rb +++ b/data/rbot/plugins/quotes.rb @@ -3,17 +3,20 @@ # # :title: Quotes plugin # -# TODO:: use message mapper instead of multiple ifs # TODO:: switch to db 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)) @@ -28,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}" } } @@ -62,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 @@ -266,6 +269,19 @@ end plugin = QuotePlugin.new plugin.register("quotes") +plugin.default_auth('other::edit', false) # Prevent random people from editing other channels quote lists by default +plugin.default_auth('other::view', true) # But allow them to view them + +plugin.map "addquote :channel *quote", :action => :cmd_addquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN }, :auth_path => '!quote::other::edit::add!' +plugin.map "delquote :channel :num", :action => :cmd_delquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN, :num => /^\d+$/ }, :auth_path => '!quote::other::edit::del!' +plugin.map "getquote :channel [:num]", :action => :cmd_getquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN, :num => /^\d+$/ }, :auth_path => '!quote::other::view::get!' +plugin.map "whoquote :channel :num", :action => :cmd_whoquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN, :num => /^\d+$/ }, :auth_path => '!quote::other::view::who!' +plugin.map "whenquote :channel :num", :action => :cmd_whenquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN, :num => /^\d+$/ }, :auth_path => '!quote::other::view::when!' +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 @@ -279,14 +295,3 @@ plugin.map "countquote [*reg]", :action => :cmd_countquote, :private => false, : plugin.map "topicquote [:num]", :action => :cmd_topicquote, :private => false, :requirements => { :num => /^\d+$/ }, :auth_path => '!quote::topic!' plugin.map "lastquote", :action => :cmd_lastquote, :private => false, :auth_path => '!quote::view::last!' -plugin.default_auth('other::edit', false) # Prevent random people from editing other channels quote lists by default -plugin.default_auth('other::view', true) # But allow them to view them - -plugin.map "addquote :channel *quote", :action => :cmd_addquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN }, :auth_path => '!quote::other::edit::add!' -plugin.map "delquote :channel :num", :action => :cmd_delquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN, :num => /^\d+$/ }, :auth_path => '!quote::other::edit::del!' -plugin.map "getquote :channel [:num]", :action => :cmd_getquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN, :num => /^\d+$/ }, :auth_path => '!quote::other::view::get!' -plugin.map "whoquote :channel :num", :action => :cmd_whoquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN, :num => /^\d+$/ }, :auth_path => '!quote::other::view::who!' -plugin.map "whenquote :channel :num", :action => :cmd_whenquote, :requirements => { :channel => Regexp::Irc::GEN_CHAN, :num => /^\d+$/ }, :auth_path => '!quote::other::view::when!' -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!'