ruboty-response 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29000ff2c755ae4722df86c16394cd46eaf9dcc6
4
+ data.tar.gz: 2ee778ed52afa4a4b86b638a93967611abdb184a
5
+ SHA512:
6
+ metadata.gz: b6077551bbf7079abbd4be70d30b19368b2e8af4b73014f9f02d5ea7877970df92026c5f86431244dbf7e4808a23df2ab18686f163e1c3261ddff6f81a4193db
7
+ data.tar.gz: 870466585aa6c5600f07f1bedbcac7c476c8e0e265bb270573e0980ce4873ba78aeff8c1c8dc881e71c42b795841094c2c9417b11d13111b56525ed66de61ff7
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-response.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 kaihar4
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Ruboty::Response
2
+
3
+ Ruboty handler to register a response.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-response'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ @ruboty respond /<regex>/ <response>
17
+ @ruboty list responses
18
+ @ruboty delete response <id>
19
+ ```
20
+
21
+ ## Example
22
+
23
+ ```
24
+ > @ruboty respond /^foo$/ bar
25
+ Response 533 registered.
26
+ > foo
27
+ bar
28
+ > fooo
29
+ >
30
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,68 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class Response < Base
4
+ NAMESPACE = 'response'
5
+
6
+ on /(?<keyword>.+)/, name: 'catchall', hidden: true, all: true
7
+
8
+ on /respond \/(?<regex>.+)\/ (?<response>.+)/, name: 'respond', description: 'Register a response'
9
+ on /delete response (?<id>.+)/, name: 'delete', description: 'Delete a response'
10
+ on /list responses/, name: 'list', description: 'Show registered responses'
11
+
12
+ def catchall(message)
13
+ responses.each do |id, hash|
14
+ if /#{hash[:regex]}/ =~ message[:keyword]
15
+ message.reply(hash[:response])
16
+ end
17
+ end
18
+ end
19
+
20
+ def respond(message)
21
+ id = generate_id
22
+ hash = {
23
+ regex: message[:regex],
24
+ response: message[:response]
25
+ }
26
+
27
+ # Insert to the brain
28
+ responses[id] = hash
29
+
30
+ message.reply("Response #{id} registered.")
31
+ end
32
+
33
+ def delete(message)
34
+ if responses.delete(message[:id].to_i)
35
+ message.reply('Deleted.')
36
+ else
37
+ message.reply('Not found.')
38
+ end
39
+ end
40
+
41
+ def list(message)
42
+ body =
43
+ if responses.empty?
44
+ 'No response registered.'
45
+ else
46
+ responses.map do |id, hash|
47
+ "#{id}: /#{hash[:regex]}/ -> #{hash[:response]}"
48
+ end.join("\n")
49
+ end
50
+
51
+ message.reply(body)
52
+ end
53
+
54
+ private
55
+
56
+ def responses
57
+ robot.brain.data[NAMESPACE] ||= {}
58
+ end
59
+
60
+ def generate_id
61
+ loop do
62
+ id = rand(1000)
63
+ break id unless responses.has_key?(id)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,2 @@
1
+ require 'ruboty'
2
+ require 'ruboty/handlers/response'
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Response
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
2
+ require 'ruboty/response/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'ruboty-response'
6
+ spec.version = Ruboty::Response::VERSION
7
+ spec.authors = ['kaihar4']
8
+ spec.email = ['kaihar4@gmail.com']
9
+ spec.summary = 'Ruboty handler to register a response.'
10
+ spec.description = spec.summary
11
+ spec.homepage = 'https://github.com/kaihar4/ruboty-response'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'ruboty'
20
+
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'pry'
24
+ spec.add_development_dependency 'awesome_print'
25
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-response
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kaihar4
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
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
+ description: Ruboty handler to register a response.
84
+ email:
85
+ - kaihar4@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/ruboty/handlers/response.rb
96
+ - lib/ruboty/response.rb
97
+ - lib/ruboty/response/version.rb
98
+ - ruboty-response.gemspec
99
+ homepage: https://github.com/kaihar4/ruboty-response
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Ruboty handler to register a response.
123
+ test_files: []