ruboty-gamification 0.0.2 → 0.0.3

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: d5603aa2b19a58433d82d7ad56cafd30f25ff09f
4
- data.tar.gz: d7eed04b8668b8efcff0a732e4d151afaa337de5
3
+ metadata.gz: 7a96642772edbd67687ad163c88d59e21efae582
4
+ data.tar.gz: a33b5669474702c03a8593bb53b8d5f9aec80283
5
5
  SHA512:
6
- metadata.gz: 91551b1fbceb1f7e22087f6ff28a6ceb2a8f1e8bcc93684e152991e7931bc58fff299d8d8ee4c62a07e1f391702e5c6a279ec6a3986b8eb587e9e99dc425e304
7
- data.tar.gz: 071dbd146dcf9bea87e39b32a17ae4e62fd38c1eaf119cc0776b232297aed39cac6a3501ce5d878cc022109fcb4230582c7d2af40924783c29bc62f5bbc9a5c3
6
+ metadata.gz: eefbd8ef5193c1da8eae742258eb8fcff519fa780326e328b5d5487f63035579329998a302af41aed46006977a8fd442c55612f3b545f37e285a4f35288d715c
7
+ data.tar.gz: 0c9817e41fa9b1b7b1392b3641dee9bd9794fc81a9d51c1b804aa32792523b762d1050d779d892aee595b956ee66df5818c577ac50d8a546a66af8e43a7eb270
@@ -13,14 +13,32 @@ module Ruboty
13
13
  def setup
14
14
  load(:increment)
15
15
  load(:decrement)
16
- @gamification.reply_messages = reply_messages
16
+ end
17
+
18
+ def increment(message)
19
+ name = message.from_name
20
+ message.reply(reply_message(:increment ,message))
21
+ message.reply("#{name}++")
22
+ end
23
+
24
+ def decrement(message)
25
+ name = message.from_name
26
+ message.reply(reply_message(:decrement ,message))
27
+ message.reply("#{name}--")
28
+ end
29
+
30
+ def reload(message)
31
+ load(:increment)
32
+ load(:decrement)
17
33
  end
18
34
 
19
35
  private
20
36
  def load(label)
21
37
  get(labels: label).body.each do |data|
38
+ pattern = /#{Regexp.escape(data["title"])}$/
39
+ next if @gamification.actions.any?{|action| action.pattern == pattern}
22
40
  @gamification.on(
23
- /#{data["title"]}$/,
41
+ pattern,
24
42
  name: "#{label}",
25
43
  description: "#{label} score (https://github.com/yoshiori/ruboty-gamification/issues)",
26
44
  )
@@ -28,6 +46,12 @@ module Ruboty
28
46
  end
29
47
  end
30
48
 
49
+ def reply_message(label, message)
50
+ if /\A@?#{Regexp.escape(message.robot.name)}:?\s*(.*)/ =~ message.body
51
+ reply_messages[label][$1]
52
+ end
53
+ end
54
+
31
55
  def reply_messages
32
56
  @reply_messages ||= {increment: {}, decrement: {}}
33
57
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Gamification
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -9,31 +9,28 @@ module Ruboty
9
9
 
10
10
  NAMESPACE = "gamification"
11
11
 
12
+ on /gamification reload$/, name: "reload", description: "reload issues"
13
+
12
14
  client = Ruboty::Gamification::Client.new(self)
13
15
  client.setup
14
16
 
17
+ define_method(:client) do
18
+ client
19
+ end
20
+
15
21
  private
16
22
 
17
23
  def increment(message)
18
- name = message.from_name
19
- return unless name
20
- message.reply(reply_message(:increment ,message))
21
- message.reply("#{name}++")
24
+ client.increment(message)
22
25
  end
23
26
 
24
27
  def decrement(message)
25
- name = message.from_name
26
- return unless name
27
- message.reply(reply_message(:decrement ,message))
28
- message.reply("#{name}--")
28
+ client.decrement(message)
29
29
  end
30
30
 
31
- def reply_message(label, message)
32
- if /\A@?#{Regexp.escape(robot.name)}:?\s*(.*)/ =~ message.body
33
- Gamification.reply_messages[label][$1]
34
- end
31
+ def reload(message)
32
+ client.reload(message)
35
33
  end
36
-
37
34
  end
38
35
  end
39
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-gamification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiori SHOJI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-06 00:00:00.000000000 Z
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty