ruboty-hubot 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f0e5c0842257c3dbb56ac1413afea7297326dcb
4
+ data.tar.gz: 9b073aca8dcb346ecf6888547e93ea4c34271b98
5
+ SHA512:
6
+ metadata.gz: cdad93387e226601a964264aee0016bc0291a1fe02f40e77fae7eee057f47b1c364f7763b7ce2257b0922283de9dd56f357288b0aac832047d7b2b249f017b27
7
+ data.tar.gz: 2bdf4a1ff82fdd79e2f4e21d3952e2b528495204dfb6ef300ad78311141adf5c980e664ff625d732d4674b21fe617e6074df595704c2093f8b4c6aa0f5637222
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-hubot.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 block_given?
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,51 @@
1
+ # Ruboty::Hubot
2
+
3
+ ruboty plugin for using hubot script in ruboty.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-hubot'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ruboty-hubot
20
+
21
+ ## Usage
22
+
23
+ put your hubot scripts under the `scripts`
24
+
25
+ ### Example:
26
+
27
+ ``` js
28
+ module.exports = function(robot) {
29
+ return robot.respond(/yo$/i, function(res) {
30
+ return res.send('yo!');
31
+ });
32
+ };
33
+ ```
34
+
35
+ ## TODO
36
+
37
+ - [x] support `.js` scripts
38
+ - [ ] support `.coffee` scripts
39
+ - [x] support robot.respond
40
+ - [ ] support robot.hear
41
+ - [ ] support more complex methods (e.x. robot.http)
42
+ - [ ] support `external-scripts.json`
43
+ - [ ] support `hubot-scripts.json`
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/blockgiven/ruboty-hubot/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,11 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class Hubot < Base
4
+ on /.*/, name: 'respond', description: 'respond by hubot scripts'
5
+
6
+ def respond(message)
7
+ Ruboty::Hubot::Actions::Respond.new(message).call
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ module Ruboty
2
+ module Hubot
3
+ module Actions
4
+ class Respond < Ruboty::Actions::Base
5
+ class << self
6
+ include Mem
7
+
8
+ def scripts
9
+ Dir.glob(File.join(Dir.pwd, 'scripts/*')).map do |path|
10
+ Script.new(path)
11
+ end
12
+ end
13
+
14
+ def robot
15
+ robot = Robot.new
16
+ scripts.each {|script| robot.load_script script }
17
+ robot
18
+ end
19
+ memoize :robot
20
+ end
21
+
22
+ def call
23
+ self.class.robot.receive(message.body) do |res|
24
+ message.reply("@#{message.from_name} #{res}")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,74 @@
1
+ require 'execjs'
2
+
3
+ module Ruboty
4
+ module Hubot
5
+ class Robot
6
+ include Mem
7
+
8
+ def initialize
9
+ @scripts = []
10
+ end
11
+
12
+ def load_script(script)
13
+ @scripts << script
14
+ end
15
+
16
+ def receive(text)
17
+ if res_text = robot_context.call("ruboty.receive", text)
18
+ yield res_text if block_given?
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def robot_context
25
+ ExecJS.compile(robot_js)
26
+ end
27
+ memoize :robot_context
28
+
29
+ def robot_js
30
+ @robot_js = <<ROBOT_JS
31
+ var module = {};
32
+
33
+ #{@scripts.join(";\n")}
34
+
35
+ var ruboty = {
36
+ handlers: [],
37
+ respond: function (regexp, callback) {
38
+ ruboty.handlers.push({
39
+ response: function (text) {
40
+ var match;
41
+ if (match = text.match(regexp)) {
42
+ var res = {
43
+ match: match,
44
+ sentText: null,
45
+ send: function (text) { return res.sentText = text; }
46
+ };
47
+ return res;
48
+ }
49
+ },
50
+ callback: callback
51
+ });
52
+ },
53
+
54
+ // all
55
+ hear: undefined,
56
+
57
+ // mention
58
+ receive: function (text) {
59
+ var i, len, res;
60
+ for (i = 0, len = ruboty.handlers.length; i < len; i++) {
61
+ if (res = ruboty.handlers[i].response(text)) {
62
+ return ruboty.handlers[i].callback(res);
63
+ }
64
+ }
65
+ return undefined;
66
+ }
67
+ };
68
+
69
+ module.exports(ruboty);
70
+ ROBOT_JS
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,14 @@
1
+ module Ruboty
2
+ module Hubot
3
+ class Script
4
+ # TODO: compile .coffee
5
+ def initialize(source_path)
6
+ @source = File.read(source_path)
7
+ end
8
+
9
+ def to_s
10
+ @source
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Hubot
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require "ruboty/hubot/version"
2
+ require "ruboty/hubot/robot"
3
+ require "ruboty/hubot/script"
4
+ require "ruboty/handlers/hubot"
5
+ require "ruboty/hubot/actions/respond"
6
+
7
+ module Ruboty
8
+ module Hubot
9
+ # Your code goes here...
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/hubot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-hubot"
8
+ spec.version = Ruboty::Hubot::VERSION
9
+ spec.authors = ["block_given?"]
10
+ spec.email = ["block_given@outlook.com"]
11
+ spec.summary = %q{ruboty plugin for using hubot script in ruboty.}
12
+ spec.homepage = "https://github.com/blockgiven/ruboty-hubot"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "ruboty"
21
+ spec.add_runtime_dependency "execjs"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "pry-byebug"
26
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-hubot
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - block_given?
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-11 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: execjs
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - block_given@outlook.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/ruboty/handlers/hubot.rb
110
+ - lib/ruboty/hubot.rb
111
+ - lib/ruboty/hubot/actions/respond.rb
112
+ - lib/ruboty/hubot/robot.rb
113
+ - lib/ruboty/hubot/script.rb
114
+ - lib/ruboty/hubot/version.rb
115
+ - ruboty-hubot.gemspec
116
+ homepage: https://github.com/blockgiven/ruboty-hubot
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: ruboty plugin for using hubot script in ruboty.
140
+ test_files: []