cinch-wikipedia 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ nguage: ruby
2
+ rvm:
3
+ - ruby-head
4
+ - 1.9.2
5
+ - 1.9.3
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Cinch::Plugins::Wikipedia
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/cinch-wikipedia.png)](http://badge.fury.io/rb/cinch-wikipedia)
4
+ [![Dependency Status](https://gemnasium.com/bhaberer/cinch-wikipedia.png)](https://gemnasium.com/bhaberer/cinch-wikipedia)
5
+ [![Build Status](https://travis-ci.org/bhaberer/cinch-wikipedia.png?branch=master)](https://travis-ci.org/bhaberer/cinch-wikipedia)
6
+ [![Coverage Status](https://coveralls.io/repos/bhaberer/cinch-wikipedia/badge.png?branch=master)](https://coveralls.io/r/bhaberer/cinch-wikipedia?branch=master)
7
+ [![Code Climate](https://codeclimate.com/github/bhaberer/cinch-wikipedia.png)](https://codeclimate.com/github/bhaberer/cinch-wikipedia)
8
+
3
9
  Cinch plugin to query wikipedia.
4
10
 
5
11
  ## Installation
@@ -18,9 +24,13 @@ Or install it yourself as:
18
24
 
19
25
  ## Usage
20
26
 
21
- Just add th plugin to your list:
27
+ Just add the plugin to your list:
22
28
 
23
- c.plugins.plugins = [Cinch::Plugins::Wikipedia]
29
+ @bot = Cinch::Bot.new do
30
+ configure do |c|
31
+ c.plugins.plugins = [Cinch::Plugins::Wikipedia]
32
+ end
33
+ end
24
34
 
25
35
  Then in channel use .wiki:
26
36
 
@@ -33,3 +43,9 @@ Then in channel use .wiki:
33
43
  3. Commit your changes (`git commit -am 'Add some feature'`)
34
44
  4. Push to the branch (`git push origin my-new-feature`)
35
45
  5. Create new Pull Request
46
+
47
+ ## Changelog
48
+
49
+ * v1.0.0
50
+ * Added checks for terms that are not found and disambig pages.
51
+ * Tests!
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -17,6 +17,11 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency 'cinch-toolbox'
21
- gem.add_dependency 'cinch-cooldown'
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'coveralls'
23
+
24
+ gem.add_dependency 'cinch', '~> 2.0.4'
25
+ gem.add_dependency 'cinch-toolbox', '~> 1.0.0'
26
+ gem.add_dependency 'cinch-cooldown', '~> 1.0.0'
22
27
  end
@@ -1,2 +1,2 @@
1
- require "cinch/plugins/wikipedia/version.rb"
2
- require "cinch/plugins/wikipedia/wikipedia.rb"
1
+ require "cinch/plugins/wikipedia/version"
2
+ require "cinch/plugins/wikipedia/wikipedia"
@@ -1,7 +1,7 @@
1
1
  module Cinch
2
2
  module Plugins
3
3
  class Wikipedia
4
- VERSION = "0.0.1"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -14,6 +14,11 @@ module Cinch::Plugins
14
14
  match /wiki (.*)/
15
15
  match /wikipedia (.*)/
16
16
 
17
+ def initialize(*args)
18
+ super
19
+ @max_length = config[:max_length] || 300
20
+ end
21
+
17
22
  def execute(m, term)
18
23
  m.reply get_def(term)
19
24
  end
@@ -25,13 +30,33 @@ module Cinch::Plugins
25
30
  term = URI.escape(term, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
26
31
  url = "http://en.wikipedia.org/w/index.php?search=#{term}"
27
32
 
28
- # Grab the text
29
- text = Cinch::Toolbox.get_html_element(url, '#mw-content-text p')
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
30
43
 
31
- # Truncate if it's super long
32
- text = Cinch::Toolbox.truncate(text, 300)
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
33
50
 
34
- return "Wikipedia ∴ #{text} [#{Cinch::Toolbox.shorten(url)}]"
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
35
60
  end
36
61
  end
37
62
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cinch::Plugins::Wikipedia do
4
+
5
+ before(:all) do
6
+ @plugin = Cinch::Plugins::Wikipedia.new
7
+ end
8
+
9
+ # normal queries
10
+ it 'should return a definition of a term' do
11
+ @plugin.send(:get_def, 'computer').
12
+ should include("A computer is a general purpose device")
13
+ end
14
+
15
+ it 'should not return multiple lined definitions' do
16
+ @plugin.send(:get_def, 'Teenager').
17
+ should_not include("\n")
18
+ end
19
+
20
+ it 'should not return definitions that are longer than 250 chars' do
21
+ @plugin.send(:get_def, 'Teenager').length.
22
+ should == 334
23
+ end
24
+
25
+ # Not found
26
+ it 'should return an error message when a term is not found' do
27
+ @plugin.send(:get_def, 'dasdafasfasfasfasafsdfsdfsadf').
28
+ should include("I couldn't find anything for that search, sorry!")
29
+ end
30
+
31
+ it 'should provide suggestions if one is listed on the page' do
32
+ @plugin.send(:get_def, 'smegama').
33
+ should include("I couldn't find anything for that search, did you mean 'smegma'?")
34
+ end
35
+
36
+ # disambiguation
37
+ it 'should return helful information when a disambuation page' do
38
+ @plugin.send(:get_def, 'hipster').
39
+ should include('is too vague and lead to a disambiguation page')
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
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
11
+
12
+ module Cinch
13
+ module Plugin
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-wikipedia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,17 +9,17 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-02 00:00:00.000000000 Z
12
+ date: 2013-06-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: cinch-toolbox
15
+ name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
- type: :runtime
22
+ type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
@@ -28,14 +28,14 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: cinch-cooldown
31
+ name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
- type: :runtime
38
+ type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
@@ -43,6 +43,70 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: coveralls
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: cinch
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.0.4
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.4
78
+ - !ruby/object:Gem::Dependency
79
+ name: cinch-toolbox
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.0.0
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.0.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: cinch-cooldown
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.0.0
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.0.0
46
110
  description: Cinch plugin that fetches a truncated blurb from the head of a wikipedia
47
111
  page.
48
112
  email:
@@ -52,6 +116,7 @@ extensions: []
52
116
  extra_rdoc_files: []
53
117
  files:
54
118
  - .gitignore
119
+ - .travis.yml
55
120
  - Gemfile
56
121
  - LICENSE.txt
57
122
  - README.md
@@ -60,6 +125,8 @@ files:
60
125
  - lib/cinch-wikipedia.rb
61
126
  - lib/cinch/plugins/wikipedia/version.rb
62
127
  - lib/cinch/plugins/wikipedia/wikipedia.rb
128
+ - spec/cinch-wikipedia_spec.rb
129
+ - spec/spec_helper.rb
63
130
  homepage: https://github.com/bhaberer/cinch-wikipedia
64
131
  licenses: []
65
132
  post_install_message:
@@ -84,4 +151,7 @@ rubygems_version: 1.8.24
84
151
  signing_key:
85
152
  specification_version: 3
86
153
  summary: Cinch Wikipedia Plugin
87
- test_files: []
154
+ test_files:
155
+ - spec/cinch-wikipedia_spec.rb
156
+ - spec/spec_helper.rb
157
+ has_rdoc: