summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-08-03 20:07:14 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-08-03 20:07:14 +0000
commitdd0b318cfd3df017b1ec4e44afc2f4e412fd2033 (patch)
treee364fc26af86c1105124385d8da2768262e97d23 /lib/rbot
parentfba4b7bba7a5d15f2b98f4d9f1ece390881c5ae9 (diff)
Wed Aug 03 15:25:07 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
* Added french language file (TODO most of the plugins just talk english) * The way the Enum configs were set up, it wasn't possible to add language files to rbot at runtime (the directory was only scanned at startup). Now you can set a values Proc, which is called to return a list of allowed values whenever it's queried. * Added Config module for determining where we were installed. Unfortunately rubygems is a total whore in this regard, and I hope the current hackery I have to do to support it becomes redundant in the future.
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/config.rb7
-rw-r--r--lib/rbot/ircbot.rb6
-rw-r--r--lib/rbot/language.rb10
-rw-r--r--lib/rbot/plugins.rb10
-rw-r--r--lib/rbot/post-install.rb (renamed from lib/rbot/post-config.rb)4
-rw-r--r--lib/rbot/rbotconfig.rb33
6 files changed, 56 insertions, 14 deletions
diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb
index 834b5a98..e4237e81 100644
--- a/lib/rbot/config.rb
+++ b/lib/rbot/config.rb
@@ -120,6 +120,13 @@ module Irc
super
@values = params[:values]
end
+ def values
+ if @values.instance_of?(Proc)
+ return @values.call(BotConfig.bot)
+ else
+ return @values
+ end
+ end
def parse(string)
unless @values.include?(string)
raise ArgumentError, "invalid value #{string}, allowed values are: " + @values.join(", ")
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 5f051290..11b03f50 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -108,8 +108,8 @@ class IrcBot
@argv = params[:argv]
- unless FileTest.directory? Config::DATADIR
- puts "data directory '#{Config::DATADIR}' not found, did you install.rb?"
+ unless FileTest.directory? Config::datadir
+ puts "data directory '#{Config::datadir}' not found, did you install.rb?"
exit 2
end
@@ -122,7 +122,7 @@ class IrcBot
puts "Error: file #{botclass} exists but isn't a directory"
exit 2
end
- FileUtils.cp_r Config::DATADIR+'/templates', botclass
+ FileUtils.cp_r Config::datadir+'/templates', botclass
end
Dir.mkdir("#{botclass}/logs") unless File.exist?("#{botclass}/logs")
diff --git a/lib/rbot/language.rb b/lib/rbot/language.rb
index c472c12e..1a4a889a 100644
--- a/lib/rbot/language.rb
+++ b/lib/rbot/language.rb
@@ -4,9 +4,11 @@ module Language
class Language
BotConfig.register BotConfigEnumValue.new('core.language',
:default => "english", :wizard => true,
- :values => Dir.new(Config::DATADIR + "/languages").collect {|f|
- f =~ /\.lang$/ ? f.gsub(/\.lang$/, "") : nil
- }.compact,
+ :values => Proc.new{|bot|
+ Dir.new(Config::datadir + "/languages").collect {|f|
+ f =~ /\.lang$/ ? f.gsub(/\.lang$/, "") : nil
+ }.compact
+ },
:on_change => Proc.new {|bot, v| bot.lang.set_language v},
:desc => "Which language file the bot should use")
@@ -15,7 +17,7 @@ module Language
end
def set_language(language)
- file = Config::DATADIR + "/languages/#{language}.lang"
+ file = Config::datadir + "/languages/#{language}.lang"
unless(FileTest.exist?(file))
raise "no such language: #{language} (no such file #{file})"
end
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index e525ebfc..d98630e1 100644
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -171,7 +171,7 @@ module Plugins
# load plugins from pre-assigned list of directories
def scan
dirs = Array.new
- dirs << Config::DATADIR + "/plugins"
+ dirs << Config::datadir + "/plugins"
dirs += @dirs
dirs.each {|dir|
if(FileTest.directory?(dir))
@@ -179,7 +179,7 @@ module Plugins
d.sort.each {|file|
next if(file =~ /^\./)
next unless(file =~ /\.rb$/)
- @tmpfilename = "#{dir}/#{file}"
+ tmpfilename = "#{dir}/#{file}"
# create a new, anonymous module to "house" the plugin
# the idea here is to prevent namespace pollution. perhaps there
@@ -187,11 +187,11 @@ module Plugins
plugin_module = Module.new
begin
- plugin_string = IO.readlines(@tmpfilename).join("")
- debug "loading module: #{@tmpfilename}"
+ plugin_string = IO.readlines(tmpfilename).join("")
+ debug "loading plugin #{tmpfilename}"
plugin_module.module_eval(plugin_string)
rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err
- puts "warning: plugin #{@tmpfilename} load failed: " + err
+ puts "warning: plugin #{tmpfilename} load failed: " + err
puts err.backtrace.join("\n")
end
}
diff --git a/lib/rbot/post-config.rb b/lib/rbot/post-install.rb
index 182cdfce..e26653ba 100644
--- a/lib/rbot/post-config.rb
+++ b/lib/rbot/post-install.rb
@@ -1,7 +1,7 @@
# write out our datadir so we can reference it at runtime
-File.open('rbotconfig.rb', "w") {|f|
+File.open("#{config('rbdir')}/rbot/pkgconfig.rb", "w") {|f|
f.puts "module Irc"
- f.puts " module Config"
+ f.puts " module PKGConfig"
f.puts " DATADIR = '#{config('datadir')}/rbot'"
f.puts " end"
f.puts "end"
diff --git a/lib/rbot/rbotconfig.rb b/lib/rbot/rbotconfig.rb
new file mode 100644
index 00000000..fad7b032
--- /dev/null
+++ b/lib/rbot/rbotconfig.rb
@@ -0,0 +1,33 @@
+module Irc
+ module Config
+ @@datadir = nil
+ # setup pkg-based configuration - i.e. where were we installed to, where
+ # are our data files, etc.
+ begin
+ require 'rubygems'
+ gemname, gem = Gem.source_index.find{|name, spec| spec.name == 'rbot' && spec.version.version == $version}
+ if gem && path = gem.full_gem_path
+ debug "installed via rubygems to #{path}"
+ @@datadir = "#{path}/data/rbot"
+ else
+ debug "not installed via rubygems"
+ end
+ rescue LoadError
+ debug "no rubygems installed"
+ end
+
+ if @@datadir.nil?
+ begin
+ require 'rbot/pkgconfig'
+ @@datadir = PKGConfig::DATADIR
+ rescue LoadError
+ puts "fatal - no way to determine data dir"
+ exit 2
+ end
+ end
+
+ def Config.datadir
+ @@datadir
+ end
+ end
+end