]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - bin/rbot
just some tiny tweaks. giuseppe! you have been busy! :)
[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 $KCODE = 'u'
25
26 $VERBOSE=true
27
28 require 'etc'
29 require 'getoptlong'
30 require 'fileutils'
31
32 $version="0.9.10-svn"
33 $opts = Hash.new
34
35 orig_opts = ARGV.dup
36
37 opts = GetoptLong.new(
38   ["--background", "-b", GetoptLong::NO_ARGUMENT],
39   ["--debug", "-d", GetoptLong::NO_ARGUMENT],
40   ["--help",  "-h", GetoptLong::NO_ARGUMENT],
41   ["--loglevel",  "-l", GetoptLong::REQUIRED_ARGUMENT],
42   ["--trace",  "-t", GetoptLong::REQUIRED_ARGUMENT],
43   ["--version", "-v", GetoptLong::NO_ARGUMENT]
44 )
45
46 $debug = false
47 $daemonize = false
48
49 opts.each {|opt, arg|
50   $debug = true if(opt == "--debug")
51   $daemonize = true if(opt == "--background")
52   $opts[opt.sub(/^-+/, "")] = arg
53 }
54
55 $cl_loglevel = $opts["loglevel"].to_i
56
57 if ($opts["trace"])
58   set_trace_func proc { |event, file, line, id, binding, classname|
59     if classname.to_s == $opts["trace"]
60       printf "TRACE: %8s %s:%-2d %10s %8s\n", event, File.basename(file), line, id, classname
61     end
62   }
63 end
64
65 defaultlib = File.expand_path(File.dirname($0) + '/../lib')
66
67 if File.directory? "#{defaultlib}/rbot"
68   unless $:.include? defaultlib
69     $:.push defaultlib
70   end
71 end
72   
73 begin
74   require 'rbot/ircbot'
75 rescue LoadError => e
76   puts "Error: couldn't find the rbot/ircbot module (or one of its dependencies)\n"
77   puts e
78   exit 2
79 end
80
81 if ($opts["version"])
82   puts "rbot #{$version}"
83   exit 0
84 end
85
86 if ($opts["help"])
87   puts "usage: rbot [options] [config directory]"
88   puts "  -h, --help         this message"
89   puts "  -v, --version      version information"
90   puts "  -d, --debug        enable debug messages"
91   puts "  -b, --background   background (daemonize) the bot"
92   puts "config directory defaults to ~/.rbot"
93   exit 0
94 end
95
96 if(bot = Irc::IrcBot.new(ARGV.shift, :argv => orig_opts))
97   # just run the bot
98   bot.mainloop
99 end
100