lita-onewheel-karma 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +10 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +31 -0
- data/Rakefile +6 -0
- data/lib/lita-onewheel-karma.rb +12 -0
- data/lib/lita/handlers/onewheel_karma.rb +74 -0
- data/lita-onewheel-karma.gemspec +26 -0
- data/locales/en.yml +4 -0
- data/spec/lita/handlers/onewheel_karma_spec.rb +118 -0
- data/spec/spec_helper.rb +14 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8bc8d88dbb150a6b5c52cfe9c2612c061d5a1ef3
|
4
|
+
data.tar.gz: d51a298e99784b1f279302ec4a714edf0b035caf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 789bf77cad108c1caea736199ebf807a7d46dd95a28b60331d1a56c285c74500280944b2c7efc217b09aa951f410375583a4d4f5de7f60451db7eaf584a2cda2
|
7
|
+
data.tar.gz: 6cd8707b45cbd6ed5469677c74dfe9a5945b44a669689ea27d5a0fc8f2f4f3cf388449bf9f1c81bd6fe875a29e401cf7ade91d48362ca42505365ccd072041f0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Andrew Kreps
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# lita-onewheel-karma
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/onewheelskyward/lita-onewheel-karma.png?branch=master)](https://travis-ci.org/onewheelskyward/lita-onewheel-karma)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/onewheelskyward/lita-onewheel-karma/badge.png)](https://coveralls.io/r/onewheelskyward/lita-onewheel-karma)
|
5
|
+
|
6
|
+
Karma should be opinionated, and unlimited.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add lita-onewheel-karma to your Lita instance's Gemfile:
|
11
|
+
|
12
|
+
``` ruby
|
13
|
+
gem "lita-onewheel-karma"
|
14
|
+
```
|
15
|
+
|
16
|
+
## Configuration
|
17
|
+
|
18
|
+
n/a at this moment. I might customize messaging at some point.
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Here are a few of the ways you can add/remove/multiply karma:
|
23
|
+
|
24
|
+
nick++
|
25
|
+
nick--
|
26
|
+
nick+=\d+
|
27
|
+
nick-=\d+
|
28
|
+
nick*=\d+
|
29
|
+
|
30
|
+
and negative karma will be expressed with poo emoji and perhaps roman numerals.
|
31
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'lita'
|
2
|
+
|
3
|
+
Lita.load_locales Dir[File.expand_path(
|
4
|
+
File.join('..', '..', 'locales', '*.yml'), __FILE__
|
5
|
+
)]
|
6
|
+
|
7
|
+
require 'lita/handlers/onewheel_karma'
|
8
|
+
|
9
|
+
Lita::Handlers::OnewheelKarma.template_root File.expand_path(
|
10
|
+
File.join('..', '..', 'templates'),
|
11
|
+
__FILE__
|
12
|
+
)
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Lita
|
2
|
+
module Handlers
|
3
|
+
class OnewheelKarma < Handler
|
4
|
+
route /([^\s]+)\s*\+\+(\s|$)/, :add_one_karma,
|
5
|
+
help: 'object++: Add one karma to [object].'
|
6
|
+
route /([^\s]+)\s*--(\s|$)/, :remove_one_karma,
|
7
|
+
help: 'object++: Remove one karma from [object].'
|
8
|
+
route /([^\s]+)\s*\*=\s*([-\d]+)/, :multiply_karma,
|
9
|
+
help: 'object*=n: Multiply karma by n'
|
10
|
+
route /([^\s]+)\s*\+=\s*([-\d]+)/, :add_arbitrary_karma,
|
11
|
+
help: 'object+=n: Add n karma to [object].'
|
12
|
+
route /([^\s]+)\s*-=\s*([-\d]+)/, :remove_arbitrary_karma,
|
13
|
+
help: 'object+=n: Remove n karma from [object].'
|
14
|
+
|
15
|
+
def add_one_karma(response)
|
16
|
+
karma_object = response.matches[0][0]
|
17
|
+
karma = find_and_set_karma(karma_object)
|
18
|
+
response.reply reply_with_karma(karma_object, karma)
|
19
|
+
end
|
20
|
+
|
21
|
+
def remove_one_karma(response)
|
22
|
+
karma_object = response.matches[0][0]
|
23
|
+
karma = find_and_set_karma(karma_object, -1)
|
24
|
+
response.reply reply_with_karma(karma_object, karma)
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_arbitrary_karma(response)
|
28
|
+
karma_object = response.matches[0][0]
|
29
|
+
increment_value = response.matches[0][1].to_i
|
30
|
+
karma = find_and_set_karma(karma_object, increment_value)
|
31
|
+
response.reply reply_with_karma(karma_object, karma)
|
32
|
+
end
|
33
|
+
|
34
|
+
def remove_arbitrary_karma(response)
|
35
|
+
karma_object = response.matches[0][0]
|
36
|
+
increment_value = response.matches[0][1].to_i * -1 # -= means we negate the increment_value. - -9 = + 9
|
37
|
+
karma = find_and_set_karma(karma_object, increment_value)
|
38
|
+
response.reply reply_with_karma(karma_object, karma)
|
39
|
+
end
|
40
|
+
|
41
|
+
def multiply_karma(response)
|
42
|
+
karma_object = response.matches[0][0]
|
43
|
+
multiplier = response.matches[0][1]
|
44
|
+
karma = find_and_set_karma(karma_object, multiplier, true)
|
45
|
+
response.reply reply_with_karma(karma_object, karma)
|
46
|
+
end
|
47
|
+
|
48
|
+
def reply_with_karma(karma_object, karma)
|
49
|
+
if karma >= 0
|
50
|
+
"#{karma_object} has #{karma} karma!"
|
51
|
+
else
|
52
|
+
"#{karma_object} has -💩 karma!"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Find the karma object from redis and increment appropriately.
|
57
|
+
def find_and_set_karma(karma_object, increment_value = 1, multiply = false)
|
58
|
+
karma = redis.get(karma_object).to_i
|
59
|
+
|
60
|
+
if multiply
|
61
|
+
karma *= increment_value.to_i
|
62
|
+
else
|
63
|
+
karma += increment_value
|
64
|
+
end
|
65
|
+
|
66
|
+
redis.set(karma_object, karma)
|
67
|
+
karma
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
Lita.register_handler(OnewheelKarma)
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'lita-onewheel-karma'
|
3
|
+
spec.version = '0.0.0'
|
4
|
+
spec.authors = ['Andrew Kreps']
|
5
|
+
spec.email = ['andrew.kreps@gmail.com']
|
6
|
+
spec.description = 'Karma with a maths-focused twist.'
|
7
|
+
spec.summary = "Karma shouldn't be bound by simple increment and decrement operations."
|
8
|
+
spec.homepage = 'https://github.com/onewheelskyward/lita-onewheel-karma'
|
9
|
+
spec.license = 'MIT'
|
10
|
+
spec.metadata = { 'lita_plugin_type' => 'handler' }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
|
17
|
+
spec.add_runtime_dependency 'lita', '~> 4.4'
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
20
|
+
# spec.add_development_dependency 'pry-byebug' # I go inline.
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
22
|
+
spec.add_development_dependency 'rack-test', '~> 0.6'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
|
+
spec.add_development_dependency 'simplecov', '~> 0.10'
|
25
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
26
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lita::Handlers::OnewheelKarma, lita_handler: true do
|
4
|
+
NEGATIVE_MESSAGE = 'a has -💩 karma!'
|
5
|
+
|
6
|
+
it 'will add one karma' do
|
7
|
+
send_message 'a++'
|
8
|
+
expect(replies.last).to eq 'a has 1 karma!'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'will add two karma' do
|
12
|
+
send_message 'a++'
|
13
|
+
send_message 'a++'
|
14
|
+
expect(replies.last).to eq 'a has 2 karma!'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'will remove one karma' do
|
18
|
+
send_message 'a--'
|
19
|
+
expect(replies.last).to eq NEGATIVE_MESSAGE
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'will remove lotsa karma' do
|
23
|
+
send_message 'a--'
|
24
|
+
send_message 'a--'
|
25
|
+
send_message 'a--'
|
26
|
+
send_message 'a--'
|
27
|
+
send_message 'a--'
|
28
|
+
send_message 'a--'
|
29
|
+
expect(replies.last).to eq NEGATIVE_MESSAGE
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'will multiply one karma' do
|
33
|
+
send_message 'a++'
|
34
|
+
send_message 'a*=2'
|
35
|
+
expect(replies.last).to eq 'a has 2 karma!'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'will multiply many karma' do
|
39
|
+
send_message 'a++'
|
40
|
+
send_message 'a++'
|
41
|
+
send_message 'a++'
|
42
|
+
send_message 'a++'
|
43
|
+
send_message 'a++'
|
44
|
+
send_message 'a*=5'
|
45
|
+
expect(replies.last).to eq 'a has 25 karma!'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'will multiply many negative karma' do
|
49
|
+
send_message 'a--'
|
50
|
+
send_message 'a--'
|
51
|
+
send_message 'a--'
|
52
|
+
send_message 'a--'
|
53
|
+
send_message 'a--'
|
54
|
+
send_message 'a*=5'
|
55
|
+
# -25
|
56
|
+
expect(replies.last).to eq NEGATIVE_MESSAGE
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'will add arbitrary karma' do
|
60
|
+
send_message 'a+=9'
|
61
|
+
expect(replies.last).to eq 'a has 9 karma!'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'will add negative arbitrary karma' do
|
65
|
+
send_message 'a+=-9'
|
66
|
+
expect(replies.last).to eq NEGATIVE_MESSAGE
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'will subtract arbitrary karma' do
|
70
|
+
send_message 'a-=9'
|
71
|
+
expect(replies.last).to eq NEGATIVE_MESSAGE
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'will subtract negative arbitrary karma' do
|
75
|
+
send_message 'a-=-9'
|
76
|
+
expect(replies.last).to eq 'a has 9 karma!'
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'will spacing' do
|
80
|
+
send_message 'a -= -9'
|
81
|
+
expect(replies.last).to eq 'a has 9 karma!'
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'will spacing 2' do
|
85
|
+
send_message 'a += -9'
|
86
|
+
expect(replies.last).to eq NEGATIVE_MESSAGE
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'will spacing 3' do
|
90
|
+
send_message 'a ++'
|
91
|
+
expect(replies.last).to eq 'a has 1 karma!'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'will spacing 4' do
|
95
|
+
send_message 'a --'
|
96
|
+
expect(replies.last).to eq NEGATIVE_MESSAGE
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'uri tests' do
|
100
|
+
send_message 'http://www.oregonlive.com/history/2015/07/throwback--thursday-portlands_j.html'
|
101
|
+
expect(replies.last).to eq nil
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'uri tests' do
|
105
|
+
send_message 'http://www.oregonlive.com/history/2015/07/throwback++thursday-portlands_j.html'
|
106
|
+
expect(replies.last).to eq nil
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'midstream karmas' do
|
110
|
+
send_message 'I like big a++ and I cannot lie'
|
111
|
+
expect(replies.last).to eq 'a has 1 karma!'
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'midstream karma--s' do
|
115
|
+
send_message 'I like big a-- and I cannot lie'
|
116
|
+
expect(replies.last).to eq NEGATIVE_MESSAGE
|
117
|
+
end
|
118
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
+
SimpleCov::Formatter::HTMLFormatter,
|
5
|
+
Coveralls::SimpleCov::Formatter
|
6
|
+
]
|
7
|
+
SimpleCov.start { add_filter '/spec/' }
|
8
|
+
|
9
|
+
require 'lita-onewheel-karma'
|
10
|
+
require 'lita/rspec'
|
11
|
+
|
12
|
+
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
|
13
|
+
# was generated with Lita 4, the compatibility mode should be left disabled.
|
14
|
+
Lita.version_3_compatibility_mode = false
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-onewheel-karma
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kreps
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.8'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.8'
|
111
|
+
description: Karma with a maths-focused twist.
|
112
|
+
email:
|
113
|
+
- andrew.kreps@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/lita-onewheel-karma.rb
|
125
|
+
- lib/lita/handlers/onewheel_karma.rb
|
126
|
+
- lita-onewheel-karma.gemspec
|
127
|
+
- locales/en.yml
|
128
|
+
- spec/lita/handlers/onewheel_karma_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
homepage: https://github.com/onewheelskyward/lita-onewheel-karma
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata:
|
134
|
+
lita_plugin_type: handler
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.4.5
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Karma shouldn't be bound by simple increment and decrement operations.
|
155
|
+
test_files:
|
156
|
+
- spec/lita/handlers/onewheel_karma_spec.rb
|
157
|
+
- spec/spec_helper.rb
|