ruboty-karma 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a56590d972dfc201689c903d1e25a8c8c75dabd3
4
- data.tar.gz: 3bd7d652a90ade4a24b4363ec17a1c6657c48b91
3
+ metadata.gz: a4dd21b5fbd118593db0a559b6efbb61c5494d53
4
+ data.tar.gz: 8f8c63ed016ce5f7494c416bab4cc2927f572c8b
5
5
  SHA512:
6
- metadata.gz: c005bf59d8b73e4f6187315022d6e436cbd3c1a0a7903f463e94f9e77a4ba9e2aa448cf7d36a47ff2694c12449cb00385ef0ff1578ee61d34212457408903aac
7
- data.tar.gz: e99d67cb4778888921314c0abc08d4e112bdc1d29f369c0097f21bb8799339d223f02377b4ce32ba3aaea313ab0cecf80bdb86d367a6980f774bfe826b8bc46f
6
+ metadata.gz: fa720417106bf2e4c43251f9a6ffb57b6235d34d113d7f53d6baebe81321b842cacb0d3d0a167c4b930dbaf4fa3669be12be88021215c78ee17b3be4fcd9ea62
7
+ data.tar.gz: e81f9622dfbe065dc9537886b7afa618ea45ca3933637eb418c14028c5b085fbc593196d0507c2876c445923c479c7b75fc528b9d372ea825742353b40b07c8b
data/README.md CHANGED
@@ -29,12 +29,29 @@ Or install it yourself as:
29
29
  @ruboty will increase @name's karma.
30
30
 
31
31
  If you want to make @ruboty to say other response, you can use RUBOTY_KARMA_ADD.
32
+
32
33
  ex
33
34
 
34
35
  ```
35
36
  export RUBOTY_KARMA_ADD=%s got %d karma total! Awesome!
36
37
  ```
37
38
 
39
+ #### replace
40
+
41
+ You can use [`ruboty-replace`](https://github.com/r7kamura/ruboty-replace) to use shortcut commands.
42
+
43
+ Register
44
+
45
+ ```
46
+ @ruboty: replace thx @?([^  :]+) with @ruboty @\1 ++
47
+ ```
48
+
49
+ Use
50
+
51
+ ```
52
+ thx @name (you can write message here)
53
+ ```
54
+
38
55
  ### list
39
56
 
40
57
  ```
@@ -9,6 +9,7 @@ module Ruboty
9
9
  class Karma < Base
10
10
  INCREMENT_PATTERN = /@?(?<name>[^@:\s]+):?\s+\+\+/m
11
11
  DELETE_PATTERN = /delete karma @?(?<name>[^@:\s]+):?/m
12
+ LIST_PATTERN = /list karma(\s+(?<args>.+))?/
12
13
 
13
14
  on(
14
15
  INCREMENT_PATTERN,
@@ -16,7 +17,7 @@ module Ruboty
16
17
  description: "increment a user's karma"
17
18
  )
18
19
  on(
19
- /list karma/,
20
+ LIST_PATTERN,
20
21
  name: 'list',
21
22
  description: "list all users' karma"
22
23
  )
@@ -9,9 +9,25 @@ module Ruboty
9
9
  lists = brain.data[key].map do |user|
10
10
  [user, brain.data["karma-@#{user}"]]
11
11
  end
12
- text = lists.sort_by { |e| -e[1] }.map { |e| e.join(': ') }.join("\n")
12
+ sorted = lists.sort_by { |e| -e[1] }
13
+ text = sorted.map { |e|
14
+ e.last = quiet_name(e.last) if quiet?
15
+ e.join(': ')
16
+ }.join("\n")
13
17
  message.reply(text)
14
18
  end
19
+
20
+ def args
21
+ message['args'].split(/\s+/)
22
+ end
23
+
24
+ def quiet?
25
+ args.include?('-q') || args.include?('--quiet')
26
+ end
27
+
28
+ def quiet_name(name)
29
+ name.split('').join(' ')
30
+ end
15
31
  end
16
32
  end
17
33
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Karma
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -3,18 +3,8 @@ require 'minitest-power_assert'
3
3
  require 'ruboty/karma'
4
4
 
5
5
  describe Ruboty::Handlers::Karma do
6
- class Ruboty::Handlers::Karma
7
- def self.increment_pattern
8
- INCREMENT_PATTERN
9
- end
10
-
11
- def self.delete_pattern
12
- DELETE_PATTERN
13
- end
14
- end
15
-
16
6
  describe 'INCREMENT_PATTERN' do
17
- pattern = Ruboty::Handlers::Karma.increment_pattern
7
+ pattern = Ruboty::Handlers::Karma::INCREMENT_PATTERN
18
8
  it "should match '@hoge ++' -> hoge" do
19
9
  match = pattern.match('@hoge ++')
20
10
  assert { !match.nil? }
@@ -38,7 +28,7 @@ describe Ruboty::Handlers::Karma do
38
28
  end
39
29
 
40
30
  describe 'DELETE_PATTERN' do
41
- pattern = Ruboty::Handlers::Karma.delete_pattern
31
+ pattern = Ruboty::Handlers::Karma::DELETE_PATTERN
42
32
  it "should match 'delete karma @hoge' -> hoge" do
43
33
  match = pattern.match('delete karma @hoge')
44
34
  assert { !match.nil? }
@@ -60,4 +50,24 @@ describe Ruboty::Handlers::Karma do
60
50
  assert { match['name'] == 'hoge' }
61
51
  end
62
52
  end
53
+
54
+ describe 'LIST_PATTERN' do
55
+ pattern = Ruboty::Handlers::Karma::LIST_PATTERN
56
+ it "should match 'list karma'" do
57
+ match = pattern.match('list karma')
58
+ assert { !match.nil? }
59
+ end
60
+
61
+ it "should be able to capture args" do
62
+ match = pattern.match('list karma args')
63
+ assert { !match.nil? }
64
+ assert { match['args'] == 'args' }
65
+ end
66
+
67
+ it "should be able to capture two args" do
68
+ match = pattern.match('list karma args1 args2')
69
+ assert { !match.nil? }
70
+ assert { match['args'] == 'args1 args2' }
71
+ end
72
+ end
63
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-karma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hkdnet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-10 00:00:00.000000000 Z
11
+ date: 2016-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.4.5.1
122
+ rubygems_version: 2.5.1
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: manage members' karma