Changeset 6083
- Timestamp:
- 02/03/08 06:19:47 (5 years ago)
- Location:
- lang/ruby/chokan/trunk/plugins
- Files:
-
- 3 modified
-
google_calc.rb (modified) (1 diff)
-
google_search.rb (modified) (3 diffs)
-
nico_search.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/chokan/trunk/plugins/google_calc.rb
r6017 r6083 7 7 8 8 def initialize(config, chokan) 9 HYDE === 156.0 && HYDE === 156.0&& HYDE === 156.09 HYDE.is_a?(Numeric) && HYDE === 156.0 10 10 super 11 HYDE === 156.0 && HYDE === 156.0 && HYDE === 156.012 11 @prefix = @config['prefix'] || 'c ' 13 HYDE === 156.0 && HYDE === 156.0 && HYDE === 156.014 12 end 15 13 -
lang/ruby/chokan/trunk/plugins/google_search.rb
r6018 r6083 9 9 def description 10 10 <<-DESCRIPTION.gsub(/^\s+/, '') 11 このプラグインは API を利用しておらず、真っ黒です。 12 ご利用は自己責任となります。 11 このプラグインは Google の API を利用しておらず、真っ黒です。 12 絶対に利用しないでください。 13 <http://www.google.com/accounts/TOS> 13 14 DESCRIPTION 14 15 end … … 18 19 @prefix = @config['prefix'] || 'g' 19 20 @number = @config['number'] || 3 21 @limit = @config['limit'] || 10 20 22 end 21 23 22 24 def on_privmsg(prefix, channel, message) 23 25 case message 24 when /^#{@prefix}(?::(\d+))?\s+(.+)$/ 25 result = search(Regexp.last_match[2], Regexp.last_match[1]) 26 when / 27 ^ 28 #{@prefix} 29 (?: :(\d+) (?# 1: :N) 30 | ((?:#{@prefix})+) (?# 2: repetition of the prefix) 31 )? 32 \s+ 33 (.+) (?# 3: search words) 34 $ 35 /x 36 words = $3 37 number = $1 && $1.to_i || 38 $2 && $2.scan(@prefix).size + 1 39 result = search words, number 26 40 result.each { |line| notice(channel, line) } 27 41 end … … 29 43 30 44 private 31 def search (string, number=nil) 32 number = number && number.to_i <= @number * 2 \ 33 ? number.to_i : @number 45 def search (string, shu=nil) 34 46 result = Array.new 35 47 keywords = string.split(/\s+/).collect{ |item| URI.escape(item, /[^-.!~*'()\w]/n) }.join('+') 36 Net::HTTP.start('www.google.co.jp', 80) do |http| 37 request_uri = "/search?q=#{keywords}&ie=utf-8&oe=utf-8&lr=lang_ja&num=#{number}" 38 response = http.get(request_uri) 48 number = shu.nil? || shu.zero? ? @number : shu <= @limit ? shu : @limit 49 uri = URI.parse("http://www.google.co.jp/search?q=#{keywords}&ie=utf-8&oe=utf-8&lr=lang_ja&num=#{number}") 50 Net::HTTP.start(uri.host, uri.port) do |http| 51 response = http.get(uri.request_uri) 39 52 if response.code.to_i == 200 then 40 53 document = Hpricot(response.body) -
lang/ruby/chokan/trunk/plugins/nico_search.rb
r6064 r6083 11 11 @prefix = @config['prefix'] || 'ns' 12 12 @number = @config['number'] || 3 13 @limit = @config['limit'] || 10 13 14 end 14 15 … … 16 17 case message 17 18 when /^#{@prefix}(?::(\d+))?\s+(.+)$/ 18 result = search(Regexp.last_match[2], Regexp.last_match[1] )19 result = search(Regexp.last_match[2], Regexp.last_match[1] && Regexp.last_match[1].to_i) 19 20 result.each { |line| notice(channel, line) } 20 21 end … … 22 23 23 24 private 24 def search (string, number=nil) 25 number = number && number.to_i <= @number * 2 \ 26 ? number.to_i : @number 27 result = Array.new 28 keywords = string.split(/\s+/).collect{ |item| URI.escape(item, /[^-.!~*'()\w]/n) }.join('+') 29 login_uri = "https://secure.nicovideo.jp/secure/login?mail=#{@config['user']}&password=#{@config['pass']}&site=niconico" 25 def search (string, shu=nil) 26 number = shu.nil? || shu.zero? ? @number : shu <= @limit ? shu : @limit 27 result = Array.new 28 keywords = string.split(/\s+/).collect{ |item| URI.escape(item, /[^-.!~*'()\w]/n) }.join('+') 29 login_uri = "https://secure.nicovideo.jp/secure/login?mail=#{@config['user']}&password=#{@config['pass']}&site=niconico" 30 30 search_uri = "http://www.nicovideo.jp/search/#{keywords}?sort=v" 31 31
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)