summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/salut.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-02-15 01:30:51 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-02-15 02:06:27 +0100
commit91a9024e21ec8b429605a036b5c9193442a580e3 (patch)
treef1524dd5595a80e32d0702c0d8939b1001c695fb /data/rbot/plugins/salut.rb
parent38be7f6511447d98780a069bccefecd933238e30 (diff)
+ @bot.path and datafile methods
We provide two methods that make it more simple and elegant for botmodules to define paths relative to the bot's own directory (botclass) and to the BotModule's (assumed) non-registry directory. The first method is Irc::Bot#path(), which joins its arguments with the botclass. This method can be used to access datafiles in the bot directory with a much cleaner syntax; and since it uses File.join, the resulting paths are also properly formatted on each platform, which doesn't hurt. Each BotModule now also carries a dirname() method that should return the directory under botclass that holds the BotModule's datafiles. dirname() defaults to the BotModule's name(), but it can be overridden, e.g. for backwards compatibility (see the patch for the quotes plugin), or for BotModules that share their datafiles. Datafiles can be accessed using the BotModule#datafile() method that joins the botclass, the dirname() and whatever other argument is passed.
Diffstat (limited to 'data/rbot/plugins/salut.rb')
-rw-r--r--data/rbot/plugins/salut.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/data/rbot/plugins/salut.rb b/data/rbot/plugins/salut.rb
index c169d138..e80a02b0 100644
--- a/data/rbot/plugins/salut.rb
+++ b/data/rbot/plugins/salut.rb
@@ -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
}