simple-slack-bot 0.1.2 → 0.2.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 +4 -4
- data/lib/{simple-slack-bot.rb → simple_slack_bot.rb} +1 -2
- data/lib/simple_slack_bot/client.rb +7 -13
- data/lib/simple_slack_bot/command.rb +3 -8
- data/lib/simple_slack_bot/config.rb +11 -12
- data/lib/simple_slack_bot/version.rb +1 -1
- data/spec/client_spec.rb +17 -1
- data/spec/command_spec.rb +22 -1
- data/spec/config_spec.rb +4 -4
- data/spec/spec_helper.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d15f1598ca875b032dfc8787c8250ce28f17abd5
|
4
|
+
data.tar.gz: 20e89ad5e2b92a6e90843724b9d99d55414247ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb2a1a16fd9bde84219e65ea4ed2e6a64e93af1d2742811f4fdd891525d6de1de3d711d4c88c6536fe6f87c59957c9350ed5dec24e344ff8600886f7f7d83f3a
|
7
|
+
data.tar.gz: f90813d74d3c415d7a4747013f5eac1891a0857e1b70576d4152b924ca885944524b8c6d4c7f0b624f4947e1351fe26be64e78a931e693d17d3b2fb124d9df81
|
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
1
|
require 'slack-ruby-client'
|
3
2
|
|
4
3
|
module SlackBot
|
5
|
-
|
6
4
|
class Client
|
7
5
|
attr_accessor :slack_web_client, :slack_realtime_client
|
8
6
|
attr_accessor :commands
|
@@ -15,9 +13,7 @@ module SlackBot
|
|
15
13
|
def add_command(regex)
|
16
14
|
command = Command.new(self)
|
17
15
|
command.regex = regex
|
18
|
-
command.action =
|
19
|
-
yield(data)
|
20
|
-
}
|
16
|
+
command.action = -> (data) { yield(data) }
|
21
17
|
@commands << command
|
22
18
|
end
|
23
19
|
|
@@ -27,8 +23,8 @@ module SlackBot
|
|
27
23
|
return
|
28
24
|
end
|
29
25
|
|
30
|
-
|
31
|
-
|
26
|
+
slack_init
|
27
|
+
message_event_init
|
32
28
|
|
33
29
|
EM.run do
|
34
30
|
@slack_realtime_client.start!
|
@@ -73,16 +69,14 @@ module SlackBot
|
|
73
69
|
puts data if config.debug.eql?(true)
|
74
70
|
|
75
71
|
case data['subtype']
|
76
|
-
|
77
|
-
|
72
|
+
when 'channel_join' then
|
73
|
+
client.message channel: data['channel'], text: config.join_message
|
78
74
|
end
|
79
75
|
|
80
76
|
@commands.each do |command|
|
81
|
-
if command.match?(data['text'])
|
82
|
-
command.execute(data)
|
83
|
-
end
|
77
|
+
command.execute(data) if command.match?(data['text'])
|
84
78
|
end
|
85
79
|
end
|
86
80
|
end
|
87
81
|
end
|
88
|
-
end
|
82
|
+
end
|
@@ -1,18 +1,13 @@
|
|
1
|
-
|
2
1
|
module SlackBot
|
3
2
|
class Command
|
4
|
-
attr_accessor :bot_client
|
5
|
-
attr_accessor :regex
|
6
|
-
attr_accessor :help_message
|
7
|
-
attr_accessor :action
|
3
|
+
attr_accessor :bot_client, :regex, :help_message, :action
|
8
4
|
|
9
5
|
def initialize(bot_client)
|
10
6
|
@bot_client = bot_client
|
11
7
|
end
|
12
8
|
|
13
9
|
def match?(str)
|
14
|
-
|
15
|
-
true
|
10
|
+
(@regex.nil? || @regex.match(str).nil?) ? false : true
|
16
11
|
end
|
17
12
|
|
18
13
|
def execute(data)
|
@@ -20,4 +15,4 @@ module SlackBot
|
|
20
15
|
@action.call(data)
|
21
16
|
end
|
22
17
|
end
|
23
|
-
end
|
18
|
+
end
|
@@ -1,12 +1,11 @@
|
|
1
|
-
|
2
1
|
module SlackBot
|
3
2
|
module Config
|
4
3
|
extend self
|
5
4
|
|
6
5
|
ATTRIBUTES = [
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
:debug,
|
7
|
+
:join_message,
|
8
|
+
:token
|
10
9
|
]
|
11
10
|
|
12
11
|
attr_accessor(*Config::ATTRIBUTES)
|
@@ -16,13 +15,13 @@ module SlackBot
|
|
16
15
|
self.token = 'TOKEN'
|
17
16
|
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
module_function
|
19
|
+
|
20
|
+
def configure
|
21
|
+
block_given? ? yield(Config) : Config
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
24
|
+
def config
|
25
|
+
Config
|
27
26
|
end
|
28
|
-
end
|
27
|
+
end
|
data/spec/client_spec.rb
CHANGED
@@ -1,2 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
|
2
|
-
|
3
|
+
describe SlackBot::Client do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'have an empty commands array' do
|
6
|
+
expect(SlackBot::Client.new.commands).to eq []
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.add_command' do
|
11
|
+
bot = SlackBot::Client.new
|
12
|
+
|
13
|
+
it 'add command to commands array' do
|
14
|
+
result = bot.add_command('Hello')
|
15
|
+
expect(result).to eq bot.commands
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/command_spec.rb
CHANGED
@@ -1,2 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
|
2
|
-
|
3
|
+
describe SlackBot::Command do
|
4
|
+
describe '#initialize' do
|
5
|
+
bot = SlackBot::Client.new
|
6
|
+
|
7
|
+
it 'have a bot_client' do
|
8
|
+
command = SlackBot::Command.new(bot)
|
9
|
+
expect(command.bot_client).to eq bot
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.match?' do
|
14
|
+
bot = SlackBot::Client.new
|
15
|
+
bot.add_command('Hello')
|
16
|
+
|
17
|
+
it 'iterate commands' do
|
18
|
+
bot.commands.each do |command|
|
19
|
+
expect(command.regex).to eq 'Hello'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/config_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe SlackBot::Config do
|
4
4
|
describe '#initialize' do
|
5
5
|
it 'sets config' do
|
6
|
-
expect(SlackBot
|
7
|
-
expect(SlackBot
|
8
|
-
expect(SlackBot
|
6
|
+
expect(SlackBot.config.join_message).to eq 'Hello!'
|
7
|
+
expect(SlackBot.config.debug).to eq false
|
8
|
+
expect(SlackBot.config.token).to eq 'TOKEN'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -24,4 +24,4 @@ describe SlackBot::Config do
|
|
24
24
|
expect(SlackBot.config.token).to eq 'Invalid Token'
|
25
25
|
end
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-slack-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Sun-Hyoup
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-client
|
@@ -115,7 +115,7 @@ files:
|
|
115
115
|
- README.md
|
116
116
|
- Rakefile
|
117
117
|
- images/preview.gif
|
118
|
-
- lib/
|
118
|
+
- lib/simple_slack_bot.rb
|
119
119
|
- lib/simple_slack_bot/client.rb
|
120
120
|
- lib/simple_slack_bot/command.rb
|
121
121
|
- lib/simple_slack_bot/config.rb
|