From a708da678ebafbfac08e1c867610fc809680ae68 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 15 Oct 2006 19:36:36 +0000 Subject: [PATCH] Make the lart plugin use language-specific lart/praises --- data/rbot/plugins/lart.rb | 42 ++++++++++++------- .../templates/lart/{larts => larts-english} | 0 .../lart/{praises => praises-english} | 0 3 files changed, 28 insertions(+), 14 deletions(-) rename data/rbot/templates/lart/{larts => larts-english} (100%) rename data/rbot/templates/lart/{praises => praises-english} (100%) diff --git a/data/rbot/plugins/lart.rb b/data/rbot/plugins/lart.rb index d4abee3b..40a0432a 100644 --- a/data/rbot/plugins/lart.rb +++ b/data/rbot/plugins/lart.rb @@ -1,9 +1,13 @@ -# Author: Michael Brailsford -# aka brailsmt -# Purpose: Provide for humorous larts and praises -# Copyright: 2002 Michael Brailsford. All rights reserved. -# License: This plugin is licensed under the BSD license. The terms of -# which follow. +# Original Author: +# Michael Brailsford +# aka brailsmt +# Author: Giuseppe "Oblomov" Bilotta +# Purpose: Provide for humorous larts and praises +# Original Copyright: +# 2002 Michael Brailsford. All rights reserved. +# Copyright: 2006 Giuseppe Bilotta. All rights reserved. +# License: This plugin is licensed under the BSD license. The terms of +# which follow. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -33,17 +37,26 @@ class LartPlugin < Plugin end def initialize - super @larts = Array.new @praises = Array.new - #read in the lart and praise files - if File.exists? "#{@bot.botclass}/lart/larts" - IO.foreach("#{@bot.botclass}/lart/larts") { |line| + @lartfile = nil + @praisefile = nil + super + end + + def set_language(lang) + save + @lartfile = "#{@bot.botclass}/lart/larts-#{lang}" + @praisefile = "#{@bot.botclass}/lart/praises-#{lang}" + @larts.clear + @praises.clear + if File.exists? @lartfile + IO.foreach(@lartfile) { |line| @larts << line.chomp } end - if File.exists? "#{@bot.botclass}/lart/praises" - IO.foreach("#{@bot.botclass}/lart/praises") { |line| + if File.exists? @praisefile + IO.foreach(@praisefile) { |line| @praises << line.chomp } end @@ -53,12 +66,13 @@ class LartPlugin < Plugin end def save + return if @lartfile.nil? and @praisefile.nil? Dir.mkdir("#{@bot.botclass}/lart") if not FileTest.directory? "#{@bot.botclass}/lart" # TODO implement safe saving here too - File.open("#{@bot.botclass}/lart/larts", "w") { |file| + File.open(@lartfile, "w") { |file| file.puts @larts } - File.open("#{@bot.botclass}/lart/praises", "w") { |file| + File.open(@praisefile, "w") { |file| file.puts @praises } end diff --git a/data/rbot/templates/lart/larts b/data/rbot/templates/lart/larts-english similarity index 100% rename from data/rbot/templates/lart/larts rename to data/rbot/templates/lart/larts-english diff --git a/data/rbot/templates/lart/praises b/data/rbot/templates/lart/praises-english similarity index 100% rename from data/rbot/templates/lart/praises rename to data/rbot/templates/lart/praises-english -- 2.39.2