ruboty-attendance 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruboty/attendance/version.rb +1 -1
- data/lib/ruboty/handlers/attendance.rb +37 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d393ca269d49bbaf388554b39b5e7e24837ccf6
|
4
|
+
data.tar.gz: 4d4531971e83628d706af60cbe8e5c6b73654b2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f708b9f7245403dc94da8a70361c26a14c602f2f2e560b010329566b0a1c98b2966cccf062a89b7f8b2861651c77e7ce29fe764d3a13163b951fc8e9b64522c
|
7
|
+
data.tar.gz: 7ad2ee8c2a210e28043b0ed2280c9a6498f552d4069ecd4f7f40c7f4d87dc47f5220e57007a78d0fece44463cc7d39aeda3388573065ec876119f7544c8e90e9
|
@@ -3,12 +3,34 @@
|
|
3
3
|
module Ruboty
|
4
4
|
module Handlers
|
5
5
|
class Attendance < Base
|
6
|
+
NAMESPACE = "attendance"
|
7
|
+
|
6
8
|
on( /(?<name>.+) 出社/, name: "come_to_the_office", description: "<name> just got to work.")
|
7
9
|
|
8
10
|
env :START_OF_OFFICE_HOURS, "The start of office hours. e.g. 9:30", optional: true
|
11
|
+
|
9
12
|
private
|
10
13
|
|
11
14
|
def come_to_the_office(message)
|
15
|
+
name = message[:name]
|
16
|
+
if check_duplicate(name)
|
17
|
+
duplicate(message)
|
18
|
+
return
|
19
|
+
end
|
20
|
+
check_limit ? success(name, message) : failure(name, message)
|
21
|
+
end
|
22
|
+
|
23
|
+
def check_duplicate(name)
|
24
|
+
last_time = scores[name]
|
25
|
+
return false unless last_time
|
26
|
+
now = Time.now
|
27
|
+
last = Time.at(last_time)
|
28
|
+
now.year == last.year &&
|
29
|
+
now.month == last.month &&
|
30
|
+
now.day == last.day
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_limit
|
12
34
|
now = Time.now
|
13
35
|
limit = Time.local(
|
14
36
|
now.year,
|
@@ -18,17 +40,22 @@ module Ruboty
|
|
18
40
|
start_of_office_hours[1],
|
19
41
|
00
|
20
42
|
)
|
21
|
-
now
|
43
|
+
now <= limit
|
22
44
|
end
|
23
45
|
|
24
|
-
def
|
25
|
-
|
26
|
-
message.reply("
|
46
|
+
def duplicate(message)
|
47
|
+
message.reply("Duplicate login!")
|
48
|
+
message.reply("#{robot.name} zoi ごはんにする")
|
49
|
+
end
|
50
|
+
|
51
|
+
def failure(name, message)
|
52
|
+
scores[name] = Time.now.to_i
|
53
|
+
message.reply("Login mission failure!\n今度はがんばりましょう")
|
27
54
|
message.reply("#{name}--")
|
28
55
|
end
|
29
56
|
|
30
|
-
def success(message)
|
31
|
-
name =
|
57
|
+
def success(name, message)
|
58
|
+
scores[name] = Time.now.to_i
|
32
59
|
message.reply("Login mission success!")
|
33
60
|
message.reply("#{name}++")
|
34
61
|
end
|
@@ -36,6 +63,10 @@ module Ruboty
|
|
36
63
|
def start_of_office_hours
|
37
64
|
ENV["START_OF_OFFICE_HOURS"].split(":").map(&:to_i)
|
38
65
|
end
|
66
|
+
|
67
|
+
def scores
|
68
|
+
robot.brain.data[NAMESPACE] ||= {}
|
69
|
+
end
|
39
70
|
end
|
40
71
|
end
|
41
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-attendance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-09-
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|