]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - bin/rbot
fixy
[user/henk/code/ruby/rbot.git] / bin / rbot
1 #!/usr/bin/env ruby
2
3 # Copyright (C) 2002 Tom Gilbert.
4 #
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:
11 #
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
15 # used.
16 #
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.
23
24 $VERBOSE=true
25
26 require 'etc'
27 require 'getoptlong'
28 require 'fileutils'
29
30 $version="0.9.9"
31 $opts = Hash.new
32
33 orig_opts = ARGV.dup
34
35 opts = GetoptLong.new(
36   ["--debug", "-d", GetoptLong::NO_ARGUMENT],
37   ["--help",  "-h", GetoptLong::NO_ARGUMENT],
38   ["--trace",  "-t", GetoptLong::REQUIRED_ARGUMENT],
39   ["--version", "-v", GetoptLong::NO_ARGUMENT]
40 )
41
42 $debug = false
43 opts.each {|opt, arg|
44   $debug = true if(opt == "--debug")
45   $opts[opt.sub(/^-+/, "")] = arg
46 }
47
48 if ($opts["trace"])
49   set_trace_func proc { |event, file, line, id, binding, classname|
50     if classname.to_s == $opts["trace"]
51       printf "TRACE: %8s %s:%-2d %10s %8s\n", event, File.basename(file), line, id, classname
52     end
53   }
54 end
55
56 begin
57   require 'rbot/ircbot'
58 rescue LoadError => e
59   puts "Error: couldn't find the rbot/ircbot module for loading\n - did you install rbot using install.rb?"
60   exit 2
61 end
62
63 if ($opts["version"])
64   puts "rbot #{$version}"
65   exit 0
66 end
67
68 if ($opts["help"])
69   puts "usage: rbot [options] [config directory]"
70   puts "  -h, --help         this message"
71   puts "  -v, --version      version information"
72   puts "  -d, --debug        enable debug messages"
73   puts "config directory defaults to ~/.rbot"
74   exit 0
75 end
76
77 if(bot = Irc::IrcBot.new(ARGV.shift, :argv => orig_opts))
78   # just run the bot
79   bot.mainloop
80 end
81