lita-howdoi 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lita/handlers/howdoi.rb +11 -9
- data/lita-howdoi.gemspec +1 -1
- data/spec/lita/handlers/howdoi_spec.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c56116b7c526963d01fc92219714341484088e75
|
4
|
+
data.tar.gz: 0fd161f94ddc87c3b2e371682924b3cd50a07990
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fec1243b2181645292bc9a453e7fe80783b1369b4107277804f0a438e09ec22251576f90a249ff215b42689158711d0bef7c5ea08df596dea7f329a124eb32cf
|
7
|
+
data.tar.gz: 6dfd96b880d6137c127c0b353d384b3806f768e7cf360e3d6a5dce023b44225367a31d0b2f453d2b49c1e4ce536dfeea85f12d51703138149cef90a02afd8eae
|
data/lib/lita/handlers/howdoi.rb
CHANGED
@@ -3,14 +3,14 @@ require 'nokogiri'
|
|
3
3
|
module Lita
|
4
4
|
module Handlers
|
5
5
|
class Howdoi < Handler
|
6
|
-
GOOGLE_SEARCH_URL = "http://
|
6
|
+
GOOGLE_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 get_url(url)
|
13
|
-
http.get(url).body
|
12
|
+
def get_url(url, q="")
|
13
|
+
http.get(url, q: q).body
|
14
14
|
end
|
15
15
|
|
16
16
|
def is_question?(stackoverflow_url)
|
@@ -18,11 +18,11 @@ module Lita
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def get_google_links(args)
|
21
|
-
page = get_url(
|
21
|
+
page = get_url(GOOGLE_SEARCH_URL, args)
|
22
22
|
html = Nokogiri.HTML(page)
|
23
23
|
posts = []
|
24
|
-
html.css('.
|
25
|
-
posts <<
|
24
|
+
html.css('.result-link a').each do |link|
|
25
|
+
posts << "http://stackoverflow.com#{link[:href]}"
|
26
26
|
end
|
27
27
|
posts
|
28
28
|
end
|
@@ -37,7 +37,7 @@ module Lita
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def howdoi(chat)
|
40
|
-
args = chat.matches[0].last.split
|
40
|
+
args = chat.matches[0].last.split.join("+")
|
41
41
|
links = get_google_links(args)
|
42
42
|
link = get_link_at_pos(links, 1)
|
43
43
|
|
@@ -51,10 +51,12 @@ module Lita
|
|
51
51
|
collect(&:content).
|
52
52
|
join(" " * 5 + '-' * 50 + "\n") ||
|
53
53
|
ans.at_css("code").content
|
54
|
-
|
54
|
+
|
55
|
+
unless instruction.empty?
|
55
56
|
chat.reply "```\n#{instruction}```"
|
56
57
|
else
|
57
|
-
|
58
|
+
p ans.at_css('.post-text').content
|
59
|
+
chat.reply "```\n#{ans.at_css('.post-text').content}```"
|
58
60
|
end
|
59
61
|
end
|
60
62
|
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.2"
|
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."
|
@@ -9,4 +9,9 @@ describe Lita::Handlers::Howdoi, lita_handler: true do
|
|
9
9
|
send_command("howdoi split a string in ruby")
|
10
10
|
expect(replies.last).to match /\.split/
|
11
11
|
end
|
12
|
+
|
13
|
+
it "doesn't always return an answer" do
|
14
|
+
send_command("howdoi asdufkjhsdfjidsklf")
|
15
|
+
expect(replies.last).to match /Sorry/
|
16
|
+
end
|
12
17
|
end
|