#!/usr/bin/env ruby
#
# Created by Peter Haza on 2007-10-07.
# Copyright (c) 2007. All rights reserved.
module VBBot
class HandleManager
def initialize( connection )
@connection = connection
@handlers = Hash.new() { |h,k| h[k] = [] }
end
def handle( action, *args )
loaded?( action.downcase )
end
def loaded?( handler )
return @handlers.has_key?( handler.to_s )
end
def load( handler )
handler = handler.to_s.downcase
list = Dir.glob( "handlers/#{handler}.rb", 0 )
unless list.empty?
list.each do |file|
require file
h = VBBot::Handlers.const_get( handler.capitalize ).new( self )
@handlers[handler] = h
end
else
@connection.logger.warn( "Handler for #{handler} not found" )
end
end
end
end
test = VBBot::HandleManager.new( nil )
test.load( 'ping' )