lita-howdoi 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lita/handlers/howdoi.rb +14 -38
- data/lita-howdoi.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08a51a35b101b8ad418f41c7cebd29ea93ca220e
|
4
|
+
data.tar.gz: e90cb47de247a6de3eb64908cf5c9e60b248c46d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67d72065746769a71e5a7f804dbb4ccaa677d06dce1d0bbd31d6c8fc389555a6b1182100e87e343c4d811f81467938018bd3f1c0408e7b9c07d72b40f055913e
|
7
|
+
data.tar.gz: 15d61085c194105ac9ba0e810b700656c6aa4d8d14436c524646caadefc989999ce7c88b4104400eb84385e7100eb9c3e839681a8090d27b2fbcf22fe74f8ebf
|
data/lib/lita/handlers/howdoi.rb
CHANGED
@@ -3,60 +3,36 @@ require 'nokogiri'
|
|
3
3
|
module Lita
|
4
4
|
module Handlers
|
5
5
|
class Howdoi < Handler
|
6
|
-
|
6
|
+
SEARCH_URL = "http://stackoverflow.com/search"
|
7
7
|
|
8
8
|
route(/^howdoi (.*)$/, :howdoi, command: true, help: {
|
9
9
|
"howdoi QUERY" => "Searches Stack Overflow for the first answer it finds with a solution to QUERY.",
|
10
10
|
})
|
11
11
|
|
12
|
-
def
|
13
|
-
http.get(
|
14
|
-
end
|
15
|
-
|
16
|
-
def is_question?(stackoverflow_url)
|
17
|
-
stackoverflow_url =~ %r(/questions/\d+/)
|
18
|
-
end
|
19
|
-
|
20
|
-
def get_google_links(args)
|
21
|
-
page = get_url(GOOGLE_SEARCH_URL, args)
|
12
|
+
def search_stack_overflow_for(search_query)
|
13
|
+
page = http.get(SEARCH_URL, q: search_query).body
|
22
14
|
html = Nokogiri.HTML(page)
|
23
|
-
|
24
|
-
html.css('.result-link a').each do |link|
|
25
|
-
posts << "http://stackoverflow.com#{link[:href]}"
|
26
|
-
end
|
27
|
-
posts
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_link_at_pos(links, pos)
|
31
|
-
link = nil
|
32
|
-
pos.times do |i|
|
33
|
-
break if i > links.size
|
34
|
-
link = links[i]
|
35
|
-
end
|
36
|
-
link
|
15
|
+
html.css('.result-link a').map { |link| "http://stackoverflow.com#{link[:href]}" }
|
37
16
|
end
|
38
17
|
|
39
18
|
def howdoi(chat)
|
40
|
-
|
41
|
-
|
42
|
-
link = get_link_at_pos(links, 1)
|
19
|
+
search_query = chat.matches[0].last.split.join("+")
|
20
|
+
first_result = search_stack_overflow_for(search_query).first
|
43
21
|
|
44
|
-
if
|
45
|
-
|
46
|
-
|
47
|
-
ans = html.at_css(".answer")
|
22
|
+
if first_result
|
23
|
+
html = Nokogiri.HTML(http.get(first_result).body)
|
24
|
+
answer = html.at_css(".answer")
|
48
25
|
|
49
|
-
if
|
50
|
-
instruction =
|
26
|
+
if answer
|
27
|
+
instruction = answer.css("pre").children.
|
51
28
|
collect(&:content).
|
52
29
|
join(" " * 5 + '-' * 50 + "\n") ||
|
53
|
-
|
30
|
+
answer.at_css("code").content
|
54
31
|
|
55
|
-
|
32
|
+
if !instruction.empty?
|
56
33
|
chat.reply "```\n#{instruction}```"
|
57
34
|
else
|
58
|
-
|
59
|
-
chat.reply "```\n#{ans.at_css('.post-text').content}```"
|
35
|
+
chat.reply "```\n#{answer.at_css('.post-text').content}```"
|
60
36
|
end
|
61
37
|
end
|
62
38
|
else
|
data/lita-howdoi.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-howdoi"
|
3
|
-
spec.version = "0.0.
|
3
|
+
spec.version = "0.0.3"
|
4
4
|
spec.authors = ["Taylor Lapeyre"]
|
5
5
|
spec.email = ["taylorlapeyre@gmail.com"]
|
6
6
|
spec.description = "Crawls Stack Overflow for the first answer it finds with a solution to some query."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-howdoi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Lapeyre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|