ruboty-hubot 1.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/ruboty/handlers/hubot.rb +5 -0
- data/lib/ruboty/hubot.rb +1 -0
- data/lib/ruboty/hubot/actions/hear.rb +13 -0
- data/lib/ruboty/hubot/actions/respond.rb +2 -19
- data/lib/ruboty/hubot/robot.rb +56 -41
- data/lib/ruboty/hubot/script.rb +29 -2
- data/lib/ruboty/hubot/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08178c671464d11a66e37e77af0ffac63f17378b
|
4
|
+
data.tar.gz: 39e08ee9c98106aa374b15f104118a08e7978407
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d2270185a67e19933c21d843dc7ca3c74f507b5e3cb5ff19863c6bbb501e7c98e244570a67f7cef12880b1302ed12ae837033c6ae1d8a04ea7cd0bf6eba1b72
|
7
|
+
data.tar.gz: 31c25946be925da58e76ece1cbe5639f916b5d30d2417020ee77f5e6ab8831104b5e11cb68b306acc011eaaf623f19587921314a500f17b348db5f74b21b5cc6
|
data/README.md
CHANGED
@@ -35,9 +35,9 @@ module.exports = function(robot) {
|
|
35
35
|
## TODO
|
36
36
|
|
37
37
|
- [x] support `.js` scripts
|
38
|
-
- [
|
38
|
+
- [x] support `.coffee` scripts
|
39
39
|
- [x] support robot.respond
|
40
|
-
- [
|
40
|
+
- [x] support robot.hear
|
41
41
|
- [ ] support more complex methods (e.x. robot.http)
|
42
42
|
- [ ] support `external-scripts.json`
|
43
43
|
- [ ] support `hubot-scripts.json`
|
@@ -1,8 +1,13 @@
|
|
1
1
|
module Ruboty
|
2
2
|
module Handlers
|
3
3
|
class Hubot < Base
|
4
|
+
on /.*/, name: 'hear', description: 'respond by hubot scripts', all: true
|
4
5
|
on /.*/, name: 'respond', description: 'respond by hubot scripts'
|
5
6
|
|
7
|
+
def hear(message)
|
8
|
+
Ruboty::Hubot::Actions::Hear.new(message).call
|
9
|
+
end
|
10
|
+
|
6
11
|
def respond(message)
|
7
12
|
Ruboty::Hubot::Actions::Respond.new(message).call
|
8
13
|
end
|
data/lib/ruboty/hubot.rb
CHANGED
@@ -2,26 +2,9 @@ module Ruboty
|
|
2
2
|
module Hubot
|
3
3
|
module Actions
|
4
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
5
|
def call
|
23
|
-
|
24
|
-
message.reply(
|
6
|
+
Robot.instance.receive_mention(message.body) do |res|
|
7
|
+
message.reply(res)
|
25
8
|
end
|
26
9
|
end
|
27
10
|
end
|
data/lib/ruboty/hubot/robot.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'execjs'
|
2
|
+
require 'singleton'
|
2
3
|
|
3
4
|
module Ruboty
|
4
5
|
module Hubot
|
5
6
|
class Robot
|
6
7
|
include Mem
|
8
|
+
include Singleton
|
7
9
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def load_script(script)
|
13
|
-
@scripts << script
|
10
|
+
def receive_all(text)
|
11
|
+
if res_text = robot_context.call("ruboty.receiveAll", text)
|
12
|
+
yield res_text if block_given?
|
13
|
+
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
if res_text = robot_context.call("ruboty.
|
16
|
+
def receive_mention(text)
|
17
|
+
if res_text = robot_context.call("ruboty.receiveMention", text)
|
18
18
|
yield res_text if block_given?
|
19
19
|
end
|
20
20
|
end
|
@@ -28,47 +28,62 @@ module Ruboty
|
|
28
28
|
|
29
29
|
def robot_js
|
30
30
|
@robot_js = <<ROBOT_JS
|
31
|
-
var
|
31
|
+
var ruboty = {
|
32
|
+
// mention
|
33
|
+
respondHandlers: [],
|
32
34
|
|
33
|
-
|
35
|
+
respond: function (regexp, callback) {
|
36
|
+
ruboty.respondHandlers.push({
|
37
|
+
regexp: regexp,
|
38
|
+
callback: callback
|
39
|
+
});
|
40
|
+
},
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
},
|
42
|
+
receiveMention: function (text) {
|
43
|
+
return ruboty.receive(text, ruboty.respondHandlers);
|
44
|
+
},
|
53
45
|
|
54
|
-
// all
|
55
|
-
|
46
|
+
// all
|
47
|
+
hearHandlers: [],
|
56
48
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
return
|
66
|
-
}
|
49
|
+
hear: function (regexp, callback) {
|
50
|
+
ruboty.hearHandlers.push({
|
51
|
+
regexp: regexp,
|
52
|
+
callback: callback
|
53
|
+
});
|
54
|
+
},
|
55
|
+
|
56
|
+
receiveAll: function (text) {
|
57
|
+
return ruboty.receive(text, ruboty.hearHandlers);
|
58
|
+
},
|
59
|
+
|
60
|
+
receive: function (text, handlers) {
|
61
|
+
var i, len, match, message;
|
62
|
+
for (i = 0, len = handlers.length; i < len; i++) {
|
63
|
+
if (match = text.match(handlers[i].regexp)) {
|
64
|
+
message = {
|
65
|
+
match: match,
|
66
|
+
sentText: null,
|
67
|
+
send: function (text) { return message.sentText = text; }
|
68
|
+
};
|
69
|
+
handlers[i].callback(message);
|
70
|
+
return message.sentText;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
return undefined;
|
74
|
+
}
|
67
75
|
};
|
76
|
+
var module = {};
|
77
|
+
#{scripts.map {|s| "#{s}\nif (module.exports) { module.exports(ruboty); module.exports = undefined; }\n" }.join("\n")}
|
68
78
|
|
69
|
-
module.exports(ruboty);
|
70
79
|
ROBOT_JS
|
71
80
|
end
|
81
|
+
|
82
|
+
def scripts
|
83
|
+
Dir.glob(File.join(Dir.pwd, 'scripts/*')).map do |path|
|
84
|
+
Script.new(path)
|
85
|
+
end
|
86
|
+
end
|
72
87
|
end
|
73
88
|
end
|
74
89
|
end
|
data/lib/ruboty/hubot/script.rb
CHANGED
@@ -1,9 +1,36 @@
|
|
1
|
+
require 'mem'
|
2
|
+
require 'execjs'
|
3
|
+
require "open-uri"
|
4
|
+
|
1
5
|
module Ruboty
|
2
6
|
module Hubot
|
3
7
|
class Script
|
4
|
-
|
8
|
+
class << self
|
9
|
+
include Mem
|
10
|
+
|
11
|
+
def compile(source)
|
12
|
+
coffee.call("CoffeeScript.compile", source, bare: true)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def coffee
|
18
|
+
ExecJS.compile(coffee_source)
|
19
|
+
end
|
20
|
+
memoize :coffee
|
21
|
+
|
22
|
+
def coffee_source
|
23
|
+
open("http://coffeescript.org/extras/coffee-script.js").read
|
24
|
+
end
|
25
|
+
memoize :coffee_source
|
26
|
+
end
|
27
|
+
|
5
28
|
def initialize(source_path)
|
6
|
-
|
29
|
+
if File.extname(source_path).downcase == '.coffee'
|
30
|
+
@source = self.class.compile(File.read(source_path))
|
31
|
+
else
|
32
|
+
@source = File.read(source_path)
|
33
|
+
end
|
7
34
|
end
|
8
35
|
|
9
36
|
def to_s
|
data/lib/ruboty/hubot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-hubot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- block_given?
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- Rakefile
|
109
109
|
- lib/ruboty/handlers/hubot.rb
|
110
110
|
- lib/ruboty/hubot.rb
|
111
|
+
- lib/ruboty/hubot/actions/hear.rb
|
111
112
|
- lib/ruboty/hubot/actions/respond.rb
|
112
113
|
- lib/ruboty/hubot/robot.rb
|
113
114
|
- lib/ruboty/hubot/script.rb
|
@@ -138,3 +139,4 @@ signing_key:
|
|
138
139
|
specification_version: 4
|
139
140
|
summary: ruboty plugin for using hubot script in ruboty.
|
140
141
|
test_files: []
|
142
|
+
has_rdoc:
|