cinch-karma 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-karma.gemspec +11 -12
- data/lib/cinch/plugins/karma.rb +43 -44
- data/lib/cinch/plugins/karma/version.rb +1 -1
- data/spec/cinch-karma_spec.rb +36 -26
- data/spec/spec_helper.rb +1 -0
- metadata +37 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: 85e1c22bb5600f38351ca7961c075ae56b3e5bd3
|
4
|
+
data.tar.gz: aa6e10363e33dc70e45df5b1db8e2bda64103a42
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44e85ba6839c0a853b8ce4436293278d3109962f6757a661607e69eb1b2529f7f8778561beb723abf870d0cfc5336f87e5db71096d98a3fe8d2b73637b463940
|
7
|
+
data.tar.gz: 7a1ba7a20611dca1e7273c17e8a40172cecce3ae77e4f9f8a0011dda162b2a5314319e628ca4f8330d49464ffb8890fe0e9ed90eac937c7159751225d58f3734
|
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-karma.gemspec
CHANGED
@@ -8,22 +8,21 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Cinch::Plugins::Karma::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 to track karma (item++ / item--) in the channel)
|
12
|
+
gem.summary = %q(Cinch Plugin to Track Karma)
|
13
13
|
gem.homepage = 'https://github.com/bhaberer/cinch-karma'
|
14
14
|
gem.license = 'MIT'
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($/)
|
17
|
-
gem.executables = gem.files.grep(
|
18
|
-
gem.test_files = gem.files.grep(
|
17
|
+
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
19
19
|
gem.require_paths = ['lib']
|
20
20
|
|
21
|
-
gem.add_development_dependency
|
22
|
-
gem.add_development_dependency
|
23
|
-
gem.add_development_dependency
|
24
|
-
gem.add_development_dependency
|
25
|
-
|
26
|
-
gem.add_dependency
|
27
|
-
gem.add_dependency
|
28
|
-
gem.add_dependency 'cinch-storage', '~> 1.1.0'
|
21
|
+
gem.add_development_dependency 'rake', '~> 10'
|
22
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
23
|
+
gem.add_development_dependency 'coveralls', '~> 0.7'
|
24
|
+
gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.0'
|
25
|
+
gem.add_dependency 'cinch', '~> 2'
|
26
|
+
gem.add_dependency 'cinch-cooldown', '~> 1.1', '>= 1.1.3'
|
27
|
+
gem.add_dependency 'cinch-storage', '~> 1.1'
|
29
28
|
end
|
data/lib/cinch/plugins/karma.rb
CHANGED
@@ -3,74 +3,73 @@ require 'cinch'
|
|
3
3
|
require 'cinch/cooldown'
|
4
4
|
require 'cinch/storage'
|
5
5
|
|
6
|
-
module Cinch
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
module Cinch
|
7
|
+
module Plugins
|
8
|
+
# Cinch Plugin to monitor karma and report.
|
9
|
+
class Karma
|
10
|
+
include Cinch::Plugin
|
10
11
|
|
11
|
-
|
12
|
+
enforce_cooldown
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
self.help = 'Use .karma <item> to see it\'s karma level. You can use ' \
|
15
|
+
'<item>++ or <item>-- [or (something with spaces)++] to ' \
|
16
|
+
'alter karma for an item'
|
16
17
|
|
17
|
-
|
18
|
+
listen_to :channel
|
18
19
|
|
19
|
-
|
20
|
-
match /k (.+)/
|
20
|
+
match(/(?:k|karma) (.+)/)
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def initialize(*args)
|
23
|
+
super
|
24
|
+
@storage = Cinch::Storage.new(config[:filename] || 'yaml/karma.yml')
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
def listen(m)
|
28
|
+
return unless m.message.match(/\S+[\+\-]{2}/)
|
29
29
|
channel = m.channel.name
|
30
30
|
|
31
31
|
# Scan messages for multiple karma items
|
32
|
-
m.message.scan(/(\s|\A)(\w+|\(.+?\))(\+\+|--)(\s|\z)/).each do |
|
33
|
-
process_karma(channel,
|
32
|
+
m.message.scan(/(\s|\A)(\w+|\(.+?\))(\+\+|--)(\s|\z)/).each do |k|
|
33
|
+
process_karma(channel, k[1].gsub(/\(|\)/, '').downcase, k[2])
|
34
34
|
end
|
35
35
|
|
36
36
|
@storage.synced_save(@bot)
|
37
37
|
end
|
38
|
-
end
|
39
38
|
|
40
|
-
|
41
|
-
|
39
|
+
def execute(m, item)
|
40
|
+
return if sent_via_pm?(m)
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
channel = m.channel.name
|
43
|
+
item.downcase!
|
44
|
+
init_karma(channel, item)
|
46
45
|
|
47
|
-
|
48
|
-
|
46
|
+
m.reply "Karma for #{item} is #{@storage.data[channel][item]}"
|
47
|
+
end
|
49
48
|
|
50
|
-
|
49
|
+
private
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
def process_karma(channel, item, operation)
|
52
|
+
# Ensure the item's Karma has been init
|
53
|
+
init_karma(channel, item)
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
case operation
|
56
|
+
when '++'
|
57
|
+
@storage.data[channel][item] += 1
|
58
|
+
when '--'
|
59
|
+
@storage.data[channel][item] -= 1
|
60
|
+
end
|
61
61
|
end
|
62
|
-
end
|
63
62
|
|
64
|
-
|
65
|
-
|
63
|
+
def sent_via_pm?(m)
|
64
|
+
return false unless m.channel.nil?
|
66
65
|
m.reply 'You must use that command in the main channel.'
|
67
|
-
|
66
|
+
true
|
68
67
|
end
|
69
|
-
end
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
def init_karma(channel, item = nil)
|
70
|
+
@storage.data[channel] ||= {}
|
71
|
+
@storage.data[channel][item] ||= 0 unless item.nil?
|
72
|
+
end
|
74
73
|
end
|
75
74
|
end
|
76
75
|
end
|
data/spec/cinch-karma_spec.rb
CHANGED
@@ -4,69 +4,79 @@ describe Cinch::Plugins::Karma do
|
|
4
4
|
include Cinch::Test
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
-
@bot = make_bot(Cinch::Plugins::Karma, { :
|
7
|
+
@bot = make_bot(Cinch::Plugins::Karma, { filename: '/dev/null' })
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should default to zero karma' do
|
11
|
-
msg = make_message(@bot, '!karma foo', { :
|
12
|
-
get_replies(msg).first.text
|
11
|
+
msg = make_message(@bot, '!karma foo', { channel: '#foo' })
|
12
|
+
expect(get_replies(msg).first.text)
|
13
|
+
.to eq('Karma for foo is 0')
|
13
14
|
end
|
14
15
|
|
15
16
|
it 'should allow users to add karma' do
|
16
|
-
msg = make_message(@bot, 'foo++', { :
|
17
|
+
msg = make_message(@bot, 'foo++', { channel: '#foo' })
|
17
18
|
get_replies(msg)
|
18
|
-
msg = make_message(@bot, '!karma foo', { :
|
19
|
-
get_replies(msg).first.text
|
19
|
+
msg = make_message(@bot, '!karma foo', { channel: '#foo' })
|
20
|
+
expect(get_replies(msg).first.text)
|
21
|
+
.to eq('Karma for foo is 1')
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'should allow users to add karma mid message' do
|
23
|
-
msg = make_message(@bot, 'd asd asdasd foo++ dasdasd sadasd sad', { :
|
25
|
+
msg = make_message(@bot, 'd asd asdasd foo++ dasdasd sadasd sad', { channel: '#foo' })
|
24
26
|
get_replies(msg)
|
25
|
-
msg = make_message(@bot, '!karma foo', { :
|
26
|
-
get_replies(msg).first.text
|
27
|
+
msg = make_message(@bot, '!karma foo', { channel: '#foo' })
|
28
|
+
expect(get_replies(msg).first.text)
|
29
|
+
.to eq('Karma for foo is 1')
|
27
30
|
end
|
28
31
|
|
29
32
|
it 'should allow users to add karma with items with spaces via ()' do
|
30
|
-
msg = make_message(@bot, '(foo bar)++', { :
|
33
|
+
msg = make_message(@bot, '(foo bar)++', { channel: '#foo' })
|
31
34
|
get_replies(msg)
|
32
|
-
msg = make_message(@bot, '!karma foo bar', { :
|
33
|
-
get_replies(msg).first.text
|
35
|
+
msg = make_message(@bot, '!karma foo bar', { channel: '#foo' })
|
36
|
+
expect(get_replies(msg).first.text)
|
37
|
+
.to eq('Karma for foo bar is 1')
|
34
38
|
end
|
35
39
|
|
36
40
|
it 'should allow users to remove karma' do
|
37
|
-
msg = make_message(@bot, 'foo--', { :
|
41
|
+
msg = make_message(@bot, 'foo--', { channel: '#foo' })
|
38
42
|
get_replies(msg)
|
39
|
-
msg = make_message(@bot, '!karma foo', { :
|
40
|
-
get_replies(msg).first.text
|
43
|
+
msg = make_message(@bot, '!karma foo', { channel: '#foo' })
|
44
|
+
expect(get_replies(msg).first.text)
|
45
|
+
.to eq('Karma for foo is -1')
|
41
46
|
end
|
42
47
|
|
43
48
|
it 'should allow users to remove karma mid message' do
|
44
|
-
msg = make_message(@bot, 'd asd asdasd foo-- dasdasd sadasd sad', { :
|
49
|
+
msg = make_message(@bot, 'd asd asdasd foo-- dasdasd sadasd sad', { channel: '#foo' })
|
45
50
|
get_replies(msg)
|
46
|
-
msg = make_message(@bot, '!karma foo', { :
|
47
|
-
get_replies(msg).first.text
|
51
|
+
msg = make_message(@bot, '!karma foo', { channel: '#foo' })
|
52
|
+
expect(get_replies(msg).first.text)
|
53
|
+
.to eq('Karma for foo is -1')
|
48
54
|
end
|
49
55
|
|
50
56
|
it 'should allow users to remove karma with items with spaces via ()' do
|
51
|
-
msg = make_message(@bot, '(foo bar)--', { :
|
57
|
+
msg = make_message(@bot, '(foo bar)--', { channel: '#foo' })
|
52
58
|
get_replies(msg)
|
53
|
-
msg = make_message(@bot, '!karma foo bar', { :
|
54
|
-
get_replies(msg).first.text
|
59
|
+
msg = make_message(@bot, '!karma foo bar', { channel: '#foo' })
|
60
|
+
expect(get_replies(msg).first.text)
|
61
|
+
.to eq('Karma for foo bar is -1')
|
55
62
|
end
|
56
63
|
it 'should not allow users to check karam via pm' do
|
57
64
|
msg = make_message(@bot, '!karma foo')
|
58
|
-
get_replies(msg).first.text
|
65
|
+
expect(get_replies(msg).first.text)
|
66
|
+
.to eq('You must use that command in the main channel.')
|
59
67
|
end
|
60
68
|
|
61
69
|
it 'should not allow users to add karma via pm' do
|
62
70
|
msg = make_message(@bot, 'foo++')
|
63
|
-
msg = make_message(@bot, '!karma foo', { :
|
64
|
-
get_replies(msg).first.text
|
71
|
+
msg = make_message(@bot, '!karma foo', { channel: '#foo' })
|
72
|
+
expect(get_replies(msg).first.text)
|
73
|
+
.to eq('Karma for foo is 0')
|
65
74
|
end
|
66
75
|
|
67
76
|
it 'should not allow users to remove karma via pm' do
|
68
77
|
msg = make_message(@bot, 'foo--')
|
69
|
-
msg = make_message(@bot, '!karma foo', { :
|
70
|
-
get_replies(msg).first.text
|
78
|
+
msg = make_message(@bot, '!karma foo', { channel: '#foo' })
|
79
|
+
expect(get_replies(msg).first.text)
|
80
|
+
.to eq('Karma for foo is 0')
|
71
81
|
end
|
72
82
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,128 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-karma
|
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-07-31 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.0
|
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.0
|
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
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.3
|
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.3
|
110
109
|
- !ruby/object:Gem::Dependency
|
111
110
|
name: cinch-storage
|
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 to track karma (item++ / item--) in the channel
|
127
124
|
email:
|
128
125
|
- bhaberer@gmail.com
|
@@ -145,29 +142,27 @@ files:
|
|
145
142
|
homepage: https://github.com/bhaberer/cinch-karma
|
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 to Track Karma
|
170
166
|
test_files:
|
171
167
|
- spec/cinch-karma_spec.rb
|
172
168
|
- spec/spec_helper.rb
|
173
|
-
has_rdoc:
|