ruboty-reminder 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7b62f4666afc1723a79cf0f1cabd10ec85c5447
4
- data.tar.gz: ff2850c17f0b7d5417a185ade68e047be9615e18
3
+ metadata.gz: 220184f328d7e33769c728a75cc2f460c846fef9
4
+ data.tar.gz: 637e3a1fd2542212a2fb33cc378c34aa6531c2b7
5
5
  SHA512:
6
- metadata.gz: e077ec44ad554792644f4a5f6660c67f4df3b9c45253339d4100b8089920e28893e26e72d2c493f2327829a8f9aad9ecbee5a98403ae56da966f67426c4a3544
7
- data.tar.gz: c4307a77c5ca19bb33e1a053a2bce8997489ef9a5a455e7ab30d2abd22f2e53762e91c3b7e4fb5d305b4467bc4b59f2b16fb16d4b0b9129304394092d7088dc1
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
- # e.g. @ruboty remind 07:00 Hi,kaihara!
17
- @ruboty remind HH:MM <task>
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 /remind (?<hh>\d{2}):(?<mm>\d{2}) (?<task>.+)/, name: 'remind', description: 'Remind a task'
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 remind(message)
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: message[:hh].to_i,
19
- min: message[:mm].to_i
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)
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Reminder
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-reminder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaihar4