X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Frbot%2Fircbot.rb;h=f99dd940d5207794d00c486eeb7e9fb13dd38427;hb=e7558ab501d89ed4d04ff69b58344aec8de50844;hp=6bdf7bdf8eef03f59bf1a1ffa7efa88840183adb;hpb=adb719c8e886fead559802bfce868ddfce001a80;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 6bdf7bdf..f99dd940 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -1,28 +1,14 @@ -# Copyright (C) 2002 Tom Gilbert. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies of the Software and its documentation and acknowledgment shall be -# given in the documentation and software packages that this Software was -# used. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - require 'thread' require 'etc' require 'fileutils' +$debug = false unless $debug +# print +message+ if debugging is enabled +def debug(message=nil) + print "DEBUG: #{message}\n" if($debug && message) + #yield +end + # these first require 'rbot/rbotconfig' require 'rbot/config' @@ -43,8 +29,8 @@ require 'rbot/httputil' module Irc -# Main bot class, which receives messages, handles them or passes them to -# plugins, and stores runtime data +# Main bot class, which manages the various components, receives messages, +# handles them or passes them to plugins, and contains core functionality. class IrcBot # the bot's current nickname attr_reader :nick @@ -71,6 +57,9 @@ class IrcBot # channel info for channels the bot is in attr_reader :channels + # bot's irc socket + attr_reader :socket + # bot's object registry, plugins get an interface to this for persistant # storage (hash interface tied to a bdb file, plugins use Accessors to store # and restore objects in their own namespaces.) @@ -126,8 +115,8 @@ class IrcBot @argv = params[:argv] - unless FileTest.directory? Config::DATADIR - puts "data directory '#{Config::DATADIR}' not found, did you install.rb?" + unless FileTest.directory? Config::datadir + puts "data directory '#{Config::datadir}' not found, did you install.rb?" exit 2 end @@ -140,7 +129,7 @@ class IrcBot puts "Error: file #{botclass} exists but isn't a directory" exit 2 end - FileUtils.cp_r Config::DATADIR+'/templates', botclass + FileUtils.cp_r Config::datadir+'/templates', botclass end Dir.mkdir("#{botclass}/logs") unless File.exist?("#{botclass}/logs") @@ -387,6 +376,7 @@ class IrcBot end while(message.length > 0) end + # queue an arbitraty message for the server def sendq(message="") # temporary @socket.queue(message) @@ -447,6 +437,7 @@ class IrcBot sendq "TOPIC #{where} :#{topic}" end + # disconnect from the server and cleanup all plugins and modules def shutdown(message = nil) trap("SIGTERM", "DEFAULT") trap("SIGHUP", "DEFAULT") @@ -557,6 +548,7 @@ class IrcBot return helpstr end + # returns a string describing the current status of the bot (uptime etc) def status secs_up = Time.new - @startup_time uptime = Utils.secs_to_string secs_up