cinch-magic 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +20 -1
- data/cinch-magic.gemspec +11 -14
- data/lib/cinch/plugins/magic.rb +89 -87
- data/lib/cinch/plugins/magic/version.rb +1 -1
- data/spec/cinch-magic_spec.rb +4 -4
- metadata +39 -44
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: 376e98bc2aabf615ae71b5b283899bb4787c7bf1
|
4
|
+
data.tar.gz: bdd655ceed8614fb0346b741e6607cd74716c7ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f415955882480f34f1f73b1a414b4d46e2e0227683f9b16302d3e07c182ce872150af2629a73538bfab68da2473753197dbf7ac74f6002a3f4acf2dbed1f6fe2
|
7
|
+
data.tar.gz: a5f190e08e3ed39c91712597e7727f04f067006f889ffc21bdf0d20bdc02e283b4d5f48bd2263d66a1830fcc4f21906b4581fc45731c3c2f42592c564186778b
|
data/.travis.yml
CHANGED
@@ -1,4 +1,23 @@
|
|
1
1
|
language: ruby
|
2
|
+
env:
|
3
|
+
global:
|
4
|
+
- "JRUBY_OPTS=-Xcext.enabled=true"
|
2
5
|
rvm:
|
3
|
-
- 1.
|
6
|
+
- 2.1.0
|
7
|
+
- 2.0.0
|
4
8
|
- 1.9.3
|
9
|
+
- 1.9.2
|
10
|
+
- 1.8.7
|
11
|
+
- jruby-18mode
|
12
|
+
- jruby-19mode
|
13
|
+
- ruby-head
|
14
|
+
- jruby-head
|
15
|
+
- ree
|
16
|
+
matrix:
|
17
|
+
allow_failures:
|
18
|
+
- rvm: 1.8.7
|
19
|
+
- rvm: ree
|
20
|
+
- rvm: jruby-18mode
|
21
|
+
- rvm: jruby-19mode
|
22
|
+
- rvm: jruby-head
|
23
|
+
fast_finish: true
|
data/cinch-magic.gemspec
CHANGED
@@ -8,22 +8,19 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Cinch::Plugins::Magic::VERSION
|
9
9
|
gem.authors = ['Brian Haberer']
|
10
10
|
gem.email = ['bhaberer@gmail.com']
|
11
|
-
gem.description = %q
|
12
|
-
gem.summary = %q
|
11
|
+
gem.description = %q(Cinch Plugin that searches http://magiccards.info/ for card information.)
|
12
|
+
gem.summary = %q(Cinch Plugin for Magic Cards)
|
13
13
|
gem.homepage = 'https://github.com/bhaberer/cinch-magic'
|
14
14
|
gem.license = 'MIT'
|
15
|
-
|
16
15
|
gem.files = `git ls-files`.split($/)
|
17
|
-
gem.executables = gem.files.grep(
|
18
|
-
gem.test_files = gem.files.grep(
|
16
|
+
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
19
18
|
gem.require_paths = ['lib']
|
20
|
-
|
21
|
-
gem.add_development_dependency
|
22
|
-
gem.add_development_dependency
|
23
|
-
gem.add_development_dependency
|
24
|
-
gem.
|
25
|
-
|
26
|
-
gem.add_dependency
|
27
|
-
gem.add_dependency 'cinch-toolbox', '~> 1.1.0'
|
28
|
-
gem.add_dependency 'cinch-cooldown', '~> 1.1.1'
|
19
|
+
gem.add_development_dependency 'rake', '~> 10'
|
20
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
21
|
+
gem.add_development_dependency 'coveralls', '~> 0.7'
|
22
|
+
gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.1'
|
23
|
+
gem.add_dependency 'cinch', '~> 2'
|
24
|
+
gem.add_dependency 'cinch-cooldown', '~> 1.1', '>= 1.1.1'
|
25
|
+
gem.add_dependency 'cinch-toolbox', '~> 1.1'
|
29
26
|
end
|
data/lib/cinch/plugins/magic.rb
CHANGED
@@ -3,93 +3,95 @@ require 'cinch'
|
|
3
3
|
require 'cinch/toolbox'
|
4
4
|
require 'cinch/cooldown'
|
5
5
|
|
6
|
-
module Cinch
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
m
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
6
|
+
module Cinch
|
7
|
+
module Plugins
|
8
|
+
# Cinch Plugin to looking MTG cards
|
9
|
+
class Magic
|
10
|
+
include Cinch::Plugin
|
11
|
+
|
12
|
+
enforce_cooldown
|
13
|
+
|
14
|
+
self.help = 'Use .mtg <card name> to see the info for that card.'
|
15
|
+
|
16
|
+
match(/mtg (.*)/)
|
17
|
+
|
18
|
+
def execute(m, term)
|
19
|
+
m.reply get_card(term)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def get_card(term)
|
25
|
+
# Fetch the html for the search term
|
26
|
+
data = card_data(term)
|
27
|
+
|
28
|
+
# Catch nil responses.
|
29
|
+
return '[Magic] Card not found, or problem fetching page.' if data.nil?
|
30
|
+
|
31
|
+
# Build card string
|
32
|
+
card = "#{card_name(data)} [#{card_info(data)}] - #{card_text(data)}"
|
33
|
+
|
34
|
+
# Truncate if it's super long
|
35
|
+
card = Cinch::Toolbox.truncate(card, 300)
|
36
|
+
|
37
|
+
"[Magic] #{card} [#{card_link(data)}]"
|
38
|
+
end
|
39
|
+
|
40
|
+
def card_info(data)
|
41
|
+
text = data[/<p[^>]*>([^<]+)<\/p>/, 1]
|
42
|
+
|
43
|
+
# Replace Newlines, unicode lines, total mana, and large spaces.
|
44
|
+
text = text.gsub(/\n/, '')
|
45
|
+
text = text.gsub(/\s—/, ', ')
|
46
|
+
text = text.gsub(/\s\(\d*\)/, '')
|
47
|
+
text = text.gsub(/\s{2,}/, ' ')
|
48
|
+
|
49
|
+
# Remove pesky whitespace that might have snuck in...
|
50
|
+
text.strip!
|
51
|
+
|
52
|
+
text
|
53
|
+
rescue
|
54
|
+
debug 'Error getting the card info'
|
55
|
+
return ''
|
56
|
+
end
|
57
|
+
|
58
|
+
def card_name(data)
|
59
|
+
data[/<a href=[^>]*>([^<]+)<\/a>/, 1]
|
60
|
+
rescue
|
61
|
+
debug 'Error finding the card name'
|
62
|
+
return ''
|
63
|
+
end
|
64
|
+
|
65
|
+
def card_link(data)
|
66
|
+
"http://magiccards.info#{data[/<a href="([^>]*)">[^<]+<\/a>/, 1]}"
|
67
|
+
rescue
|
68
|
+
debug 'Error finding the card url'
|
69
|
+
return ''
|
70
|
+
end
|
71
|
+
|
72
|
+
def card_text(data)
|
73
|
+
data[%r{<p class="ctext"><b[^>]*>(.+)</b></p>}, 1].gsub(/<br><br>/, ' ')
|
74
|
+
rescue
|
75
|
+
debug 'Error finding the card description'
|
76
|
+
return ''
|
77
|
+
end
|
78
|
+
|
79
|
+
def card_data(term)
|
80
|
+
# URI Encode the term and build the URL
|
81
|
+
term = URI.escape("!#{term}",
|
82
|
+
Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
83
|
+
url = "http://magiccards.info/query?q=#{term}"
|
84
|
+
|
85
|
+
# Make sure the URL is legit
|
86
|
+
url = URI.extract(url, %w(http https)).first
|
87
|
+
|
88
|
+
# Grab the html block because magiccards.info fucking loves tables
|
89
|
+
# and hates helpful ids and classnames
|
90
|
+
Cinch::Toolbox.get_html_element(url, '//table[3]/tr/td[2]', :xpath_full)
|
91
|
+
rescue
|
92
|
+
debug "Error looking up card: #{term}"
|
93
|
+
return
|
94
|
+
end
|
93
95
|
end
|
94
96
|
end
|
95
97
|
end
|
data/spec/cinch-magic_spec.rb
CHANGED
@@ -9,12 +9,12 @@ describe Cinch::Plugins::Magic do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should allow users to lookup cards' do
|
12
|
-
get_replies(make_message(@bot, '!mtg forest')).first
|
13
|
-
|
12
|
+
msg = get_replies(make_message(@bot, '!mtg forest')).first
|
13
|
+
expect(msg.text).to include('[Magic] Forest [Basic Land, Forest] - ({T}: Add {G} to your mana pool.)')
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should return an error when a card is not found' do
|
17
|
-
get_replies(make_message(@bot, '!mtg random string that is probably not a real card')).first
|
18
|
-
|
17
|
+
msg = get_replies(make_message(@bot, '!mtg random string that is probably not a real card')).first
|
18
|
+
expect(msg.text).to eq('[Magic] Card not found, or problem fetching page.')
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,128 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brian Haberer
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-08-01 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: '10'
|
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: '10'
|
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
42
|
name: coveralls
|
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.7'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
54
|
+
version: '0.7'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: cinch-test
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.1'
|
67
62
|
- - ! '>='
|
68
63
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
64
|
+
version: 0.1.1
|
70
65
|
type: :development
|
71
66
|
prerelease: false
|
72
67
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
68
|
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0.1'
|
75
72
|
- - ! '>='
|
76
73
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
74
|
+
version: 0.1.1
|
78
75
|
- !ruby/object:Gem::Dependency
|
79
76
|
name: cinch
|
80
77
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
78
|
requirements:
|
83
79
|
- - ~>
|
84
80
|
- !ruby/object:Gem::Version
|
85
|
-
version: 2
|
81
|
+
version: '2'
|
86
82
|
type: :runtime
|
87
83
|
prerelease: false
|
88
84
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
85
|
requirements:
|
91
86
|
- - ~>
|
92
87
|
- !ruby/object:Gem::Version
|
93
|
-
version: 2
|
88
|
+
version: '2'
|
94
89
|
- !ruby/object:Gem::Dependency
|
95
|
-
name: cinch-
|
90
|
+
name: cinch-cooldown
|
96
91
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
92
|
requirements:
|
99
93
|
- - ~>
|
100
94
|
- !ruby/object:Gem::Version
|
101
|
-
version: 1.1
|
95
|
+
version: '1.1'
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.1.1
|
102
99
|
type: :runtime
|
103
100
|
prerelease: false
|
104
101
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
102
|
requirements:
|
107
103
|
- - ~>
|
108
104
|
- !ruby/object:Gem::Version
|
109
|
-
version: 1.1
|
105
|
+
version: '1.1'
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 1.1.1
|
110
109
|
- !ruby/object:Gem::Dependency
|
111
|
-
name: cinch-
|
110
|
+
name: cinch-toolbox
|
112
111
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
112
|
requirements:
|
115
113
|
- - ~>
|
116
114
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.1
|
115
|
+
version: '1.1'
|
118
116
|
type: :runtime
|
119
117
|
prerelease: false
|
120
118
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
119
|
requirements:
|
123
120
|
- - ~>
|
124
121
|
- !ruby/object:Gem::Version
|
125
|
-
version: 1.1
|
122
|
+
version: '1.1'
|
126
123
|
description: Cinch Plugin that searches http://magiccards.info/ for card information.
|
127
124
|
email:
|
128
125
|
- bhaberer@gmail.com
|
@@ -145,29 +142,27 @@ files:
|
|
145
142
|
homepage: https://github.com/bhaberer/cinch-magic
|
146
143
|
licenses:
|
147
144
|
- MIT
|
145
|
+
metadata: {}
|
148
146
|
post_install_message:
|
149
147
|
rdoc_options: []
|
150
148
|
require_paths:
|
151
149
|
- lib
|
152
150
|
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
151
|
requirements:
|
155
152
|
- - ! '>='
|
156
153
|
- !ruby/object:Gem::Version
|
157
154
|
version: '0'
|
158
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
-
none: false
|
160
156
|
requirements:
|
161
157
|
- - ! '>='
|
162
158
|
- !ruby/object:Gem::Version
|
163
159
|
version: '0'
|
164
160
|
requirements: []
|
165
161
|
rubyforge_project:
|
166
|
-
rubygems_version:
|
162
|
+
rubygems_version: 2.2.2
|
167
163
|
signing_key:
|
168
|
-
specification_version:
|
164
|
+
specification_version: 4
|
169
165
|
summary: Cinch Plugin for Magic Cards
|
170
166
|
test_files:
|
171
167
|
- spec/cinch-magic_spec.rb
|
172
168
|
- spec/spec_helper.rb
|
173
|
-
has_rdoc:
|