5 # :title: Mechanize Agent Factory
7 # Author:: Matthias Hecker <apoc@sixserv.org>
9 # Central factory for Mechanize agent instances, creates
10 # pre-configured agents. The main goal of this is to have
11 # central proxy and user agent configuration for mechanize.
13 # plugins can just call @bot.agent.create to return
14 # a new unique mechanize agent.
25 Bot::Config.register Bot::Config::IntegerValue.new('agent.max_redir',
27 :desc => "Maximum number of redirections to be used when getting a document")
28 Bot::Config.register Bot::Config::BooleanValue.new('agent.ssl_verify',
30 :desc => "Whether or not you want to validate SSL certificates")
31 Bot::Config.register Bot::Config::BooleanValue.new('agent.proxy_use',
33 :desc => "Use HTTP proxy or not")
34 Bot::Config.register Bot::Config::StringValue.new('agent.proxy_host',
35 :default => '127.0.0.1',
36 :desc => "HTTP proxy hostname")
37 Bot::Config.register Bot::Config::IntegerValue.new('agent.proxy_port',
39 :desc => "HTTP proxy port")
40 Bot::Config.register Bot::Config::StringValue.new('agent.proxy_username',
42 :desc => "HTTP proxy username")
43 Bot::Config.register Bot::Config::StringValue.new('agent.proxy_password',
45 :desc => "HTTP proxy password")
54 # Returns a new, unique instance of Mechanize.
57 agent.redirection_limit = @bot.config['agent.max_redir']
58 if not @bot.config['agent.ssl_verify']
59 agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
61 if @bot.config['agent.proxy_use']
63 @bot.config['agent.proxy_host'],
64 @bot.config['agent.proxy_port'],
65 @bot.config['agent.proxy_username'],
66 @bot.config['agent.proxy_password']
76 class AgentPlugin < CoreBotModule
79 debug 'initializing agent factory'
80 @bot.agent = Irc::Utils::AgentFactory.new(@bot)
84 debug 'shutting down agent factory'