3 # Copyright (C) 2002 Tom Gilbert.
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to
7 # deal in the Software without restriction, including without limitation the
8 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 # sell copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies of the Software and its documentation and acknowledgment shall be
14 # given in the documentation and software packages that this Software was
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 # Most of the string processing across rbot is done against IRC messages, which
25 # do not have a well-defined encoding. Although many clients are now using
26 # UTF-8, there is no guarantee that an arbitrary string received from IRC will
27 # be UTF-8 encoded. We have to force ASCII (byte-wise/charset agnostic)
28 # matching because otherwise some strings can give problems: in particular, for
29 # example, the bytesequence "\340\350\354\362\371" (that is the aeiou vowels,
30 # each with a grave accent) will cause the string to be considered up to the
31 # "\354" (i with grave accent) only: so either the rest of the message is
32 # ignored, or the matching fails.
45 up = File.dirname(__FILE__) + "/.."
46 rev = " (unknown revision)"
48 svn_out = `svn info #{up}`
49 if svn_out =~ /Last Changed Rev: (\d+)/
50 rev = " (revision #{$1}"
52 svn_st = `svn st #{up}`
54 rev << ", local changes"
65 opts = GetoptLong.new(
66 ["--background", "-b", GetoptLong::NO_ARGUMENT],
67 ["--debug", "-d", GetoptLong::NO_ARGUMENT],
68 ["--help", "-h", GetoptLong::NO_ARGUMENT],
69 ["--loglevel", "-l", GetoptLong::REQUIRED_ARGUMENT],
70 ["--trace", "-t", GetoptLong::REQUIRED_ARGUMENT],
71 ["--version", "-v", GetoptLong::NO_ARGUMENT]
78 $debug = true if(opt == "--debug")
79 $daemonize = true if(opt == "--background")
80 $opts[opt.sub(/^-+/, "")] = arg
83 $cl_loglevel = $opts["loglevel"].to_i
86 set_trace_func proc { |event, file, line, id, binding, classname|
87 if classname.to_s == $opts["trace"]
88 printf "TRACE: %8s %s:%-2d %10s %8s\n", event, File.basename(file), line, id, classname
93 defaultlib = File.expand_path(File.dirname($0) + '/../lib')
95 if File.directory? "#{defaultlib}/rbot"
96 unless $:.include? defaultlib
102 require 'rbot/ircbot'
103 rescue LoadError => e
104 puts "Error: couldn't find the rbot/ircbot module (or one of its dependencies)\n"
109 if ($opts["version"])
110 puts "rbot #{$version}"
115 puts "usage: rbot [options] [config directory]"
116 puts " -h, --help this message"
117 puts " -v, --version version information"
118 puts " -d, --debug enable debug messages"
119 puts " -b, --background background (daemonize) the bot"
120 puts "config directory defaults to ~/.rbot"
124 if(bot = Irc::Bot.new(ARGV.shift, :argv => orig_opts))