ruboty-reminder 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/ruboty/handlers/reminder.rb +36 -4
- data/lib/ruboty/reminder/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 220184f328d7e33769c728a75cc2f460c846fef9
|
4
|
+
data.tar.gz: 637e3a1fd2542212a2fb33cc378c34aa6531c2b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d40ec768186e09b46a627535182cbde67e6d970b09562c4439a95f8b458c3031223a7fd739c2879581b9e783da7e02c2e75564f30bfff102cb813a7406c4013
|
7
|
+
data.tar.gz: 8c88ed81d33411e35853fb7054b183949375cc5f62b194cd103d3393b7b5b7e181e57bc8e48613d4c674bd6c9c7eb43d640fa6051f4a2f4efaed2eaf22ca4822
|
data/README.md
CHANGED
@@ -13,6 +13,14 @@ gem 'ruboty-reminder'
|
|
13
13
|
## Usage
|
14
14
|
|
15
15
|
```
|
16
|
-
|
17
|
-
@ruboty
|
16
|
+
@ruboty add task HH:MM <task>
|
17
|
+
@ruboty delete task <id>
|
18
|
+
@ruboty list tasks <id>
|
19
|
+
```
|
20
|
+
|
21
|
+
## Example
|
22
|
+
|
23
|
+
```
|
24
|
+
> @ruboty add task 07:00 Hi,kaihara!
|
25
|
+
Task 270 created.
|
18
26
|
```
|
@@ -3,20 +3,31 @@ module Ruboty
|
|
3
3
|
class Reminder < Base
|
4
4
|
NAMESPACE = 'reminder'
|
5
5
|
|
6
|
-
on /
|
6
|
+
on /add task (?<hh>\d{2}):(?<mm>\d{2}) (?<task>.+)/, name: 'add', description: 'Add a task'
|
7
|
+
on /delete task (?<id>.+)/, name: 'delete', description: 'Delete a task'
|
8
|
+
on /list tasks/, name: 'list', description: 'Show all reminders'
|
7
9
|
|
8
10
|
def initialize(*args)
|
9
11
|
super
|
10
12
|
restart
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
15
|
+
def add(message)
|
16
|
+
hour = message[:hh].to_i
|
17
|
+
min = message[:mm].to_i
|
18
|
+
|
19
|
+
# Validate
|
20
|
+
unless hour >= 0 && hour <= 23 && min >= 0 && min <= 59
|
21
|
+
message.reply('Invalid time format.')
|
22
|
+
return
|
23
|
+
end
|
24
|
+
|
14
25
|
task = Ruboty::Reminder::Task.new(
|
15
26
|
message.original.except(:robot).merge(
|
16
27
|
id: generate_id,
|
17
28
|
body: message[:task],
|
18
|
-
hour:
|
19
|
-
min:
|
29
|
+
hour: hour,
|
30
|
+
min: min
|
20
31
|
)
|
21
32
|
)
|
22
33
|
task.start(robot)
|
@@ -26,6 +37,27 @@ module Ruboty
|
|
26
37
|
tasks[task.hash[:id]] = task.hash
|
27
38
|
end
|
28
39
|
|
40
|
+
def delete(message)
|
41
|
+
if tasks.delete(message[:id].to_i)
|
42
|
+
message.reply('Deleted.')
|
43
|
+
else
|
44
|
+
message.reply('Not found.')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def list(message)
|
49
|
+
body =
|
50
|
+
if tasks.empty?
|
51
|
+
"The task doesn't exist."
|
52
|
+
else
|
53
|
+
tasks.map do |id, hash|
|
54
|
+
"#{id}: #{'%02d' % hash[:hour]}:#{'%02d' % hash[:min]} -> #{hash[:body]}"
|
55
|
+
end.join("\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
message.reply(body)
|
59
|
+
end
|
60
|
+
|
29
61
|
def restart
|
30
62
|
tasks.each do |id, hash|
|
31
63
|
task = Ruboty::Reminder::Task.new(hash)
|