slack-ruby-bot 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3365b0c48f85bc8a707d27d21ff1e955754e5bcf
4
- data.tar.gz: ef53963a3d19a9f70ebfee939121e1dbb6c49a93
3
+ metadata.gz: 27ef75b4d9ac822b0386b61c6cb4f868e50ab886
4
+ data.tar.gz: 0935126c87fc8d94e6f0040bd5036d4aebbab722
5
5
  SHA512:
6
- metadata.gz: 4fe517f5e5a0a51cf1c1d5d2355b5fe21e58c6f8f0059bc62e2cccdfb932a0b1e8b6d1b177874920e59f502bbc495c447ab106df130b15a09c6d2ea9bb1a17b4
7
- data.tar.gz: 08a92f29fc40b4d64d9fc8898eaf8bdf7c6f527ee0d488ae8be76fcb691567097f1412f8094c6876b4022e4a3259b1d6aa0a9f61536a1ec13ab0b2684f502a17
6
+ metadata.gz: be49d4c6780e9c79189b9b8912ab11e4ef480c60aacb43a88b51c4dcfb3dbaedf427a20ec377ec9489c7fa93f995ac49c87560d25100fced8e219c26c5e0c02d
7
+ data.tar.gz: f5b292868182f92738cf452310edcab0ddbcb5ac3e4d2f9b1a331e171f56a6d0cca33c3c875d77d6ea01fd124d08159ebd7b531a66c1d24ebc6ef1a8a8449455
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.4.2 (8/20/2015)
2
+
3
+ * [#12](https://github.com/dblock/slack-ruby-bot/issues/12): Added support for bot aliases - [@dblock](https://githubcom/dblock).
4
+
1
5
  ### 0.4.1 (7/25/2015)
2
6
 
3
7
  * Use a real client in `respond_with_slack_message` expectaions - [@dblock](https://githubcom/dblock).
@@ -9,7 +13,7 @@
9
13
 
10
14
  ### 0.3.1 (7/21/2015)
11
15
 
12
- * [#8](https://github.com/dblock/slack-ruby-bot/issues/8): Fix: `undefined method `strip!' for nil:NilClass` on nil message - [@dblock](https://github.com/dblock).
16
+ * [#8](https://github.com/dblock/slack-ruby-bot/issues/8): Fix: `undefined method 'strip!' for nil:NilClass` on nil message - [@dblock](https://github.com/dblock).
13
17
 
14
18
  ### 0.3.0 (7/19/2015)
15
19
 
data/DEPLOYMENT.md CHANGED
@@ -20,6 +20,14 @@ heroku config:add SLACK_API_TOKEN=...
20
20
 
21
21
  The bot replies with animated GIFs. While it's currently not necessary, you may need to set GIPHY_API_KEY in the future, see [github.com/Giphy/GiphyAPI](https://github.com/Giphy/GiphyAPI) for details.
22
22
 
23
+ #### SLACK_RUBY_BOT_ALIASES
24
+
25
+ Optional names for this bot.
26
+
27
+ ```
28
+ heroku config:add SLACK_RUBY_BOT_ALIASES=:pong: table-tennis ping-pong
29
+ ```
30
+
23
31
  ### Heroku Idling
24
32
 
25
33
  Heroku free tier applications will idle. Either pay 7$ a month for the hobby dyno or use [UptimeRobot](http://uptimerobot.com) or similar to prevent your instance from sleeping or pay for a production dyno.
data/README.md CHANGED
@@ -4,7 +4,7 @@ Slack-Ruby-Bot
4
4
  [![Gem Version](https://badge.fury.io/rb/slack-ruby-bot.svg)](http://badge.fury.io/rb/slack-ruby-bot)
5
5
  [![Build Status](https://travis-ci.org/dblock/slack-ruby-bot.png)](https://travis-ci.org/dblock/slack-ruby-bot)
6
6
 
7
- A generic Slack bot framework written in Ruby. This library does all the heavy lifting so you can focus on implementing slack bot commands, without introducing unnecessary requirements or limitations. It's a Slack bot boilerplate.
7
+ A generic Slack bot framework written in Ruby on top of [slack-ruby-client](https://github.com/dblock/slack-ruby-client). This library does all the heavy lifting, such as message parsing, so you can focus on implementing slack bot commands. It also attempts to itroduce the bare minimum number of requirements or any sorts of limitations. It's a Slack bot boilerplate.
8
8
 
9
9
  ## Usage
10
10
 
@@ -37,7 +37,7 @@ end
37
37
  PongBot::App.instance.run
38
38
  ```
39
39
 
40
- After [registering the bot](DEPLOYMENT.md), run with `SLACK_API_KEY=... bundle exec ruby pongbot.rb`. Have the bot join a channel and send it a ping.
40
+ 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.
41
41
 
42
42
  ![](screenshots/demo.gif)
43
43
 
@@ -50,6 +50,7 @@ A typical production Slack bot is a combination of a vanilla web server and a we
50
50
  The following examples of production-grade bots based on slack-ruby-bot are listed in growing order of complexity.
51
51
 
52
52
  * [slack-mathbot](https://github.com/dblock/slack-mathbot): Slack integration with math.
53
+ * [slack-google-bot](https://github.com/dblock/slack-google-bot): A Slack bot that searches Google, including CSE.
53
54
  * [slack-aws](https://github.com/dblock/slack-aws): Slack integration with Amazon Web Services.
54
55
  * [slack-gamebot](https://github.com/dblock/slack-gamebot): A generic game bot for ping-pong, chess, etc.
55
56
 
@@ -104,6 +105,24 @@ end
104
105
 
105
106
  Operator match data includes `match['operator']` and `match['expression']`. The `bot` match always checks against the `SlackRubyBot::Config.user` setting.
106
107
 
108
+ ### Bot Aliases
109
+
110
+ A bot will always respond to its name, but you can specify multiple aliases via the `SLACK_RUBY_BOT_ALIASES` environment variable or via an explicit configuration.
111
+
112
+ ```
113
+ SLACK_RUBY_BOT_ALIASES=:pp: table-tennis
114
+ ```
115
+
116
+ ```ruby
117
+ SlackRubyBot.configure do |config|
118
+ config.aliases = [':pong:', 'pongbot']
119
+ end
120
+ ```
121
+
122
+ This is particularly fun with emoji.
123
+
124
+ ![](screenshots/alias.gif)
125
+
107
126
  ### Generic Routing
108
127
 
109
128
  Commands and operators are generic versions of bot routes. You can respond to just about anything by defining a custom route.
@@ -162,6 +181,6 @@ See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING
162
181
 
163
182
  ## Copyright and License
164
183
 
165
- Copyright (c) 2015, Daniel Doubrovkine, Artsy and [Contributors](CHANGELOG.md).
184
+ Copyright (c) 2015, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
166
185
 
167
186
  This project is licensed under the [MIT License](LICENSE.md).
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- slack-ruby-bot (0.3.2)
4
+ slack-ruby-bot (0.4.2)
5
5
  activesupport
6
6
  giphy (~> 2.0.2)
7
7
  hashie
@@ -18,7 +18,7 @@ GEM
18
18
  thread_safe (~> 0.3, >= 0.3.4)
19
19
  tzinfo (~> 1.1)
20
20
  addressable (2.3.8)
21
- eventmachine (1.0.7)
21
+ eventmachine (1.0.8)
22
22
  faraday (0.9.1)
23
23
  multipart-post (>= 1.2, < 3)
24
24
  faraday_middleware (0.9.2)
@@ -40,10 +40,10 @@ GEM
40
40
  json (1.8.3)
41
41
  launchy (2.4.3)
42
42
  addressable (~> 2.3)
43
- minitest (5.7.0)
43
+ minitest (5.8.0)
44
44
  multipart-post (2.0.0)
45
- oj (2.12.10)
46
- slack-ruby-client (0.1.0)
45
+ oj (2.12.12)
46
+ slack-ruby-client (0.2.1)
47
47
  eventmachine
48
48
  faraday
49
49
  faraday_middleware
@@ -60,3 +60,6 @@ PLATFORMS
60
60
 
61
61
  DEPENDENCIES
62
62
  slack-ruby-bot!
63
+
64
+ BUNDLED WITH
65
+ 1.10.6
@@ -8,6 +8,7 @@ module SlackRubyBot
8
8
  def initialize
9
9
  SlackRubyBot.configure do |config|
10
10
  config.token = ENV['SLACK_API_TOKEN'] || fail("Missing ENV['SLACK_API_TOKEN'].")
11
+ config.aliases = ENV['SLACK_RUBY_BOT_ALIASES'].split(' ') if ENV['SLACK_RUBY_BOT_ALIASES']
11
12
  end
12
13
  Slack.configure do |config|
13
14
  config.token = SlackRubyBot.config.token
@@ -41,8 +41,8 @@ module SlackRubyBot
41
41
 
42
42
  def self.command(*values, &block)
43
43
  values.each do |value|
44
- match Regexp.new("^(?<bot>\\w*)[\\s]+(?<command>#{value})$", Regexp::IGNORECASE), &block
45
- match Regexp.new("^(?<bot>\\w*)[\\s]+(?<command>#{value})[\\s]+(?<expression>.*)$", Regexp::IGNORECASE), &block
44
+ match Regexp.new("^(?<bot>[\\w[:punct:]]*)[\\s]+(?<command>#{value})$", Regexp::IGNORECASE), &block
45
+ match Regexp.new("^(?<bot>[\\w[:punct:]]*)[\\s]+(?<command>#{value})[\\s]+(?<expression>.*)$", Regexp::IGNORECASE), &block
46
46
  end
47
47
  end
48
48
 
@@ -53,7 +53,7 @@ module SlackRubyBot
53
53
  routes.each_pair do |route, method|
54
54
  match = route.match(expression)
55
55
  next unless match
56
- next if match.names.include?('bot') && match['bot'].downcase != SlackRubyBot.config.user
56
+ next if match.names.include?('bot') && !SlackRubyBot.config.name?(match['bot'])
57
57
  called = true
58
58
  if method
59
59
  method.call(client, data, match)
@@ -4,10 +4,18 @@ module SlackRubyBot
4
4
 
5
5
  attr_accessor :token
6
6
  attr_accessor :url
7
+ attr_accessor :aliases
7
8
  attr_accessor :user
8
9
  attr_accessor :user_id
9
10
  attr_accessor :team
10
11
  attr_accessor :team_id
11
- attr_accessor :secret
12
+
13
+ def names
14
+ [user, aliases].compact.flatten
15
+ end
16
+
17
+ def name?(name)
18
+ name && names.include?(name.downcase)
19
+ end
12
20
  end
13
21
  end
@@ -1,3 +1,3 @@
1
1
  module SlackRubyBot
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
Binary file
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe SlackRubyBot do
4
+ def app
5
+ SlackRubyBot::App.new
6
+ end
7
+ before do
8
+ ENV['SLACK_RUBY_BOT_ALIASES'] = ':emoji: alias'
9
+ end
10
+ after do
11
+ ENV.delete('SLACK_RUBY_BOT_ALIASES')
12
+ end
13
+ it 'responds to emoji' do
14
+ expect(message: ':emoji: hi').to respond_with_slack_message('Hi <@user>!')
15
+ end
16
+ it 'responds to an alias' do
17
+ expect(message: 'alias hi').to respond_with_slack_message('Hi <@user>!')
18
+ end
19
+ end
metadata CHANGED
@@ -1,153 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-26 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: slack-ruby-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: giphy
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.0.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.0.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: websocket-driver
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.5.4
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.5.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rack-test
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: vcr
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: webmock
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
@@ -170,11 +170,11 @@ executables: []
170
170
  extensions: []
171
171
  extra_rdoc_files: []
172
172
  files:
173
- - ".gitignore"
174
- - ".rspec"
175
- - ".rubocop.yml"
176
- - ".rubocop_todo.yml"
177
- - ".travis.yml"
173
+ - .gitignore
174
+ - .rspec
175
+ - .rubocop.yml
176
+ - .rubocop_todo.yml
177
+ - .travis.yml
178
178
  - CHANGELOG.md
179
179
  - CONTRIBUTING.md
180
180
  - DEPLOYMENT.md
@@ -218,12 +218,14 @@ files:
218
218
  - lib/slack-ruby-bot/rspec/support/vcr.rb
219
219
  - lib/slack-ruby-bot/version.rb
220
220
  - lib/slack_ruby_bot.rb
221
+ - screenshots/aliases.gif
221
222
  - screenshots/demo.gif
222
223
  - screenshots/register-bot.png
223
224
  - screenshots/weather.gif
224
225
  - slack-ruby-bot.gemspec
225
226
  - spec/slack-ruby-bot/app_spec.rb
226
227
  - spec/slack-ruby-bot/commands/about_spec.rb
228
+ - spec/slack-ruby-bot/commands/aliases_spec.rb
227
229
  - spec/slack-ruby-bot/commands/commands_precedence_spec.rb
228
230
  - spec/slack-ruby-bot/commands/commands_spaces_spec.rb
229
231
  - spec/slack-ruby-bot/commands/commands_spec.rb
@@ -249,23 +251,24 @@ require_paths:
249
251
  - lib
250
252
  required_ruby_version: !ruby/object:Gem::Requirement
251
253
  requirements:
252
- - - ">="
254
+ - - '>='
253
255
  - !ruby/object:Gem::Version
254
256
  version: '0'
255
257
  required_rubygems_version: !ruby/object:Gem::Requirement
256
258
  requirements:
257
- - - ">="
259
+ - - '>='
258
260
  - !ruby/object:Gem::Version
259
261
  version: 1.3.6
260
262
  requirements: []
261
263
  rubyforge_project:
262
- rubygems_version: 2.2.2
264
+ rubygems_version: 2.4.5
263
265
  signing_key:
264
266
  specification_version: 4
265
267
  summary: The easiest way to write a Slack bot in Ruby.
266
268
  test_files:
267
269
  - spec/slack-ruby-bot/app_spec.rb
268
270
  - spec/slack-ruby-bot/commands/about_spec.rb
271
+ - spec/slack-ruby-bot/commands/aliases_spec.rb
269
272
  - spec/slack-ruby-bot/commands/commands_precedence_spec.rb
270
273
  - spec/slack-ruby-bot/commands/commands_spaces_spec.rb
271
274
  - spec/slack-ruby-bot/commands/commands_spec.rb