slappy 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound.yml +6 -0
- data/.travis.yml +0 -3
- data/README.md +29 -5
- data/lib/slappy/cli.rb +5 -0
- data/lib/slappy/commands/generator.rb +5 -0
- data/lib/slappy/commands/run.rb +29 -8
- data/lib/slappy/configuration.rb +21 -1
- data/lib/slappy/dsl.rb +1 -1
- data/lib/slappy/listener.rb +1 -1
- data/lib/slappy/version.rb +1 -1
- data/lib/slappy.rb +5 -12
- data/templates/slappy_config.rb +29 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e79a1760b63ef1b9dc0b47ddc653346f56d972f
|
4
|
+
data.tar.gz: 081b83f1f491f9173a1fd25f085c42faed243013
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5b60c4a6050e4df1e15f5f0d8ddd3a544edbf69669c18148dd505e05ddd152041dd14acfd662db472d73338ca32347a54cd409cdfee0e232a72374f0c78ed6b
|
7
|
+
data.tar.gz: af1e4362d1387b85cc69e7492ed88b9b2f0f0a8e5bae0fd8eb042c2762742b597ad90c1cc4f3fddfb01db993d293742ed575173d3eddc9af1a2da81124edfecd
|
data/.hound.yml
CHANGED
@@ -15,6 +15,12 @@ Style/Documentation:
|
|
15
15
|
Style/StringLiterals:
|
16
16
|
EnforcedStyle: single_quotes
|
17
17
|
|
18
|
+
##################### Lint ##################################
|
19
|
+
|
20
|
+
Lint/UnusedBlockArgument:
|
21
|
+
Exclude:
|
22
|
+
- 'templates/slappy_config.rb'
|
23
|
+
|
18
24
|
##################### Metrics ##################################
|
19
25
|
|
20
26
|
Metrics/AbcSize:
|
data/.travis.yml
CHANGED
@@ -12,9 +12,6 @@ before_script:
|
|
12
12
|
script:
|
13
13
|
- ruby --version
|
14
14
|
- bundle exec rspec
|
15
|
-
branches:
|
16
|
-
only:
|
17
|
-
- master
|
18
15
|
notifications:
|
19
16
|
slack:
|
20
17
|
secure: ocTnQAT5/a3gu93ZZ0vinihMT6/NG3fp4pV2li9WSJRuImFwSTI2eAmjlOZbk/SaZIdj2alGIB2HqMH6sHFheCiUSuAzf+8aaGvBwFh//x+2uibXccoyZLIUoDb5OMHCZSilkQgx8MtsGsPCr+7ryvclxIL+3YJz2NjTpwPPoLsXUNXXzaJtYHknb62BCGGTC5wz8J5JOVKloDXVz4F2CMZqX2ylM/DxFTl5LI94kT/7pv7KfelCHsm6R0F4ALaJT0zumx+t/QAlezzlvRqu81L76yPlEgdahydY77yd7xVqUOEhvNEEiriHMR/+4xYMEieVvERlDLsk4kvywX6YbGId/5tDaQvRIkHIN/9XeKnt/DyMbBVugC0MtZGbNREtD2a9u85V0Zzv/ufBva3FHtbWsHXBtETrb3ty9yrplDkqg/H9vOfISfnSYxOk8F56DMj0h6QSaocCk/9hk31C2I66ZvmmJC5LkSNN77KFT0u32nSFAi5Maj3FhGGW2eXg/jWqBjjyYqUQtjeQguqhtPna5QSpmY17a6l7LAujoQ/romkiEIW+Qwd2tPv53DVe5q1fWNTSrr5LVhkKjkATAWlKLv8oJOj86/EcaoNCZFS7mufq16hDMW9UJbEsuqguRCZKR49FC/U80NWwx+jrkzHY41Meh6yeYd5JQyODb9E=
|
data/README.md
CHANGED
@@ -43,6 +43,7 @@ Example:
|
|
43
43
|
```ruby
|
44
44
|
# catch pattern
|
45
45
|
hear '^hello, slappy!' do |event|
|
46
|
+
logger.info 'received message!'
|
46
47
|
say 'hello!!', channel: event.channel #=> respond message to channel
|
47
48
|
end
|
48
49
|
```
|
@@ -122,22 +123,22 @@ require 'slappy'
|
|
122
123
|
|
123
124
|
# called when start up
|
124
125
|
Slappy.hello do
|
125
|
-
|
126
|
+
Slappy.logger.info 'successfly connected'
|
126
127
|
end
|
127
128
|
|
128
129
|
# called when match message
|
129
130
|
Slappy.hear 'foo' do
|
130
|
-
|
131
|
+
Slappy.logger.info 'foo'
|
131
132
|
end
|
132
133
|
|
133
134
|
# use regexp in string literal
|
134
135
|
Slappy.hear 'bar (.*)' do |event|
|
135
|
-
|
136
|
+
Slappy.logger.info event.matches[1] #=> Event#matches return MatchData object
|
136
137
|
end
|
137
138
|
|
138
139
|
# event object is slack event JSON (convert to Hashie::Mash)
|
139
140
|
Slappy.hear '^bar (.*)' do |event|
|
140
|
-
|
141
|
+
Slappy.logger.info event.channel #=> channel id
|
141
142
|
Slappy.say 'slappy!', channel: event.channel #=> to received message channel
|
142
143
|
Slappy.say 'slappy!', channel: '#general'
|
143
144
|
Slappy.say 'slappy!', username: 'slappy!', icon_emoji: ':slappy:'
|
@@ -145,12 +146,35 @@ end
|
|
145
146
|
|
146
147
|
# use regexp literal
|
147
148
|
Slappy.hear /^foobar/ do
|
148
|
-
|
149
|
+
Slappy.logger.info 'slappppy!'
|
149
150
|
end
|
150
151
|
|
151
152
|
Slappy.start #=> Start slappy process
|
152
153
|
```
|
153
154
|
|
155
|
+
## Release Note
|
156
|
+
|
157
|
+
- v0.4.0
|
158
|
+
- Support logger
|
159
|
+
- Support load lib directory
|
160
|
+
- Add New command
|
161
|
+
- version
|
162
|
+
- Choise dsl enabled in slappy_config
|
163
|
+
|
164
|
+
- v0.3.0
|
165
|
+
- Introduce DSL
|
166
|
+
- Introduce CLI commands
|
167
|
+
- start
|
168
|
+
- new
|
169
|
+
- Use String literal for hear parameter
|
170
|
+
- Chose dsl use in slappy_config
|
171
|
+
|
172
|
+
- v0.2.0
|
173
|
+
- Modify interface
|
174
|
+
|
175
|
+
- v0.1.0
|
176
|
+
- Release
|
177
|
+
|
154
178
|
## Feature
|
155
179
|
|
156
180
|
- [ ] Execute in shell (because testable).
|
data/lib/slappy/cli.rb
CHANGED
@@ -8,6 +8,7 @@ module Slappy
|
|
8
8
|
|
9
9
|
mkdir target_dir unless @target_dir.nil?
|
10
10
|
mkdir scripts_dir_path
|
11
|
+
mkdir lib_dir_path
|
11
12
|
|
12
13
|
copy template_script_path, scripts_dir_path
|
13
14
|
copy config_file_path, target_dir
|
@@ -27,6 +28,10 @@ module Slappy
|
|
27
28
|
File.expand_path 'templates', gem_root_dir
|
28
29
|
end
|
29
30
|
|
31
|
+
def lib_dir_path
|
32
|
+
File.expand_path Slappy.configuration.lib_dir_path, target_dir
|
33
|
+
end
|
34
|
+
|
30
35
|
def scripts_dir_path
|
31
36
|
File.expand_path Slappy.configuration.scripts_dir_path, target_dir
|
32
37
|
end
|
data/lib/slappy/commands/run.rb
CHANGED
@@ -4,7 +4,9 @@ module Slappy
|
|
4
4
|
class InvalidPathError < StandardError; end
|
5
5
|
|
6
6
|
def call
|
7
|
+
load_dsl
|
7
8
|
load_config
|
9
|
+
load_libs
|
8
10
|
load_scripts
|
9
11
|
Slappy.start
|
10
12
|
rescue InvalidPathError => e
|
@@ -13,6 +15,11 @@ module Slappy
|
|
13
15
|
|
14
16
|
private
|
15
17
|
|
18
|
+
def load_dsl
|
19
|
+
return if Slappy.configuration.dsl == :disabled
|
20
|
+
require 'slappy/dsl'
|
21
|
+
end
|
22
|
+
|
16
23
|
def load_config
|
17
24
|
file = File.expand_path Slappy.configuration.config_file_path, Dir.pwd
|
18
25
|
begin
|
@@ -22,18 +29,32 @@ module Slappy
|
|
22
29
|
end
|
23
30
|
end
|
24
31
|
|
25
|
-
def
|
26
|
-
|
32
|
+
def load_directory(dir_name, &block)
|
33
|
+
dir_path = Slappy.configuration.send dir_name.to_sym
|
27
34
|
|
28
|
-
unless FileTest.directory?
|
29
|
-
message = "directory #{
|
35
|
+
unless FileTest.directory? dir_path
|
36
|
+
message = "directory #{dir_path} not found"
|
30
37
|
fail InvalidPathError.new, message
|
31
38
|
end
|
32
39
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
40
|
+
dir_path = "./#{dir_path}" unless dir_path.match(%r{"./"})
|
41
|
+
block.call(dir_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_libs
|
45
|
+
load_directory(:lib_dir_path) do |lib_dir|
|
46
|
+
Dir.glob("#{lib_dir}/**/*.rb").each do |file|
|
47
|
+
require file
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def load_scripts
|
53
|
+
load_directory(:scripts_dir_path) do |script_dir|
|
54
|
+
Dir.glob("#{script_dir}/**/*.rb").each do |file|
|
55
|
+
block = proc { require file }
|
56
|
+
block.call
|
57
|
+
end
|
37
58
|
end
|
38
59
|
end
|
39
60
|
end
|
data/lib/slappy/configuration.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
module Slappy
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :robot, :token, :scripts_dir_path
|
3
|
+
attr_accessor :robot, :token, :scripts_dir_path, :lib_dir_path, :logger
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@robot = Robot.new
|
7
7
|
end
|
8
8
|
|
9
|
+
def logger
|
10
|
+
unless @logger
|
11
|
+
@logger = Logger.new(STDOUT)
|
12
|
+
@logger.level = Logger::INFO
|
13
|
+
end
|
14
|
+
@logger
|
15
|
+
end
|
16
|
+
|
9
17
|
def token
|
10
18
|
@token || ENV['SLACK_TOKEN']
|
11
19
|
end
|
@@ -14,10 +22,22 @@ module Slappy
|
|
14
22
|
'./slappy_config.rb'
|
15
23
|
end
|
16
24
|
|
25
|
+
def lib_dir_path
|
26
|
+
@lib_dir_path || './lib'
|
27
|
+
end
|
28
|
+
|
17
29
|
def scripts_dir_path
|
18
30
|
@scripts_dir_path || './slappy-scripts'
|
19
31
|
end
|
20
32
|
|
33
|
+
def dsl
|
34
|
+
@dsl || :enabled
|
35
|
+
end
|
36
|
+
|
37
|
+
def dsl=(symbol)
|
38
|
+
fail ArgumentError if [:enabled, :disabled].include? symbol
|
39
|
+
end
|
40
|
+
|
21
41
|
def send_params
|
22
42
|
{
|
23
43
|
username: robot.username,
|
data/lib/slappy/dsl.rb
CHANGED
data/lib/slappy/listener.rb
CHANGED
data/lib/slappy/version.rb
CHANGED
data/lib/slappy.rb
CHANGED
@@ -4,10 +4,14 @@ require 'hashie'
|
|
4
4
|
require 'slack'
|
5
5
|
require 'termcolor'
|
6
6
|
require 'thor'
|
7
|
+
require 'logger'
|
7
8
|
|
8
9
|
module Slappy
|
9
10
|
class << self
|
10
|
-
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
def_delegators :configuration, :logger
|
14
|
+
def_delegators :client, :start, :hello, :hear, :say
|
11
15
|
|
12
16
|
def configure
|
13
17
|
@configuration = Configuration.new
|
@@ -21,17 +25,6 @@ module Slappy
|
|
21
25
|
@configuration || configure
|
22
26
|
end
|
23
27
|
|
24
|
-
def method_missing(method, *args, &block)
|
25
|
-
return super unless client.respond_to?(method)
|
26
|
-
client.send(method, *args, &block)
|
27
|
-
end
|
28
|
-
|
29
|
-
def respond_to?(method)
|
30
|
-
client.respond_to?(method) || super
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
28
|
def client
|
36
29
|
@client ||= Client.new
|
37
30
|
end
|
data/templates/slappy_config.rb
CHANGED
@@ -1,16 +1,33 @@
|
|
1
|
-
require 'slappy/dsl'
|
2
|
-
|
3
1
|
Slappy.configure do |config|
|
4
2
|
## Slappy Settings
|
5
3
|
#
|
6
4
|
# token:
|
7
5
|
# Slack API Token
|
8
|
-
|
6
|
+
#
|
7
|
+
# config.token = ENV['SLACK_TOKEN']
|
9
8
|
|
10
9
|
# scripts_path_dir:
|
11
10
|
# Slappy scripts directory.
|
12
11
|
# Slappy load scripts in this directory.
|
13
|
-
|
12
|
+
#
|
13
|
+
# config.scripts_dir_path = 'slappy-scripts'
|
14
|
+
|
15
|
+
# logger:
|
16
|
+
# Use logger object.
|
17
|
+
#
|
18
|
+
# config.logger = Logger.new(STDOUT)
|
19
|
+
|
20
|
+
# logger.level:
|
21
|
+
# Specify logger level.
|
22
|
+
#
|
23
|
+
# config.logger.level = Logger::INFO
|
24
|
+
|
25
|
+
# dsl:
|
26
|
+
# use dsl
|
27
|
+
#
|
28
|
+
# param: :enabled or :disabled
|
29
|
+
#
|
30
|
+
# config.dsl = :enabled
|
14
31
|
|
15
32
|
## Default parameters
|
16
33
|
#
|
@@ -23,18 +40,22 @@ Slappy.configure do |config|
|
|
23
40
|
|
24
41
|
# username:
|
25
42
|
# Name of bot.
|
26
|
-
|
43
|
+
#
|
44
|
+
# config.robot.username = 'slappy'
|
27
45
|
|
28
46
|
# channel:
|
29
47
|
# Channel, private group, or IM channel to send message to.
|
30
48
|
# Can be an encoded ID, or a name. See below for more details.
|
31
|
-
|
49
|
+
#
|
50
|
+
# config.robot.channel = nil
|
32
51
|
|
33
52
|
# icon_emoji:
|
34
53
|
# emoji to use as the icon for this message. Overrides icon_url.
|
35
|
-
|
54
|
+
#
|
55
|
+
# config.robot.icon_emoji = nil
|
36
56
|
|
37
57
|
# icon_url:
|
38
58
|
# URL to an image to use as the icon for this message
|
39
|
-
|
59
|
+
#
|
60
|
+
# config.robot.icon_url = nil
|
40
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slappy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wakaba260
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-api
|