diff --git a/lib/playbot.rb b/lib/playbot.rb index 53b94113c263fe27720c8c51d9537cbe661f3ad1..e67661a90279a425f1f4921feea6bf13f9cc52f6 100644 --- a/lib/playbot.rb +++ b/lib/playbot.rb @@ -1,13 +1,19 @@ +require 'uri' + require 'rubygems' require 'net/yail/irc_bot' -require 'site_plugin' +require_relative 'site_plugin.rb' + + +# -- +# Changing working directory so the inclusion of plugin can be done correctly. +# I don't complety know why, but this is necessary. +Dir.chdir(File.expand_path File.dirname(__FILE__)) # -- # Add plugins folder to LOAD_PATH and subsequently require all plugins. -dir = '../plugins' -$LOAD_PATH << dir -Dir[File.join(dir, '*.rb')].each {|file| require File.basename(file) } +Dir[File.join('../plugins', '*.rb')].each { |file| require_relative file } class PlayBot < IRCBot BOTNAME = 'PlayBot' @@ -65,5 +71,16 @@ class PlayBot < IRCBot def _in_msg(event) # we don't care of private messages return if event.pm? + + url = URI.extract(event.message, ['http', 'https']).first + puts "url = #{url}" + + handler = SitePlugin.for_site(url) + return if handler.nil? + + handler = handler.new + content = handler.get(url) + + #TODO: use this content... end end