slack-ruby-bot 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +39 -44
- data/examples/minimal/pongbot.rb +4 -9
- data/examples/weather/weatherbot.rb +4 -9
- data/lib/slack-ruby-bot.rb +1 -0
- data/lib/slack-ruby-bot/bot.rb +7 -0
- data/lib/slack-ruby-bot/version.rb +1 -1
- data/spec/slack-ruby-bot/commands/bot_spec.rb +19 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d913551cd5d7c5dd77eca6b408afc4f429db43dc
|
4
|
+
data.tar.gz: 5e96cb15043a4cf9cd39a661182ba0a1320872a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e01fadbae26b2a4bb53794dbe587b635b72ec30dc1b1d18cab3a71adbf061446084890ad9851c9814336ed09c6f48589fa76a82498010ce5f00ebb21dacb3034
|
7
|
+
data.tar.gz: 19df60970882c526023310c6b33aae3f7c8236f71aa59aae0ec741290bc0fb6ffb27a2ddef1bd757483a49ad73109661cc3ddf620531b806a67157d9829b8bf7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,7 @@ A generic Slack bot framework written in Ruby on top of [slack-ruby-client](http
|
|
17
17
|
|
18
18
|
## Stable Release
|
19
19
|
|
20
|
-
You're reading the documentation for the **stable** release of slack-ruby-bot, 0.5.
|
20
|
+
You're reading the documentation for the **stable** release of slack-ruby-bot, 0.5.5.
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
@@ -36,18 +36,13 @@ gem 'slack-ruby-bot'
|
|
36
36
|
```ruby
|
37
37
|
require 'slack-ruby-bot'
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
class Ping < SlackRubyBot::Commands::Base
|
44
|
-
command 'ping' do |client, data, _match|
|
45
|
-
client.message text: 'pong', channel: data.channel
|
46
|
-
end
|
39
|
+
class PongBot < SlackRubyBot::Bot
|
40
|
+
command 'ping' do |client, data, match|
|
41
|
+
client.message text: 'pong', channel: data.channel
|
47
42
|
end
|
48
43
|
end
|
49
44
|
|
50
|
-
PongBot
|
45
|
+
PongBot.run
|
51
46
|
```
|
52
47
|
|
53
48
|
After [registering the bot](DEPLOYMENT.md), run with `SLACK_API_TOKEN=... bundle exec ruby pongbot.rb`. Have the bot join a channel and send it a ping.
|
@@ -70,38 +65,13 @@ The following examples of bots based on slack-ruby-bot are listed in growing ord
|
|
70
65
|
|
71
66
|
### Commands and Operators
|
72
67
|
|
73
|
-
Bots are addressed by name, they respond to commands and operators.
|
74
|
-
|
75
|
-
```ruby
|
76
|
-
class Phone < SlackRubyBot::Commands::Base
|
77
|
-
command 'call'
|
78
|
-
|
79
|
-
def self.call(client, data, _match)
|
80
|
-
send_message client, data.channel, 'called'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
```
|
84
|
-
|
85
|
-
To respond to custom commands and to disable automatic class name matching, use the `command` keyword. The following command responds to `call` and `呼び出し` (call in Japanese).
|
86
|
-
|
87
|
-
```ruby
|
88
|
-
class Phone < SlackRubyBot::Commands::Base
|
89
|
-
command 'call'
|
90
|
-
command '呼び出し'
|
91
|
-
|
92
|
-
def self.call(client, data, _match)
|
93
|
-
send_message client, data.channel, 'called'
|
94
|
-
end
|
95
|
-
end
|
96
|
-
```
|
68
|
+
Bots are addressed by name, they respond to commands and operators.
|
97
69
|
|
98
70
|
You can combine multiple commands and use a block to implement them.
|
99
71
|
|
100
72
|
```ruby
|
101
|
-
|
102
|
-
|
103
|
-
send_message client, data.channel, 'called'
|
104
|
-
end
|
73
|
+
command 'call', '呼び出し' do |client, data, match|
|
74
|
+
send_message client, data.channel, 'called'
|
105
75
|
end
|
106
76
|
```
|
107
77
|
|
@@ -110,10 +80,8 @@ Command match data includes `match['bot']`, `match['command']` and `match['expre
|
|
110
80
|
Operators are 1-letter long and are similar to commands. They don't require addressing a bot nor separating an operator from its arguments. The following class responds to `=2+2`.
|
111
81
|
|
112
82
|
```ruby
|
113
|
-
|
114
|
-
|
115
|
-
# implementation detail
|
116
|
-
end
|
83
|
+
operator '=' do |data, match|
|
84
|
+
# implementation detail
|
117
85
|
end
|
118
86
|
```
|
119
87
|
|
@@ -146,7 +114,7 @@ Bots also will respond to a direct message, with or without the bot name in the
|
|
146
114
|
Commands and operators are generic versions of bot routes. You can respond to just about anything by defining a custom route.
|
147
115
|
|
148
116
|
```ruby
|
149
|
-
class Weather < SlackRubyBot::
|
117
|
+
class Weather < SlackRubyBot::Bot
|
150
118
|
match /^How is the weather in (?<location>\w*)\?$/ do |client, data, match|
|
151
119
|
send_message client, data.channel, "The weather in #{match[:location]} is nice."
|
152
120
|
end
|
@@ -155,7 +123,34 @@ end
|
|
155
123
|
|
156
124
|
![](screenshots/weather.gif)
|
157
125
|
|
158
|
-
### SlackRubyBot::Commands::Base
|
126
|
+
### SlackRubyBot::Commands::Base
|
127
|
+
|
128
|
+
The `SlackRubyBot::Bot` class is just sugare deriving from `SlackRubyBot::Commands::Base`. You can divide the bot implementation into subclasses of `SlackRubyBot::Commands::Base` manually. By default a command class responds, case-insensitively, to its name. A class called `Phone` that inherits from `SlackRubyBot::Commands::Base` responds to `phone` and `Phone` and calls the `call` method when implemented.
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
class Phone < SlackRubyBot::Commands::Base
|
132
|
+
command 'call'
|
133
|
+
|
134
|
+
def self.call(client, data, match)
|
135
|
+
send_message client, data.channel, 'called'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
```
|
139
|
+
|
140
|
+
To respond to custom commands and to disable automatic class name matching, use the `command` keyword. The following command responds to `call` and `呼び出し` (call in Japanese).
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
class Phone < SlackRubyBot::Commands::Base
|
144
|
+
command 'call'
|
145
|
+
command '呼び出し'
|
146
|
+
|
147
|
+
def self.call(client, data, match)
|
148
|
+
send_message client, data.channel, 'called'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
```
|
152
|
+
|
153
|
+
Other available functions include the following.
|
159
154
|
|
160
155
|
#### send_message(client, channel, text)
|
161
156
|
|
data/examples/minimal/pongbot.rb
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
require 'slack-ruby-bot'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
class Ping < SlackRubyBot::Commands::Base
|
8
|
-
def self.call(client, data, _match)
|
9
|
-
client.message text: 'pong', channel: data.channel
|
10
|
-
end
|
3
|
+
class Bot < SlackRubyBot::Bot
|
4
|
+
command 'ping' do |client, data, _match|
|
5
|
+
client.message text: 'pong', channel: data.channel
|
11
6
|
end
|
12
7
|
end
|
13
8
|
|
14
|
-
|
9
|
+
Bot.run
|
@@ -1,14 +1,9 @@
|
|
1
1
|
require 'slack-ruby-bot'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
class Weather < SlackRubyBot::Commands::Base
|
8
|
-
match(/^How is the weather in (?<location>\w*)\?$/i) do |client, data, match|
|
9
|
-
send_message client, data.channel, "The weather in #{match[:location]} is nice."
|
10
|
-
end
|
3
|
+
class WeatherBot < SlackRubyBot::Bot
|
4
|
+
match(/^How is the weather in (?<location>\w*)\?$/i) do |client, data, match|
|
5
|
+
send_message client, data.channel, "The weather in #{match[:location]} is nice."
|
11
6
|
end
|
12
7
|
end
|
13
8
|
|
14
|
-
WeatherBot
|
9
|
+
WeatherBot.run
|
data/lib/slack-ruby-bot.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SlackRubyBot::Bot do
|
4
|
+
let! :command do
|
5
|
+
Class.new(SlackRubyBot::Bot) do
|
6
|
+
command 'bot_spec' do |client, data, match|
|
7
|
+
send_message client, data.channel, match['expression']
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
def app
|
12
|
+
SlackRubyBot::App.new
|
13
|
+
end
|
14
|
+
let(:client) { app.send(:client) }
|
15
|
+
it 'sends a message' do
|
16
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
|
17
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} bot_spec message", channel: 'channel', user: 'user')
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-ruby-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -198,6 +198,7 @@ files:
|
|
198
198
|
- lib/slack-ruby-bot.rb
|
199
199
|
- lib/slack-ruby-bot/about.rb
|
200
200
|
- lib/slack-ruby-bot/app.rb
|
201
|
+
- lib/slack-ruby-bot/bot.rb
|
201
202
|
- lib/slack-ruby-bot/client.rb
|
202
203
|
- lib/slack-ruby-bot/commands.rb
|
203
204
|
- lib/slack-ruby-bot/commands/about.rb
|
@@ -232,6 +233,7 @@ files:
|
|
232
233
|
- spec/slack-ruby-bot/app_spec.rb
|
233
234
|
- spec/slack-ruby-bot/commands/about_spec.rb
|
234
235
|
- spec/slack-ruby-bot/commands/aliases_spec.rb
|
236
|
+
- spec/slack-ruby-bot/commands/bot_spec.rb
|
235
237
|
- spec/slack-ruby-bot/commands/commands_precedence_spec.rb
|
236
238
|
- spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb
|
237
239
|
- spec/slack-ruby-bot/commands/commands_spaces_spec.rb
|
@@ -284,6 +286,7 @@ test_files:
|
|
284
286
|
- spec/slack-ruby-bot/app_spec.rb
|
285
287
|
- spec/slack-ruby-bot/commands/about_spec.rb
|
286
288
|
- spec/slack-ruby-bot/commands/aliases_spec.rb
|
289
|
+
- spec/slack-ruby-bot/commands/bot_spec.rb
|
287
290
|
- spec/slack-ruby-bot/commands/commands_precedence_spec.rb
|
288
291
|
- spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb
|
289
292
|
- spec/slack-ruby-bot/commands/commands_spaces_spec.rb
|