root/bin/rbot @ e6a570257f2ccf7eff3f2055d695880a451320ac

Revision e6a570257f2ccf7eff3f2055d695880a451320ac, 3.0 KB (checked in by Giuseppe Bilotta <giuseppe.bilotta@…>, 2 months ago)

Version 0.9.15

  • Property mode set to 100755
RevLine 
[0f3e302]1#!/usr/bin/env ruby
2
[c602a60]3=begin rdoc
4
5= rbot main executable
6
7Usage:
8
9  % rbot [options] [config directory]
10
11== Options
12
13[-h, --help]
14    display a help message and exit
15[-v, --version]
16    display version information and exit
17[-d, --debug]
18    enable debug messages
19[-l, --loglevel _level_]
20    sets the minimum log level verbosity
21[-b, --background]
22    background (daemonize) the bot
23[-p, --pidfile _filename_]
24    write the bot pid to _filename_
25
26The default config directory is <tt>~/.rbot</tt>.
27
28The default pidfile is <tt><i>botdir</i>/rbot.pid</tt>.
29
30The logfile is located at <tt><i>botdir</i>/<i>botname</i>.log</tt>, and
31the default loglevel is 1 (INFO messages). Possible values for the loglevel
32are 0 (DEBUG), 1 (INFO), 2 (WARN), 3 (ERROR), 4 (FATAL).
33
34Please note that the logfile doesn't contain IRC logs (which are located at
35<tt><i>botdir</i>/logs/*</tt>, but only rbot diagnostic messages.
36
37=end
38
[b3300ca]39# Copyright (C) 2002-2006 Tom Gilbert.
40# Copyright (C) 2007-2008 Giuseppe Bilotta and the rbot development team
[0f3e302]41#
[b3300ca]42# This is free software, see COPYING for licensing details
[0f3e302]43
44$VERBOSE=true
45
[dd0b318]46require 'etc'
47require 'getoptlong'
48require 'fileutils'
49
[e6a5702]50$version ||= '0.9.15'
[34bf735]51$version_timestamp ||= 0
[dd0b318]52$opts = Hash.new
53
[adb719c]54orig_opts = ARGV.dup
55
[0f3e302]56opts = GetoptLong.new(
[6701756]57  ["--background", "-b", GetoptLong::NO_ARGUMENT],
[20b78c4]58  ["--debug", "-d", GetoptLong::NO_ARGUMENT],
[8caeee3]59  ["--help",  "-h", GetoptLong::NO_ARGUMENT],
[6701756]60  ["--loglevel",  "-l", GetoptLong::REQUIRED_ARGUMENT],
[8caeee3]61  ["--trace",  "-t", GetoptLong::REQUIRED_ARGUMENT],
[a7b1061]62  ["--pidfile", "-p", GetoptLong::REQUIRED_ARGUMENT],
[6701756]63  ["--version", "-v", GetoptLong::NO_ARGUMENT]
[0f3e302]64)
65
[97ad67c]66$debug = $DEBUG
[eff60cf]67$daemonize = false
68
[0f3e302]69opts.each {|opt, arg|
70  $debug = true if(opt == "--debug")
[eff60cf]71  $daemonize = true if(opt == "--background")
[0f3e302]72  $opts[opt.sub(/^-+/, "")] = arg
73}
74
[39d0cea]75$cl_loglevel = $opts["loglevel"].to_i if $opts["loglevel"]
[6701756]76
[8caeee3]77if ($opts["trace"])
78  set_trace_func proc { |event, file, line, id, binding, classname|
79    if classname.to_s == $opts["trace"]
80      printf "TRACE: %8s %s:%-2d %10s %8s\n", event, File.basename(file), line, id, classname
81    end
82  }
83end
84
[fe11699]85defaultlib = File.expand_path(File.dirname($0) + '/../lib')
86
87if File.directory? "#{defaultlib}/rbot"
88  unless $:.include? defaultlib
[b7f04a7]89    $:.unshift defaultlib
[fe11699]90  end
91end
92 
[dd0b318]93begin
94  require 'rbot/ircbot'
95rescue LoadError => e
[fe11699]96  puts "Error: couldn't find the rbot/ircbot module (or one of its dependencies)\n"
[119892c]97  puts e
[dd0b318]98  exit 2
99end
[8caeee3]100
[7cad4b6]101# ruby 1.9 specific fixes
102unless RUBY_VERSION < '1.9'
103  require 'rbot/compat19'
104end
105
[20b78c4]106if ($opts["version"])
107  puts "rbot #{$version}"
108  exit 0
109end
110
[da8e3ef]111if ($opts["help"])
112  puts "usage: rbot [options] [config directory]"
113  puts "  -h, --help         this message"
114  puts "  -v, --version      version information"
115  puts "  -d, --debug        enable debug messages"
[c602a60]116  puts "  -l, --loglevel     sets the log level verbosity"
[eff60cf]117  puts "  -b, --background   background (daemonize) the bot"
[c602a60]118  puts "  -p, --pidfile      write the bot pid to file"
[da8e3ef]119  puts "config directory defaults to ~/.rbot"
120  exit 0
121end
122
[7b7f130]123if(bot = Irc::Bot.new(ARGV.shift, :argv => orig_opts))
[da8e3ef]124  # just run the bot
125  bot.mainloop
[0f3e302]126end
127
Note: See TracBrowser for help on using the browser.