summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--Rakefile2
-rwxr-xr-xbin/rbot29
-rwxr-xr-xdocgen2
-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
10 files changed, 84 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index 614e20e2..40ede6d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+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.
+
Wed Aug 03 00:31:41 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
* Added Rakefile, tweaked gemspec
diff --git a/Rakefile b/Rakefile
index 18c66a06..9f9157de 100644
--- a/Rakefile
+++ b/Rakefile
@@ -21,7 +21,7 @@ spec = Gem::Specification.new do |s|
s.autorequire = 'rbot/ircbot'
s.has_rdoc = true
- s.rdoc_options = ['--exclude', '(post-config.rb|rbotconfig.rb)',
+ s.rdoc_options = ['--exclude', 'post-install.rb',
'--title', 'rbot API Documentation', '--main', 'README', 'README']
s.author = 'Tom Gilbert'
diff --git a/bin/rbot b/bin/rbot
index 886f820a..a5c71492 100755
--- a/bin/rbot
+++ b/bin/rbot
@@ -22,22 +22,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
$VERBOSE=true
-
-require 'etc'
-require 'getoptlong'
-require 'fileutils'
-require 'rbconfig'
-
-begin
- require 'rbot/ircbot'
-rescue LoadError => e
- puts "Error: couldn't find the rbot/ircbot module for loading\n - did you install rbot using install.rb?"
- exit 2
-end
-
$debug = false
-$version="0.9.9"
-$opts = Hash.new
# print +message+ if debugging is enabled
def debug(message=nil)
@@ -45,6 +30,13 @@ def debug(message=nil)
#yield
end
+require 'etc'
+require 'getoptlong'
+require 'fileutils'
+
+$version="0.9.9"
+$opts = Hash.new
+
orig_opts = ARGV.dup
opts = GetoptLong.new(
@@ -67,6 +59,13 @@ if ($opts["trace"])
}
end
+begin
+ require 'rbot/ircbot'
+rescue LoadError => e
+ puts "Error: couldn't find the rbot/ircbot module for loading\n - did you install rbot using install.rb?"
+ exit 2
+end
+
if ($opts["version"])
puts "rbot #{$version}"
diff --git a/docgen b/docgen
index a35bfc5d..e07cee27 100755
--- a/docgen
+++ b/docgen
@@ -1,3 +1,3 @@
#!/bin/sh
-rdoc -a -i 'lib' --exclude '(post-config.rb|rbotconfig.rb)' --main lib/rbot/ircbot.rb -o doc lib bin/rbot
+rdoc -a -i 'lib' --exclude 'post-install.rb' --main lib/rbot/ircbot.rb -o doc lib bin/rbot
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