24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/ruboty/rurema.rb', line 24
def rurema(message)
query = message.match_data['query']
query, params = parse_query(query)
url = build_url(query)
if url && exist_resource?(url)
message.reply url
return
end
resp = get SEARCH_API_URL_BASE + query.split.map {|q| "query:#{CGI.escape(q)}"}.join('/')
if resp.nil? || resp[:entries].empty?
message.reply "No document for #{query}"
return
end
resp = params[:n].to_i.times.map do |idx|
url = resp.dig(:entries, idx, :documents, -1, :url)
next unless url
url.sub('docs.ruby-lang.org/ja/search/http://', '')
end.compact
message.reply resp.join("\n")
end
|