X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fsalut.rb;h=1c552aab1969a2f53f1daa25c179930a7b89c09a;hb=7b35acadbd3726d46db8a691036217c336b11058;hp=569bade48d070a208938e532819248ea5641ea2f;hpb=6f9bfa43ac907700fcba394e0f6b9d987b1192fb;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/salut.rb b/data/rbot/plugins/salut.rb index 569bade4..1c552aab 100644 --- a/data/rbot/plugins/salut.rb +++ b/data/rbot/plugins/salut.rb @@ -15,12 +15,12 @@ class SalutPlugin < Plugin Config.register Config::BooleanValue.new('salut.all_languages', - :default => true, + :default => true, :desc => "Check for a salutation in all languages and not just in the one defined by core.language", :on_change => Proc.new {|bot, v| bot.plugins['salut'].reload} ) Config.register Config::BooleanValue.new('salut.address_only', - :default => true, + :default => true, :desc => "When set to true, the bot will only reply to salutations directed at him", :on_change => Proc.new {|bot, v| bot.plugins['salut'].reload} ) @@ -113,7 +113,7 @@ class SalutPlugin < Plugin return unless salut # If the bot wasn't addressed, we continue only if the match was exact # (apart from space and punctuation) or if @match[:dest] matches too - return unless to_me or m.message =~ /^#{@punct}#{salut.first}#{@punct}$/ or m.message =~ @match[salut[1]][:dest] + return unless to_me or m.message =~ /^#{@punct}#{salut.first}#{@punct}$/ or m.message =~ @match[salut[1]][:dest] h = Time.new.hour case h when 4...12 @@ -158,7 +158,7 @@ class SalutPlugin < Plugin end end debug "Replying #{choice}" - m.plainreply choice + m.reply choice, :nick => false, :to => :public end def reload @@ -168,7 +168,7 @@ class SalutPlugin < Plugin @all_langs = @bot.config['salut.all_languages'] if @all_langs # Get all available languages - langs = Dir.new("#{@bot.botclass}/salut").collect {|f| + langs = Dir.new(datafile).collect {|f| f =~ /salut-([^.]+)/ ? $1 : nil }.compact langs.each { |lang| @@ -183,11 +183,11 @@ class SalutPlugin < Plugin end def load_lang(lang) - dir = "#{@bot.botclass}/salut" + dir = datafile if not File.exist?(dir) Dir.mkdir(dir) end - file = "#{@bot.botclass}/salut/salut-#{lang}" + file = File.join dir, "salut-#{lang}" if File.exist?(file) begin salutations = Hash.new @@ -214,7 +214,7 @@ class SalutPlugin < Plugin end def save_lang(lang, val) - fn = "#{@bot.botclass}/salut/salut-#{lang}" + fn = datafile "salut-#{lang}" Utils.safe_save(fn) { |file| file.puts val.to_yaml }