boty 0.0.13 → 0.0.14
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/boty.rb +2 -0
- data/lib/boty/action.rb +10 -5
- data/lib/boty/bot.rb +8 -24
- data/lib/boty/message.rb +4 -0
- data/lib/boty/script_dsl.rb +24 -0
- data/lib/boty/script_loader.rb +21 -0
- data/lib/boty/version.rb +1 -1
- metadata +3 -2
- data/lib/boty/dsl.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1456a7baa55bfe9bd3d7f66044b48ad900753686
|
4
|
+
data.tar.gz: 3bf63d30f6d2f77b20fe2ae7b13fbbed8283ad26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13a273517a75e7d28dfcf8784167ad6950843a97ef1392bf4c522910f4ad456dade641ec935d9a79018e88c1914eba02b2b9a58664c11956beba791275abcb32
|
7
|
+
data.tar.gz: 973e402fa4780ca293790850b58690ab51d62ee0d3540bc0026f1a35190b3ee1b7846609ab2086409a3df09a6da96aaaed5973432e1745e3baeeaea68c3fc90f
|
data/Gemfile.lock
CHANGED
data/lib/boty.rb
CHANGED
data/lib/boty/action.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Boty
|
2
2
|
class Action
|
3
|
+
include Boty::Logger
|
3
4
|
attr_reader :regex, :desc, :action
|
4
5
|
|
5
6
|
class Description
|
@@ -33,11 +34,15 @@ module Boty
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def is_this?(regex, block)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
same_regex = regex == self.regex
|
38
|
+
block ? same_regex && block == self.action : same_regex
|
39
|
+
end
|
40
|
+
|
41
|
+
def execute(bot, message)
|
42
|
+
ScriptDSL.new(bot).instance_exec message, &action if message.match! regex
|
43
|
+
rescue => e
|
44
|
+
logger.error e.message
|
45
|
+
raise e
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
data/lib/boty/bot.rb
CHANGED
@@ -8,7 +8,7 @@ module Boty
|
|
8
8
|
@handlers ||= []
|
9
9
|
@commands ||= []
|
10
10
|
@events = {}
|
11
|
-
|
11
|
+
ScriptLoader.new(self).load
|
12
12
|
on :message, &method(:message_handler)
|
13
13
|
end
|
14
14
|
|
@@ -92,18 +92,6 @@ module Boty
|
|
92
92
|
|
93
93
|
private
|
94
94
|
|
95
|
-
def scripts_to_load
|
96
|
-
default_scripts_path = File.expand_path("../../../script", __FILE__)
|
97
|
-
paths = Dir["script/**/*.rb"] + Dir["#{default_scripts_path}/**/*.rb"]
|
98
|
-
paths.map { |file| File.expand_path file }.uniq
|
99
|
-
end
|
100
|
-
|
101
|
-
def load_default_scripts
|
102
|
-
scripts_to_load.each do |file|
|
103
|
-
instance_eval File.read(file), file, 1
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
95
|
def event_type(data)
|
108
96
|
type = data["type"].to_sym
|
109
97
|
logger.debug { "bot specifc event[#{type}] arrived: #{data}" }
|
@@ -129,19 +117,15 @@ module Boty
|
|
129
117
|
!!(/(<@#{id}|#{name}>)/ =~ data["text"])
|
130
118
|
end
|
131
119
|
|
132
|
-
def execute_command(command, message)
|
133
|
-
@_message = message
|
134
|
-
instance_exec @_message, &command.action
|
135
|
-
@_message = nil
|
136
|
-
end
|
137
|
-
|
138
120
|
def message_handler(data)
|
139
121
|
actions = has_valid_mention?(data) ? @commands : @handlers
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
122
|
+
@_message = Message.new data
|
123
|
+
begin
|
124
|
+
Array(actions).each do |action|
|
125
|
+
action.execute self, @_message
|
126
|
+
end
|
127
|
+
ensure
|
128
|
+
@_message = nil
|
145
129
|
end
|
146
130
|
end
|
147
131
|
end
|
data/lib/boty/message.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module Boty
|
4
|
+
class ScriptDSL
|
5
|
+
attr_accessor :bot
|
6
|
+
|
7
|
+
INSTANCES = {}
|
8
|
+
private_constant :INSTANCES
|
9
|
+
class << self
|
10
|
+
alias original_constructor new
|
11
|
+
end
|
12
|
+
|
13
|
+
extend Forwardable
|
14
|
+
def_delegators :bot, :desc, :respond, :name, :say, :im, :brain, :know_how
|
15
|
+
|
16
|
+
def initialize(bot)
|
17
|
+
@bot = bot
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.new(bot)
|
21
|
+
INSTANCES[bot] ||= original_constructor bot
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Boty
|
2
|
+
class ScriptLoader
|
3
|
+
def initialize(bot)
|
4
|
+
@dsl = ScriptDSL.new bot
|
5
|
+
end
|
6
|
+
|
7
|
+
def load
|
8
|
+
scripts_to_load.each do |file|
|
9
|
+
@dsl.instance_eval File.read(file), file, 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def scripts_to_load
|
16
|
+
default_scripts_path = File.expand_path("../../../script", __FILE__)
|
17
|
+
paths = Dir["script/**/*.rb"] + Dir["#{default_scripts_path}/**/*.rb"]
|
18
|
+
paths.map { |file| File.expand_path file }.uniq
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/boty/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Valeriano
|
@@ -191,10 +191,11 @@ files:
|
|
191
191
|
- lib/boty/action.rb
|
192
192
|
- lib/boty/bot.rb
|
193
193
|
- lib/boty/cli.rb
|
194
|
-
- lib/boty/dsl.rb
|
195
194
|
- lib/boty/logger.rb
|
196
195
|
- lib/boty/message.rb
|
197
196
|
- lib/boty/rspec.rb
|
197
|
+
- lib/boty/script_dsl.rb
|
198
|
+
- lib/boty/script_loader.rb
|
198
199
|
- lib/boty/session.rb
|
199
200
|
- lib/boty/slack.rb
|
200
201
|
- lib/boty/slack/channel.rb
|
data/lib/boty/dsl.rb
DELETED
File without changes
|