]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - bin/rbot
rbot now tries to report svn revision when ran from a svn checkout
[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.11-svn"
33 $opts = Hash.new
34
35 if $version =~ /svn/
36   up = File.dirname(__FILE__) + "/.."
37   rev = " (unknown revision)"
38   begin
39     svn_out = `svn info #{up}`
40     if svn_out =~ /Last Changed Rev: (\d+)/
41       rev = " (revision #{$1}"
42     end
43     svn_st = `svn st #{up}`
44     if svn_st =~ /^M /
45       rev << ", local changes"
46     end
47     rev << ")"
48   rescue => e
49     puts e.inspect
50   end
51   $version += rev
52 end
53
54 orig_opts = ARGV.dup
55
56 opts = GetoptLong.new(
57   ["--background", "-b", GetoptLong::NO_ARGUMENT],
58   ["--debug", "-d", GetoptLong::NO_ARGUMENT],
59   ["--help",  "-h", GetoptLong::NO_ARGUMENT],
60   ["--loglevel",  "-l", GetoptLong::REQUIRED_ARGUMENT],
61   ["--trace",  "-t", GetoptLong::REQUIRED_ARGUMENT],
62   ["--version", "-v", GetoptLong::NO_ARGUMENT]
63 )
64
65 $debug = false
66 $daemonize = false
67
68 opts.each {|opt, arg|
69   $debug = true if(opt == "--debug")
70   $daemonize = true if(opt == "--background")
71   $opts[opt.sub(/^-+/, "")] = arg
72 }
73
74 $cl_loglevel = $opts["loglevel"].to_i
75
76 if ($opts["trace"])
77   set_trace_func proc { |event, file, line, id, binding, classname|
78     if classname.to_s == $opts["trace"]
79       printf "TRACE: %8s %s:%-2d %10s %8s\n", event, File.basename(file), line, id, classname
80     end
81   }
82 end
83
84 defaultlib = File.expand_path(File.dirname($0) + '/../lib')
85
86 if File.directory? "#{defaultlib}/rbot"
87   unless $:.include? defaultlib
88     $:.unshift defaultlib
89   end
90 end
91   
92 begin
93   require 'rbot/ircbot'
94 rescue LoadError => e
95   puts "Error: couldn't find the rbot/ircbot module (or one of its dependencies)\n"
96   puts e
97   exit 2
98 end
99
100 if ($opts["version"])
101   puts "rbot #{$version}"
102   exit 0
103 end
104
105 if ($opts["help"])
106   puts "usage: rbot [options] [config directory]"
107   puts "  -h, --help         this message"
108   puts "  -v, --version      version information"
109   puts "  -d, --debug        enable debug messages"
110   puts "  -b, --background   background (daemonize) the bot"
111   puts "config directory defaults to ~/.rbot"
112   exit 0
113 end
114
115 if(bot = Irc::IrcBot.new(ARGV.shift, :argv => orig_opts))
116   # just run the bot
117   bot.mainloop
118 end
119