cinch-karma 0.0.1 → 1.0.0
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.
- data/.travis.yml +4 -0
- data/README.md +7 -1
- data/Rakefile +6 -0
- data/cinch-karma.gemspec +8 -3
- data/lib/cinch/plugins/karma/karma.rb +36 -32
- data/lib/cinch/plugins/karma/version.rb +1 -1
- data/spec/cinch-karma_spec.rb +72 -0
- data/spec/spec_helper.rb +4 -0
- metadata +81 -11
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Cinch::Plugins::Karma
|
2
2
|
|
3
|
-
|
3
|
+
[](http://badge.fury.io/rb/cinch-karma)
|
4
|
+
[](https://gemnasium.com/bhaberer/cinch-karma)
|
5
|
+
[](https://travis-ci.org/bhaberer/cinch-karma)
|
6
|
+
[](https://coveralls.io/r/bhaberer/cinch-karma?branch=master)
|
7
|
+
[](https://codeclimate.com/github/bhaberer/cinch-karma)
|
8
|
+
|
9
|
+
Cinch Plugin to track Karma.
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
data/Rakefile
CHANGED
data/cinch-karma.gemspec
CHANGED
@@ -17,7 +17,12 @@ 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.
|
21
|
-
gem.
|
22
|
-
gem.
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_development_dependency 'coveralls'
|
23
|
+
gem.add_development_dependency 'cinch-test'
|
24
|
+
|
25
|
+
gem.add_dependency 'cinch', '~> 2.0.5'
|
26
|
+
gem.add_dependency 'cinch-cooldown', '~> 1.0.0'
|
27
|
+
gem.add_dependency 'cinch-storage', '~> 0.0.2'
|
23
28
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'cinch'
|
1
2
|
require 'cinch-cooldown'
|
2
3
|
require 'cinch-storage'
|
3
4
|
|
@@ -22,47 +23,50 @@ module Cinch::Plugins
|
|
22
23
|
def listen(m)
|
23
24
|
if m.message.match(/\S+[\+\-]{2}/)
|
24
25
|
channel = m.channel.name
|
25
|
-
@storage.data[channel] = Hash.new unless @storage.data.key?(channel)
|
26
|
-
updated = false
|
27
|
-
|
28
|
-
m.message.scan(/.*?((\w+)|\((.+?)\))(\+\+|--)(\s|\z)/).each do |karma|
|
29
|
-
debug "#{karma}"
|
30
|
-
|
31
|
-
if karma[0]
|
32
|
-
item = karma[1] || karma[2]
|
33
|
-
item.downcase!
|
34
|
-
|
35
|
-
@storage.data[channel][item] = 0 unless @storage.data[channel].key?(item)
|
36
|
-
|
37
|
-
if karma[3] == '++'
|
38
|
-
@storage.data[channel][item] += 1
|
39
|
-
updated = true
|
40
|
-
elsif karma[3] == '--'
|
41
|
-
@storage.data[channel][item] -= 1
|
42
|
-
updated = true
|
43
|
-
else
|
44
|
-
debug 'something went wrong matching karma!'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
26
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
27
|
+
# Scan messages for multiple karma items
|
28
|
+
m.message.scan(/(\s|\A)(\w+|\(.+?\))(\+\+|--)(\s|\z)/).each do |karma|
|
29
|
+
process_karma(channel, karma[1].gsub(/\(|\)/, '').downcase, karma[2])
|
53
30
|
end
|
31
|
+
|
32
|
+
@storage.synced_save(@bot)
|
54
33
|
end
|
55
34
|
end
|
56
35
|
|
57
36
|
def execute(m, item)
|
37
|
+
return if sent_via_pm?(m)
|
38
|
+
|
39
|
+
channel = m.channel.name
|
40
|
+
item.downcase!
|
41
|
+
init_karma(channel, item)
|
42
|
+
|
43
|
+
m.reply "Karma for #{item} is #{@storage.data[channel][item]}"
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def process_karma(channel, item, operation)
|
49
|
+
# Ensure the item's Karma has been init
|
50
|
+
init_karma(channel, item)
|
51
|
+
|
52
|
+
case operation
|
53
|
+
when '++'
|
54
|
+
@storage.data[channel][item] += 1
|
55
|
+
when '--'
|
56
|
+
@storage.data[channel][item] -= 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def sent_via_pm?(m)
|
58
61
|
if m.channel.nil?
|
59
|
-
m.
|
60
|
-
return
|
62
|
+
m.reply "You must use that command in the main channel."
|
63
|
+
return true
|
61
64
|
end
|
65
|
+
end
|
62
66
|
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
def init_karma(channel, item = nil)
|
68
|
+
@storage.data[channel] ||= Hash.new
|
69
|
+
@storage.data[channel][item] ||= 0 unless item.nil?
|
66
70
|
end
|
67
71
|
end
|
68
72
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cinch::Plugins::Karma do
|
4
|
+
include Cinch::Test
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@bot = make_bot(Cinch::Plugins::Karma, { :filename => '/dev/null' })
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should default to zero karma' do
|
11
|
+
msg = make_message(@bot, '!karma foo', { :channel => '#foo' })
|
12
|
+
get_replies(msg).first.should == "Karma for foo is 0"
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should allow users to add karma' do
|
16
|
+
msg = make_message(@bot, 'foo++', { :channel => '#foo' })
|
17
|
+
get_replies(msg)
|
18
|
+
msg = make_message(@bot, '!karma foo', { :channel => '#foo' })
|
19
|
+
get_replies(msg).first.should == "Karma for foo is 1"
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should allow users to add karma mid message' do
|
23
|
+
msg = make_message(@bot, 'd asd asdasd foo++ dasdasd sadasd sad', { :channel => '#foo' })
|
24
|
+
get_replies(msg)
|
25
|
+
msg = make_message(@bot, '!karma foo', { :channel => '#foo' })
|
26
|
+
get_replies(msg).first.should == "Karma for foo is 1"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should allow users to add karma with items with spaces via ()' do
|
30
|
+
msg = make_message(@bot, '(foo bar)++', { :channel => '#foo' })
|
31
|
+
get_replies(msg)
|
32
|
+
msg = make_message(@bot, '!karma foo bar', { :channel => '#foo' })
|
33
|
+
get_replies(msg).first.should == "Karma for foo bar is 1"
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should allow users to remove karma' do
|
37
|
+
msg = make_message(@bot, 'foo--', { :channel => '#foo' })
|
38
|
+
get_replies(msg)
|
39
|
+
msg = make_message(@bot, '!karma foo', { :channel => '#foo' })
|
40
|
+
get_replies(msg).first.should == "Karma for foo is -1"
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should allow users to remove karma mid message' do
|
44
|
+
msg = make_message(@bot, 'd asd asdasd foo-- dasdasd sadasd sad', { :channel => '#foo' })
|
45
|
+
get_replies(msg)
|
46
|
+
msg = make_message(@bot, '!karma foo', { :channel => '#foo' })
|
47
|
+
get_replies(msg).first.should == "Karma for foo is -1"
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should allow users to remove karma with items with spaces via ()' do
|
51
|
+
msg = make_message(@bot, '(foo bar)--', { :channel => '#foo' })
|
52
|
+
get_replies(msg)
|
53
|
+
msg = make_message(@bot, '!karma foo bar', { :channel => '#foo' })
|
54
|
+
get_replies(msg).first.should == "Karma for foo bar is -1"
|
55
|
+
end
|
56
|
+
it 'should not allow users to check karam via pm' do
|
57
|
+
msg = make_message(@bot, '!karma foo')
|
58
|
+
get_replies(msg).first.should == "You must use that command in the main channel."
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should not allow users to add karma via pm' do
|
62
|
+
msg = make_message(@bot, 'foo++')
|
63
|
+
msg = make_message(@bot, '!karma foo', { :channel => '#foo' })
|
64
|
+
get_replies(msg).first.should == "Karma for foo is 0"
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should not allow users to remove karma via pm' do
|
68
|
+
msg = make_message(@bot, 'foo--')
|
69
|
+
msg = make_message(@bot, '!karma foo', { :channel => '#foo' })
|
70
|
+
get_replies(msg).first.should == "Karma for foo is 0"
|
71
|
+
end
|
72
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-karma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,33 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
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
|
-
version:
|
22
|
-
type: :
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
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: :
|
38
|
+
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: coveralls
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
|
-
type: :
|
54
|
+
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
@@ -59,6 +59,70 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: cinch-test
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: cinch
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.0.5
|
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: 2.0.5
|
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
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: cinch-storage
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.0.2
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 0.0.2
|
62
126
|
description: Cinch Plugin to track karma (item++ / item--) in the channel
|
63
127
|
email:
|
64
128
|
- bhaberer@gmail.com
|
@@ -67,6 +131,7 @@ extensions: []
|
|
67
131
|
extra_rdoc_files: []
|
68
132
|
files:
|
69
133
|
- .gitignore
|
134
|
+
- .travis.yml
|
70
135
|
- Gemfile
|
71
136
|
- LICENSE.txt
|
72
137
|
- README.md
|
@@ -75,6 +140,8 @@ files:
|
|
75
140
|
- lib/cinch-karma.rb
|
76
141
|
- lib/cinch/plugins/karma/karma.rb
|
77
142
|
- lib/cinch/plugins/karma/version.rb
|
143
|
+
- spec/cinch-karma_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
78
145
|
homepage: https://github.com/bhaberer/cinch-karma
|
79
146
|
licenses: []
|
80
147
|
post_install_message:
|
@@ -99,4 +166,7 @@ rubygems_version: 1.8.24
|
|
99
166
|
signing_key:
|
100
167
|
specification_version: 3
|
101
168
|
summary: Cinch Plugin to Track Karma
|
102
|
-
test_files:
|
169
|
+
test_files:
|
170
|
+
- spec/cinch-karma_spec.rb
|
171
|
+
- spec/spec_helper.rb
|
172
|
+
has_rdoc:
|