cinch-wikipedia 1.0.0 → 1.0.6
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 +7 -0
- data/.travis.yml +31 -2
- data/README.md +1 -1
- data/Rakefile +4 -4
- data/cinch-wikipedia.gemspec +18 -15
- data/lib/cinch-wikipedia.rb +2 -2
- data/lib/cinch/plugins/wikipedia.rb +67 -0
- data/lib/cinch/plugins/wikipedia/version.rb +3 -1
- data/spec/cinch-wikipedia_spec.rb +21 -13
- data/spec/spec_helper.rb +4 -21
- metadata +74 -57
- data/lib/cinch/plugins/wikipedia/wikipedia.rb +0 -62
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c58c81c016cd674a1de487b0d0bf24cfa42bd53753291cf77b718546b6f0ccf4
|
4
|
+
data.tar.gz: e76b020a6db12d71f426cfe67a76d92c5d68a4de9187119a3cc51a0b768fa8cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e14c045f1ab624d50d1e13530186e241b8e66ad1f4f28f7a96c3134b8dcfef1ed4b26e61954294b495b8e524549eeb6aa2561edc29b0ffa83a2f1ebf98b0a31
|
7
|
+
data.tar.gz: 34ab062343ce99a2ae77ba1ee6344deb78b092bd4ed27f32896be4300e309e14c8d09425442f86f04c54594f458fe21799aae8a0a7e07485f3151741f408ce97
|
data/.travis.yml
CHANGED
@@ -1,5 +1,34 @@
|
|
1
|
-
|
1
|
+
addons:
|
2
|
+
code_climate:
|
3
|
+
repo_token: 2be14078568687e04a23810df8b2d8b5f11347f586f720c90b74d79aed27bb6a
|
4
|
+
language: ruby
|
5
|
+
before_install:
|
6
|
+
- gem update --system
|
7
|
+
- gem update bundler
|
8
|
+
env:
|
9
|
+
global:
|
10
|
+
- "JRUBY_OPTS=-Xcext.enabled=true"
|
2
11
|
rvm:
|
3
|
-
-
|
12
|
+
- 1.8.7
|
4
13
|
- 1.9.2
|
5
14
|
- 1.9.3
|
15
|
+
- 2.0.0
|
16
|
+
- 2.1.0
|
17
|
+
- 2.2.0
|
18
|
+
- 2.3.0
|
19
|
+
- jruby-18mode
|
20
|
+
- jruby-19mode
|
21
|
+
- ruby-head
|
22
|
+
- jruby-head
|
23
|
+
- ree
|
24
|
+
matrix:
|
25
|
+
allow_failures:
|
26
|
+
- rvm: 1.8.7
|
27
|
+
- rvm: 1.9.2
|
28
|
+
- rvm: 1.9.3
|
29
|
+
- rvm: ree
|
30
|
+
- rvm: jruby-18mode
|
31
|
+
- rvm: jruby-19mode
|
32
|
+
- rvm: jruby-head
|
33
|
+
- rvm: ruby-head
|
34
|
+
fast_finish: true
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](http://badge.fury.io/rb/cinch-wikipedia)
|
4
4
|
[](https://gemnasium.com/bhaberer/cinch-wikipedia)
|
5
5
|
[](https://travis-ci.org/bhaberer/cinch-wikipedia)
|
6
|
-
[](https://codeclimate.com/github/bhaberer/cinch-wikipedia/coverage)
|
7
7
|
[](https://codeclimate.com/github/bhaberer/cinch-wikipedia)
|
8
8
|
|
9
9
|
Cinch plugin to query wikipedia.
|
data/Rakefile
CHANGED
data/cinch-wikipedia.gemspec
CHANGED
@@ -4,24 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'cinch/plugins/wikipedia/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
7
|
+
gem.name = 'cinch-wikipedia'
|
8
8
|
gem.version = Cinch::Plugins::Wikipedia::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.description =
|
12
|
-
|
13
|
-
gem.
|
9
|
+
gem.authors = ['Brian Haberer']
|
10
|
+
gem.email = ['bhaberer@gmail.com']
|
11
|
+
gem.description = 'Cinch plugin that fetches a truncated blurb from the '\
|
12
|
+
'head of a wikipedia page.'
|
13
|
+
gem.summary = 'Cinch Wikipedia Plugin'
|
14
|
+
gem.homepage = 'https://github.com/bhaberer/cinch-wikipedia'
|
15
|
+
gem.license = 'MIT'
|
14
16
|
|
15
|
-
gem.files = `git ls-files`.split(
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
17
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = [
|
20
|
+
gem.require_paths = ['lib']
|
19
21
|
|
20
|
-
gem.add_development_dependency 'rake'
|
21
|
-
gem.add_development_dependency 'rspec'
|
22
|
-
gem.add_development_dependency '
|
22
|
+
gem.add_development_dependency 'rake', '~> 12.3.3'
|
23
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
24
|
+
gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.1'
|
25
|
+
gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
|
23
26
|
|
24
|
-
gem.add_dependency 'cinch',
|
25
|
-
gem.add_dependency 'cinch-
|
26
|
-
gem.add_dependency 'cinch-
|
27
|
+
gem.add_dependency 'cinch', '~> 2'
|
28
|
+
gem.add_dependency 'cinch-cooldown', '~> 1.1', '>= 1.1.7'
|
29
|
+
gem.add_dependency 'cinch-toolbox', '~> 1.1', '>= 1.1.6'
|
27
30
|
end
|
data/lib/cinch-wikipedia.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'cinch/plugins/wikipedia/version'
|
2
|
+
require 'cinch/plugins/wikipedia'
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'cinch'
|
3
|
+
require 'cinch/toolbox'
|
4
|
+
require 'cinch/cooldown'
|
5
|
+
|
6
|
+
module Cinch
|
7
|
+
module Plugins
|
8
|
+
# Plugin to allow users to search wikipedia.
|
9
|
+
class Wikipedia
|
10
|
+
include Cinch::Plugin
|
11
|
+
|
12
|
+
enforce_cooldown
|
13
|
+
|
14
|
+
self.help = 'Use .wiki <term> to see the Wikipedia info for that term.'
|
15
|
+
|
16
|
+
match(/wiki(?:pedia)? (.*)/)
|
17
|
+
|
18
|
+
def initialize(*args)
|
19
|
+
super
|
20
|
+
@max_length = config[:max_length] || 300
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute(m, term)
|
24
|
+
m.reply wiki(term)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def wiki(term)
|
30
|
+
# URI Encode
|
31
|
+
term = URI.escape(term, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
32
|
+
url = "http://en.wikipedia.org/w/index.php?search=#{term}"
|
33
|
+
|
34
|
+
# Truncate text and url if they are too long
|
35
|
+
text = Cinch::Toolbox.truncate(get_def(term, url), @max_length)
|
36
|
+
url = Cinch::Toolbox.shorten(url)
|
37
|
+
|
38
|
+
"Wikipedia ∴ #{text} [#{url}]"
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_def(term, url)
|
42
|
+
cats = Cinch::Toolbox.get_html_element(url, '#mw-normal-catlinks')
|
43
|
+
if cats && cats.include?('Disambiguation')
|
44
|
+
return "'#{term} is too vague and lead to a disambiguation page."
|
45
|
+
else
|
46
|
+
wiki_text = Cinch::Toolbox.get_html_element(url, '#mw-content-text/p')
|
47
|
+
if wiki_text.nil?
|
48
|
+
return not_found(url)
|
49
|
+
end
|
50
|
+
return wiki_text
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def not_found(url)
|
55
|
+
msg = "I couldn't find anything for that search, "
|
56
|
+
alt_term = Cinch::Toolbox.get_html_element(url, '.searchdidyoumean')
|
57
|
+
if alt_term
|
58
|
+
alt_term = alt_term[/\ADid you mean: (\w+)\z/, 1]
|
59
|
+
msg << "did you mean '#{alt_term}'?"
|
60
|
+
else
|
61
|
+
msg << 'sorry!'
|
62
|
+
end
|
63
|
+
msg
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,41 +1,49 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Cinch::Plugins::Wikipedia do
|
4
|
+
include Cinch::Test
|
4
5
|
|
5
6
|
before(:all) do
|
6
|
-
@
|
7
|
+
@bot = make_bot(Cinch::Plugins::Wikipedia)
|
7
8
|
end
|
8
9
|
|
9
10
|
# normal queries
|
10
11
|
it 'should return a definition of a term' do
|
11
|
-
@
|
12
|
-
|
12
|
+
expect(get_replies(make_message(@bot, '!wiki computer')).first.text)
|
13
|
+
.to include('A computer is a general purpose device')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return a definition of a term for each version of cmd' do
|
17
|
+
msg1 = get_replies(make_message(@bot, '!wiki computer')).first.text
|
18
|
+
msg2 = get_replies(make_message(@bot, '!wikipedia computer')).first.text
|
19
|
+
expect(msg1).to eq(msg2)
|
13
20
|
end
|
14
21
|
|
15
22
|
it 'should not return multiple lined definitions' do
|
16
|
-
@
|
17
|
-
|
23
|
+
expect(get_replies(make_message(@bot, '!wiki Teenager')).first.text)
|
24
|
+
.to_not include("\n")
|
18
25
|
end
|
19
26
|
|
20
27
|
it 'should not return definitions that are longer than 250 chars' do
|
21
|
-
@
|
22
|
-
|
28
|
+
expect(get_replies(make_message(@bot, '!wiki Teenager')).first.text.length)
|
29
|
+
.to eq 334
|
23
30
|
end
|
24
31
|
|
25
32
|
# Not found
|
26
33
|
it 'should return an error message when a term is not found' do
|
27
|
-
@
|
28
|
-
|
34
|
+
msg = make_message(@bot, '!wiki dasdafasfasfasfasafsdfsdfsadf')
|
35
|
+
expect(get_replies(msg).first.text)
|
36
|
+
.to include("I couldn't find anything for that search, sorry!")
|
29
37
|
end
|
30
38
|
|
31
39
|
it 'should provide suggestions if one is listed on the page' do
|
32
|
-
@
|
33
|
-
|
40
|
+
expect(get_replies(make_message(@bot, '!wiki cliinton')).first.text)
|
41
|
+
.to include("I couldn't find anything for that search, did you mean 'clinton'?")
|
34
42
|
end
|
35
43
|
|
36
44
|
# disambiguation
|
37
45
|
it 'should return helful information when a disambuation page' do
|
38
|
-
@
|
39
|
-
|
46
|
+
expect(get_replies(make_message(@bot, '!wiki hacker')).first.text)
|
47
|
+
.to include('is too vague and lead to a disambiguation page')
|
40
48
|
end
|
41
49
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,22 +1,5 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require 'cinch-wikipedia'
|
4
|
-
|
5
|
-
def fake_bot
|
6
|
-
bot = Cinch::Bot.new
|
7
|
-
bot.loggers.level = :fatal
|
8
|
-
bot
|
9
|
-
return bot
|
10
|
-
end
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
11
3
|
|
12
|
-
|
13
|
-
|
14
|
-
def initialize(opts = {})
|
15
|
-
@bot = fake_bot
|
16
|
-
@handlers = []
|
17
|
-
@timers = []
|
18
|
-
# Don't init the bot
|
19
|
-
# __register
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
4
|
+
require 'cinch-wikipedia'
|
5
|
+
require 'cinch/test'
|
metadata
CHANGED
@@ -1,112 +1,131 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-wikipedia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brian Haberer
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-01-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 12.3.3
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 12.3.3
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
33
|
+
version: '3'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
40
|
+
version: '3'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
42
|
+
name: cinch-test
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
47
|
+
version: '0.1'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.1.1
|
54
51
|
type: :development
|
55
52
|
prerelease: false
|
56
53
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
54
|
requirements:
|
59
|
-
- -
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.1'
|
58
|
+
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
60
|
+
version: 0.1.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: codeclimate-test-reporter
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.4'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0.4'
|
62
75
|
- !ruby/object:Gem::Dependency
|
63
76
|
name: cinch
|
64
77
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
78
|
requirements:
|
67
|
-
- - ~>
|
79
|
+
- - "~>"
|
68
80
|
- !ruby/object:Gem::Version
|
69
|
-
version: 2
|
81
|
+
version: '2'
|
70
82
|
type: :runtime
|
71
83
|
prerelease: false
|
72
84
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
85
|
requirements:
|
75
|
-
- - ~>
|
86
|
+
- - "~>"
|
76
87
|
- !ruby/object:Gem::Version
|
77
|
-
version: 2
|
88
|
+
version: '2'
|
78
89
|
- !ruby/object:Gem::Dependency
|
79
|
-
name: cinch-
|
90
|
+
name: cinch-cooldown
|
80
91
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
92
|
requirements:
|
83
|
-
- - ~>
|
93
|
+
- - "~>"
|
84
94
|
- !ruby/object:Gem::Version
|
85
|
-
version: 1.
|
95
|
+
version: '1.1'
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.1.7
|
86
99
|
type: :runtime
|
87
100
|
prerelease: false
|
88
101
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
102
|
requirements:
|
91
|
-
- - ~>
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '1.1'
|
106
|
+
- - ">="
|
92
107
|
- !ruby/object:Gem::Version
|
93
|
-
version: 1.
|
108
|
+
version: 1.1.7
|
94
109
|
- !ruby/object:Gem::Dependency
|
95
|
-
name: cinch-
|
110
|
+
name: cinch-toolbox
|
96
111
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
112
|
requirements:
|
99
|
-
- - ~>
|
113
|
+
- - "~>"
|
100
114
|
- !ruby/object:Gem::Version
|
101
|
-
version: 1.
|
115
|
+
version: '1.1'
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.1.6
|
102
119
|
type: :runtime
|
103
120
|
prerelease: false
|
104
121
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
122
|
requirements:
|
107
|
-
- - ~>
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '1.1'
|
126
|
+
- - ">="
|
108
127
|
- !ruby/object:Gem::Version
|
109
|
-
version: 1.
|
128
|
+
version: 1.1.6
|
110
129
|
description: Cinch plugin that fetches a truncated blurb from the head of a wikipedia
|
111
130
|
page.
|
112
131
|
email:
|
@@ -115,43 +134,41 @@ executables: []
|
|
115
134
|
extensions: []
|
116
135
|
extra_rdoc_files: []
|
117
136
|
files:
|
118
|
-
- .gitignore
|
119
|
-
- .travis.yml
|
137
|
+
- ".gitignore"
|
138
|
+
- ".travis.yml"
|
120
139
|
- Gemfile
|
121
140
|
- LICENSE.txt
|
122
141
|
- README.md
|
123
142
|
- Rakefile
|
124
143
|
- cinch-wikipedia.gemspec
|
125
144
|
- lib/cinch-wikipedia.rb
|
145
|
+
- lib/cinch/plugins/wikipedia.rb
|
126
146
|
- lib/cinch/plugins/wikipedia/version.rb
|
127
|
-
- lib/cinch/plugins/wikipedia/wikipedia.rb
|
128
147
|
- spec/cinch-wikipedia_spec.rb
|
129
148
|
- spec/spec_helper.rb
|
130
149
|
homepage: https://github.com/bhaberer/cinch-wikipedia
|
131
|
-
licenses:
|
132
|
-
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
133
154
|
rdoc_options: []
|
134
155
|
require_paths:
|
135
156
|
- lib
|
136
157
|
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
158
|
requirements:
|
139
|
-
- -
|
159
|
+
- - ">="
|
140
160
|
- !ruby/object:Gem::Version
|
141
161
|
version: '0'
|
142
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
163
|
requirements:
|
145
|
-
- -
|
164
|
+
- - ">="
|
146
165
|
- !ruby/object:Gem::Version
|
147
166
|
version: '0'
|
148
167
|
requirements: []
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
specification_version: 3
|
168
|
+
rubygems_version: 3.2.6
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
153
171
|
summary: Cinch Wikipedia Plugin
|
154
172
|
test_files:
|
155
173
|
- spec/cinch-wikipedia_spec.rb
|
156
174
|
- spec/spec_helper.rb
|
157
|
-
has_rdoc:
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'cinch'
|
3
|
-
require 'cinch-toolbox'
|
4
|
-
require 'cinch-cooldown'
|
5
|
-
|
6
|
-
module Cinch::Plugins
|
7
|
-
class Wikipedia
|
8
|
-
include Cinch::Plugin
|
9
|
-
|
10
|
-
enforce_cooldown
|
11
|
-
|
12
|
-
self.help = "Use .wiki <term> to see the Wikipedia info for that term."
|
13
|
-
|
14
|
-
match /wiki (.*)/
|
15
|
-
match /wikipedia (.*)/
|
16
|
-
|
17
|
-
def initialize(*args)
|
18
|
-
super
|
19
|
-
@max_length = config[:max_length] || 300
|
20
|
-
end
|
21
|
-
|
22
|
-
def execute(m, term)
|
23
|
-
m.reply get_def(term)
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def get_def(term)
|
29
|
-
# URI Encode
|
30
|
-
term = URI.escape(term, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
31
|
-
url = "http://en.wikipedia.org/w/index.php?search=#{term}"
|
32
|
-
|
33
|
-
cats = Cinch::Toolbox.get_html_element(url, '#mw-normal-catlinks')
|
34
|
-
if cats && cats.include?('Disambiguation')
|
35
|
-
wiki_text = "'#{term} is too vague and lead to a disambiguation page."
|
36
|
-
else
|
37
|
-
# Grab the text
|
38
|
-
wiki_text = Cinch::Toolbox.get_html_element(url, '#mw-content-text p')
|
39
|
-
|
40
|
-
# Check for search errors
|
41
|
-
return not_found(wiki_text, url) if wiki_text.include?('Help:Searching')
|
42
|
-
end
|
43
|
-
|
44
|
-
# Truncate text and url if they are too long
|
45
|
-
text = Cinch::Toolbox.truncate(wiki_text, @max_length)
|
46
|
-
url = Cinch::Toolbox.shorten(url)
|
47
|
-
|
48
|
-
return "Wikipedia ∴ #{text} [#{url}]"
|
49
|
-
end
|
50
|
-
|
51
|
-
def not_found(wiki_text, url)
|
52
|
-
msg = "I couldn't find anything for that search"
|
53
|
-
if alt_term_text = Cinch::Toolbox.get_html_element(url, '.searchdidyoumean')
|
54
|
-
alt_term = alt_term_text[/\ADid you mean: (\w+)\z/, 1]
|
55
|
-
msg << ", did you mean '#{alt_term}'?"
|
56
|
-
else
|
57
|
-
msg << ", sorry!"
|
58
|
-
end
|
59
|
-
return msg
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|