ruboty-reminder 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruboty/handlers/reminder.rb +16 -12
- data/lib/ruboty/reminder/task.rb +4 -3
- data/lib/ruboty/reminder/version.rb +1 -1
- data/ruboty-reminder.gemspec +0 -2
- metadata +2 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da80f209dcff681fda0091e2be6025fdd58ea5b2
|
4
|
+
data.tar.gz: 0c5b965d4791226ca2ce14a99b941fe17811e7bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a01a00f58699c9ea3b6a561d8564f845f284c059c8c2e789a548ed7c4dc85a1f47968d548f4b93d8807ee1633cb307542d81aa5ed2088715ba6f82fd12bb0ae1
|
7
|
+
data.tar.gz: 223f2cbf7cd3eaade988047e2d2ecf25dcc10afe6164f897cbf2a9e863ec833b0d2860d94344946ed7e736e61c9e36523839e8df72eb39178e14303f24b92ac0
|
@@ -28,8 +28,8 @@ module Ruboty
|
|
28
28
|
hour = message[:hour].to_i
|
29
29
|
min = message[:min].to_i
|
30
30
|
|
31
|
-
unless
|
32
|
-
message.reply('Invalid time
|
31
|
+
unless valid_time?(year, month, day, hour, min)
|
32
|
+
message.reply('Invalid time.')
|
33
33
|
return
|
34
34
|
end
|
35
35
|
|
@@ -55,11 +55,13 @@ module Ruboty
|
|
55
55
|
task.start(robot)
|
56
56
|
message.reply("Reminder #{task.hash[:id]} is created.")
|
57
57
|
|
58
|
-
reminders[task.hash[:id]] = task
|
58
|
+
reminders[task.hash[:id]] = task
|
59
59
|
end
|
60
60
|
|
61
61
|
def delete(message)
|
62
|
-
if reminders
|
62
|
+
if task = reminders[message[:id].to_i]
|
63
|
+
task.thread.kill
|
64
|
+
reminders.delete(message[:id].to_i)
|
63
65
|
message.reply("Reminder #{message[:id]} is deleted.")
|
64
66
|
else
|
65
67
|
message.reply("Reminder #{message[:id]} is not found.")
|
@@ -70,19 +72,21 @@ module Ruboty
|
|
70
72
|
if reminders.empty?
|
71
73
|
message.reply("The reminder doesn't exist.")
|
72
74
|
else
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
"#{
|
75
|
+
sorted_reminders = reminders.sort_by {|_id, task| task.hash[:unixtime]}
|
76
|
+
|
77
|
+
reminder_list = sorted_reminders.map do |id, task|
|
78
|
+
date = "#{task.hash[:year]}/#{'%02d' % task.hash[:month]}/#{'%02d' % task.hash[:day]}"
|
79
|
+
time = "#{'%02d' % task.hash[:hour]}:#{'%02d' % task.hash[:min]}"
|
80
|
+
"#{id}: #{date} #{time} -> #{task.hash[:body]}"
|
77
81
|
end
|
78
82
|
message.reply(reminder_list.join("\n"), code: true)
|
79
83
|
end
|
80
84
|
end
|
81
85
|
|
82
86
|
def restart
|
83
|
-
reminders.each do |id,
|
84
|
-
|
85
|
-
|
87
|
+
reminders.each do |id, task|
|
88
|
+
new_task = Ruboty::Reminder::Task.new(task.hash)
|
89
|
+
new_task.start(robot)
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
@@ -97,7 +101,7 @@ module Ruboty
|
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
100
|
-
def
|
104
|
+
def valid_time?(year, month, day, hour, min)
|
101
105
|
YEAR_RANGE.include?(year) &&\
|
102
106
|
MONTH_RANGE.include?(month) &&\
|
103
107
|
DAY_RANGE.include?(day) &&\
|
data/lib/ruboty/reminder/task.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
module Ruboty
|
2
2
|
module Reminder
|
3
3
|
class Task
|
4
|
-
attr_reader :hash
|
4
|
+
attr_reader :hash, :thread
|
5
5
|
|
6
6
|
def initialize(hash)
|
7
7
|
@hash = hash
|
8
|
+
@thread = nil
|
8
9
|
end
|
9
10
|
|
10
11
|
def start(robot)
|
11
12
|
wait_time = hash[:unixtime] - Time.now.to_i
|
12
13
|
|
13
|
-
Thread.start do
|
14
|
+
@thread = Thread.start do
|
14
15
|
sleep(wait_time)
|
15
16
|
Message.new(
|
16
|
-
hash.except(:id, :body, :hour, :min).merge(robot: robot)
|
17
|
+
hash.except(:id, :body, :year, :month, :day, :hour, :min, :unixtime).merge(robot: robot)
|
17
18
|
).reply(hash[:body])
|
18
19
|
robot.brain.data[NAMESPACE].delete(hash[:id])
|
19
20
|
end
|
data/ruboty-reminder.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-reminder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|
@@ -52,34 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: pry
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: awesome_print
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
55
|
description: Ruboty handler to remind a task.
|
84
56
|
email:
|
85
57
|
- kaihar4@gmail.com
|