ruboty-response 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3bf40f5fc68b13548d71aa1d00c1b382a2ee51c
4
- data.tar.gz: d16615139a10a828f4f542840bf59c2b7d049968
3
+ metadata.gz: 100a6a6a099ff3f5276e70db33f9e113b8b8b9dc
4
+ data.tar.gz: 6165defa69a1b64107770143b5a009909c9983f4
5
5
  SHA512:
6
- metadata.gz: 1866ebc309e466d32c8e2bf5ae9daa55d8a359d46f09d5e1360f467c7e189b740ab3bdc17a8c6b57ae75094998ca1ea849e5cdebb7a877963da7b56ffd4a664e
7
- data.tar.gz: 8dc97b22585c9013462c509f65883ba0b71b01562bf7821417a6ddb3bd7c329e829297100c8188237024ef0ad72795a5247a478d32f22814561efd2d43e666ce
6
+ metadata.gz: c6ee2ceeceab7968855acf81003b04ca9f58b79a1e1caba0d096d26991577e6b73e6ff25bf5b788f92bd24a68f9d2044fe9b459ca702de75a9c49c6a335f0df4
7
+ data.tar.gz: ca4bfc4e7af44f0c80100775f7381c44f4d1d2b73f4af00e3f9c8f0c9bf0f5c7240d823abec0515fc62be83dc48d162c3aeb8273ab8cb0c117549fb44ed32a3a
data/README.md CHANGED
@@ -18,6 +18,10 @@ gem 'ruboty-response'
18
18
  @ruboty delete response <id>
19
19
  ```
20
20
 
21
+ If you would like to run a shell command, you need to surround it in back quotes.
22
+
23
+ e.g. ``@ruboty add response /^time$/ `date```
24
+
21
25
  ## Example
22
26
 
23
27
  ```
@@ -27,4 +31,8 @@ Response 533 is registered.
27
31
  bar
28
32
  > fooo
29
33
  >
34
+ > @ruboty add response /^time$/ `ruby -e 'puts Time.now.to_s'`
35
+ Response 464 is registered.
36
+ > time
37
+ 2014-11-20 14:00:00 +0900
30
38
  ```
@@ -5,13 +5,25 @@ module Ruboty
5
5
 
6
6
  on /(?<keyword>.+)/, name: 'catchall', hidden: true, all: true
7
7
 
8
- on /add response \/(?<regex>.+)\/ (?<response>.+)/, name: 'add', description: 'Add a response'
8
+ on /add response \/(?<regex>.+)\/ (?<response>`?.+`?)/, name: 'add', description: 'Add a response'
9
9
  on /delete response (?<id>.+)/, name: 'delete', description: 'Delete a response'
10
10
  on /list responses\z/, name: 'list', description: 'Show registered responses'
11
11
 
12
12
  def catchall(message)
13
13
  responses.each do |id, hash|
14
- if /#{hash[:regex]}/ =~ message[:keyword]
14
+ next unless /#{hash[:regex]}/ =~ message[:keyword]
15
+
16
+ # If the response is a code
17
+ if hash[:response] =~ /\A`.+`\z/
18
+ thread = Thread.start do
19
+ result = `#{hash[:response].match(/\A`(.+)`\z/)[1]}`.chomp!
20
+ message.reply(result)
21
+ end
22
+ Thread.start do
23
+ sleep 3
24
+ thread.kill
25
+ end
26
+ else
15
27
  message.reply(hash[:response])
16
28
  end
17
29
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Response
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-response
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaihar4
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty