~ubuntu-es.bot/ubuntu-es-bot/botijo-trunk

« back to all changes in this revision

Viewing changes to data/rbot/plugins/ubuntues-doc.rb

  • Committer: Jonathan Patrick Davies
  • Date: 2007-11-22 19:32:12 UTC
  • Revision ID: jpatrick@kubuntu.org-20071122193212-k41550mqqs21ntjt
* Nueva version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
#   Plugin for searching doc.ubuntu-es.org for info.
 
3
#   Based on Google  plugin.
 
4
#   Changes by Jonathan Patrick Davies <jpatrick@kubuntu.org>
 
5
#
 
6
 
 
7
require 'net/http'
 
8
require 'uri/common'
 
9
 
 
10
Net::HTTP.version_1_2
 
11
 
 
12
class DocUbuntuEsPlugin < Plugin
 
13
  def help(plugin, topic = "")
 
14
    "doc <parabla> => buscar doc.ubuntu-es.org para <parabla>"
 
15
  end
 
16
  def privmsg(m)
 
17
    unless(m.params && m.params.length > 0)
 
18
      m.reply "uso incorrecto: " + help(m.plugin)
 
19
      return
 
20
    end
 
21
    searchfor = URI.escape m.params
 
22
 
 
23
    query = "/search?hl=es&q=site%3Adoc.ubuntu-es.org+#{searchfor}&btnI=I%27m%20feeling%20lucky"
 
24
    # If we can't find it we tro
 
25
    result = "¡No encontrado! El equipo ubuntu-es-doc necessita tu ayuda! http://doc.ubuntu-es.org"
 
26
 
 
27
    proxy_host = nil
 
28
    proxy_port = nil
 
29
 
 
30
    if(ENV['http_proxy'])
 
31
      if(ENV['http_proxy'] =~ /^http:\/\/(.+):(\d+)$/)
 
32
        proxy_host = $1
 
33
        proxy_port = $2
 
34
      end
 
35
    end
 
36
 
 
37
    http = @bot.httputil.get_proxy(URI.parse("http://www.google.es"))
 
38
 
 
39
    begin
 
40
      http.start {|http|
 
41
        resp = http.get(query)
 
42
        if resp.code == "302"
 
43
          result = resp['location']
 
44
        end
 
45
      }
 
46
    rescue => e
 
47
      p e
 
48
      if e.response && e.response['location']
 
49
        result = e.response['location']
 
50
      else
 
51
        result = "error!"
 
52
      end
 
53
    end
 
54
    m.reply "#{m.params}: #{result}"
 
55
  end
 
56
end
 
57
 
 
58
plugin = DocUbuntuEsPlugin.new
 
59
plugin.register("doc")