slack-ruby-bot 0.1.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 +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +41 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTING.md +139 -0
- data/DEPLOYMENT.md +25 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +107 -0
- data/LICENSE.md +22 -0
- data/README.md +69 -0
- data/Rakefile +19 -0
- data/examples/minimal/Gemfile +3 -0
- data/examples/minimal/Gemfile.lock +62 -0
- data/examples/minimal/pongbot.rb +14 -0
- data/lib/config/application.rb +14 -0
- data/lib/config/boot.rb +8 -0
- data/lib/config/environment.rb +3 -0
- data/lib/initializers/giphy.rb +3 -0
- data/lib/initializers/slack/request.rb +13 -0
- data/lib/slack-ruby-bot/about.rb +7 -0
- data/lib/slack-ruby-bot/app.rb +83 -0
- data/lib/slack-ruby-bot/commands/about.rb +9 -0
- data/lib/slack-ruby-bot/commands/base.rb +27 -0
- data/lib/slack-ruby-bot/commands/help.rb +9 -0
- data/lib/slack-ruby-bot/commands/hi.rb +9 -0
- data/lib/slack-ruby-bot/commands/unknown.rb +9 -0
- data/lib/slack-ruby-bot/commands.rb +5 -0
- data/lib/slack-ruby-bot/config.rb +13 -0
- data/lib/slack-ruby-bot/fixtures/slack/auth_test.yml +48 -0
- data/lib/slack-ruby-bot/hooks/base.rb +10 -0
- data/lib/slack-ruby-bot/hooks/hello.rb +11 -0
- data/lib/slack-ruby-bot/hooks/message.rb +41 -0
- data/lib/slack-ruby-bot/hooks.rb +3 -0
- data/lib/slack-ruby-bot/rspec/fixtures/slack/auth_test.yml +48 -0
- data/lib/slack-ruby-bot/rspec/support/fixtures/slack/auth_test.yml +103 -0
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb +27 -0
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +31 -0
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +19 -0
- data/lib/slack-ruby-bot/rspec/support/slack_api_key.rb +5 -0
- data/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb +4 -0
- data/lib/slack-ruby-bot/rspec/support/vcr.rb +8 -0
- data/lib/slack-ruby-bot/rspec.rb +12 -0
- data/lib/slack-ruby-bot/version.rb +3 -0
- data/lib/slack-ruby-bot.rb +20 -0
- data/lib/slack_ruby_bot.rb +1 -0
- data/screenshots/register-bot.png +0 -0
- data/slack-ruby-bot.gemspec +27 -0
- data/spec/slack-ruby-bot/app_spec.rb +8 -0
- data/spec/slack-ruby-bot/commands/about_spec.rb +16 -0
- data/spec/slack-ruby-bot/commands/help_spec.rb +13 -0
- data/spec/slack-ruby-bot/commands/hi_spec.rb +13 -0
- data/spec/slack-ruby-bot/commands/unknown_spec.rb +17 -0
- data/spec/slack-ruby-bot/version_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -0
- metadata +246 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 579866b4a7f11a4724bba648eff1b7f47b062b6b
|
4
|
+
data.tar.gz: f14a5617e66ee1b851ec2f9f083f874023fa7b80
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8571d406cb61c2b7ea7bd66a06cd6eeb7897be28c480e34441fc2530774cd4f053ca6d58b8261c42f3487e8e93a4eaecf3b27bdf7abc7c98b775e8a93450da63
|
7
|
+
data.tar.gz: 12dd65f281d52c45f5af250aad0db8536cb878bd5f26c7e156cd4dbd4403d75371f2eefdd13f1d716107b9c95697e6b6209d30343f4ee3203439d619e71ea110
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.env
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-07-02 14:33:13 -0400 using RuboCop version 0.32.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 1
|
9
|
+
Lint/HandleExceptions:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
# Offense count: 2
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Max: 21
|
15
|
+
|
16
|
+
# Offense count: 1
|
17
|
+
Metrics/CyclomaticComplexity:
|
18
|
+
Max: 7
|
19
|
+
|
20
|
+
# Offense count: 18
|
21
|
+
# Configuration parameters: AllowURI, URISchemes.
|
22
|
+
Metrics/LineLength:
|
23
|
+
Max: 130
|
24
|
+
|
25
|
+
# Offense count: 1
|
26
|
+
# Configuration parameters: CountComments.
|
27
|
+
Metrics/MethodLength:
|
28
|
+
Max: 17
|
29
|
+
|
30
|
+
# Offense count: 14
|
31
|
+
Style/Documentation:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
# Offense count: 1
|
35
|
+
# Configuration parameters: Exclude.
|
36
|
+
Style/FileName:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
# Offense count: 1
|
40
|
+
Style/ModuleFunction:
|
41
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
# Contributing to SlackRubyBot
|
2
|
+
|
3
|
+
This project is work of [many contributors](https://github.com/dblock/slack-ruby-bot/graphs/contributors).
|
4
|
+
|
5
|
+
You're encouraged to submit [pull requests](https://github.com/dblock/slack-ruby-bot/pulls), [propose features and discuss issues](https://github.com/dblock/slack-ruby-bot/issues).
|
6
|
+
|
7
|
+
In the examples below, substitute your Github username for `contributor` in URLs.
|
8
|
+
|
9
|
+
## Fork the Project
|
10
|
+
|
11
|
+
Fork the [project on Github](https://github.com/dblock/slack-ruby-bot) and check out your copy.
|
12
|
+
|
13
|
+
```
|
14
|
+
git clone https://github.com/contributor/slack-ruby-bot.git
|
15
|
+
cd slack-ruby-bot
|
16
|
+
git remote add upstream https://github.com/dblock/slack-ruby-bot.git
|
17
|
+
```
|
18
|
+
|
19
|
+
## Bundle Install and Test
|
20
|
+
|
21
|
+
Ensure that you can build the project and run tests.
|
22
|
+
|
23
|
+
```
|
24
|
+
bundle install
|
25
|
+
bundle exec rake
|
26
|
+
```
|
27
|
+
|
28
|
+
## Run SlackRubyBot in Development
|
29
|
+
|
30
|
+
Create a private slack group for yourself.
|
31
|
+
|
32
|
+
Create a new Bot Integration under [services/new/bot](http://slack.com/services/new/bot).
|
33
|
+
|
34
|
+

|
35
|
+
|
36
|
+
On the next screen, note the API token.
|
37
|
+
|
38
|
+
Run `SLACK_API_TOKEN=<your API token> foreman start`.
|
39
|
+
|
40
|
+
You can also create a `.env` file with `SLACK_API_TOKEN=<your API token>` and just run `foreman start`.
|
41
|
+
|
42
|
+
## Create a Topic Branch
|
43
|
+
|
44
|
+
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
|
45
|
+
|
46
|
+
```
|
47
|
+
git checkout master
|
48
|
+
git pull upstream master
|
49
|
+
git checkout -b my-feature-branch
|
50
|
+
```
|
51
|
+
|
52
|
+
## Write Tests
|
53
|
+
|
54
|
+
Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build.
|
55
|
+
Add to [spec](spec).
|
56
|
+
|
57
|
+
We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
|
58
|
+
|
59
|
+
## Write Code
|
60
|
+
|
61
|
+
Implement your feature or bug fix.
|
62
|
+
|
63
|
+
Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop).
|
64
|
+
Run `bundle exec rubocop` and fix any style issues highlighted.
|
65
|
+
|
66
|
+
Make sure that `bundle exec rake` completes without errors.
|
67
|
+
|
68
|
+
## Write Documentation
|
69
|
+
|
70
|
+
Document any external behavior in the [README](README.md).
|
71
|
+
|
72
|
+
## Update Changelog
|
73
|
+
|
74
|
+
Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*.
|
75
|
+
Make it look like every other line, including your name and link to your Github account.
|
76
|
+
|
77
|
+
## Commit Changes
|
78
|
+
|
79
|
+
Make sure git knows your name and email address:
|
80
|
+
|
81
|
+
```
|
82
|
+
git config --global user.name "Your Name"
|
83
|
+
git config --global user.email "contributor@example.com"
|
84
|
+
```
|
85
|
+
|
86
|
+
Writing good commit logs is important. A commit log should describe what changed and why.
|
87
|
+
|
88
|
+
```
|
89
|
+
git add ...
|
90
|
+
git commit
|
91
|
+
```
|
92
|
+
|
93
|
+
## Push
|
94
|
+
|
95
|
+
```
|
96
|
+
git push origin my-feature-branch
|
97
|
+
```
|
98
|
+
|
99
|
+
## Make a Pull Request
|
100
|
+
|
101
|
+
Go to https://github.com/contributor/slack-ruby-bot and select your feature branch.
|
102
|
+
Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
|
103
|
+
|
104
|
+
## Rebase
|
105
|
+
|
106
|
+
If you've been working on a change for a while, rebase with upstream/master.
|
107
|
+
|
108
|
+
```
|
109
|
+
git fetch upstream
|
110
|
+
git rebase upstream/master
|
111
|
+
git push origin my-feature-branch -f
|
112
|
+
```
|
113
|
+
|
114
|
+
## Update CHANGELOG Again
|
115
|
+
|
116
|
+
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
117
|
+
|
118
|
+
```
|
119
|
+
* [#123](https://github.com/dblock/slack-ruby-bot/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
120
|
+
```
|
121
|
+
|
122
|
+
Amend your previous commit and force push the changes.
|
123
|
+
|
124
|
+
```
|
125
|
+
git commit --amend
|
126
|
+
git push origin my-feature-branch -f
|
127
|
+
```
|
128
|
+
|
129
|
+
## Check on Your Pull Request
|
130
|
+
|
131
|
+
Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
|
132
|
+
|
133
|
+
## Be Patient
|
134
|
+
|
135
|
+
It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
|
136
|
+
|
137
|
+
## Thank You
|
138
|
+
|
139
|
+
Please do know that we really appreciate and value your time and work. We love you, really.
|
data/DEPLOYMENT.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## Installation
|
2
|
+
|
3
|
+
Create a new Bot Integration under [services/new/bot](http://slack.com/services/new/bot).
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
On the next screen, note the API token.
|
8
|
+
|
9
|
+
### Environment
|
10
|
+
|
11
|
+
#### SLACK_API_TOKEN
|
12
|
+
|
13
|
+
Set SLACK_API_TOKEN from the Bot integration settings on Slack.
|
14
|
+
|
15
|
+
```
|
16
|
+
heroku config:add SLACK_API_TOKEN=...
|
17
|
+
```
|
18
|
+
|
19
|
+
#### GIPHY_API_KEY
|
20
|
+
|
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
|
+
|
23
|
+
### Heroku Idling
|
24
|
+
|
25
|
+
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/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
slack-ruby-bot (0.1.0)
|
5
|
+
activesupport
|
6
|
+
giphy (~> 2.0.2)
|
7
|
+
hashie
|
8
|
+
slack-api (~> 1.1.6)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: http://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (4.2.3)
|
14
|
+
i18n (~> 0.7)
|
15
|
+
json (~> 1.7, >= 1.7.7)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
addressable (2.3.8)
|
20
|
+
ast (2.0.0)
|
21
|
+
astrolabe (1.3.0)
|
22
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
23
|
+
crack (0.4.2)
|
24
|
+
safe_yaml (~> 1.0.0)
|
25
|
+
diff-lcs (1.2.5)
|
26
|
+
eventmachine (1.0.7)
|
27
|
+
faraday (0.9.1)
|
28
|
+
multipart-post (>= 1.2, < 3)
|
29
|
+
faraday_middleware (0.9.1)
|
30
|
+
faraday (>= 0.7.4, < 0.10)
|
31
|
+
faraday_middleware-parse_oj (0.3.0)
|
32
|
+
faraday (~> 0.9.0)
|
33
|
+
faraday_middleware (~> 0.9.1)
|
34
|
+
oj (~> 2.0)
|
35
|
+
faye-websocket (0.9.2)
|
36
|
+
eventmachine (>= 0.12.0)
|
37
|
+
websocket-driver (>= 0.5.1)
|
38
|
+
giphy (2.0.2)
|
39
|
+
faraday (~> 0.9)
|
40
|
+
faraday_middleware (~> 0.9)
|
41
|
+
faraday_middleware-parse_oj (~> 0.3)
|
42
|
+
launchy (~> 2.4)
|
43
|
+
hashie (3.4.2)
|
44
|
+
i18n (0.7.0)
|
45
|
+
json (1.8.3)
|
46
|
+
launchy (2.4.3)
|
47
|
+
addressable (~> 2.3)
|
48
|
+
minitest (5.7.0)
|
49
|
+
multi_json (1.11.1)
|
50
|
+
multipart-post (2.0.0)
|
51
|
+
oj (2.12.9)
|
52
|
+
parser (2.3.0.pre.2)
|
53
|
+
ast (>= 1.1, < 3.0)
|
54
|
+
powerpack (0.1.1)
|
55
|
+
rack (1.6.4)
|
56
|
+
rack-test (0.6.3)
|
57
|
+
rack (>= 1.0)
|
58
|
+
rainbow (2.0.0)
|
59
|
+
rake (10.4.2)
|
60
|
+
rspec (3.3.0)
|
61
|
+
rspec-core (~> 3.3.0)
|
62
|
+
rspec-expectations (~> 3.3.0)
|
63
|
+
rspec-mocks (~> 3.3.0)
|
64
|
+
rspec-core (3.3.1)
|
65
|
+
rspec-support (~> 3.3.0)
|
66
|
+
rspec-expectations (3.3.0)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.3.0)
|
69
|
+
rspec-mocks (3.3.1)
|
70
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
+
rspec-support (~> 3.3.0)
|
72
|
+
rspec-support (3.3.0)
|
73
|
+
rubocop (0.32.1)
|
74
|
+
astrolabe (~> 1.3)
|
75
|
+
parser (>= 2.2.2.5, < 3.0)
|
76
|
+
powerpack (~> 0.1)
|
77
|
+
rainbow (>= 1.99.1, < 3.0)
|
78
|
+
ruby-progressbar (~> 1.4)
|
79
|
+
ruby-progressbar (1.7.5)
|
80
|
+
safe_yaml (1.0.4)
|
81
|
+
slack-api (1.1.6)
|
82
|
+
faraday (>= 0.7, < 0.10)
|
83
|
+
faraday_middleware (~> 0.8)
|
84
|
+
faye-websocket (~> 0.9.2)
|
85
|
+
multi_json (~> 1.0, >= 1.0.3)
|
86
|
+
thread_safe (0.3.5)
|
87
|
+
tzinfo (1.2.2)
|
88
|
+
thread_safe (~> 0.1)
|
89
|
+
vcr (2.9.3)
|
90
|
+
webmock (1.21.0)
|
91
|
+
addressable (>= 2.3.6)
|
92
|
+
crack (>= 0.3.2)
|
93
|
+
websocket-driver (0.5.4)
|
94
|
+
websocket-extensions (>= 0.1.0)
|
95
|
+
websocket-extensions (0.1.2)
|
96
|
+
|
97
|
+
PLATFORMS
|
98
|
+
ruby
|
99
|
+
|
100
|
+
DEPENDENCIES
|
101
|
+
rack-test
|
102
|
+
rake
|
103
|
+
rspec
|
104
|
+
rubocop (= 0.32.1)
|
105
|
+
slack-ruby-bot!
|
106
|
+
vcr
|
107
|
+
webmock
|
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2015 Daniel Doubrovkine, Artsy and Contributors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
Slack-Ruby-Bot
|
2
|
+
==============
|
3
|
+
|
4
|
+
[](https://travis-ci.org/dblock/slack-ruby-bot)
|
5
|
+
|
6
|
+
A generic Slack bot framework written in Ruby. This library does all the heavy lifting so you can focus on implementing slack bot commands.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
### A Minimal Bot
|
11
|
+
|
12
|
+
#### Gemfile
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
source 'http://rubygems.org'
|
16
|
+
|
17
|
+
gem 'slack-ruby-bot'
|
18
|
+
```
|
19
|
+
|
20
|
+
#### pongbot.rb
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'slack-ruby-bot'
|
24
|
+
|
25
|
+
module PongBot
|
26
|
+
class App < SlackRubyBot::App
|
27
|
+
end
|
28
|
+
|
29
|
+
class Ping < SlackRubyBot::Commands::Base
|
30
|
+
def self.call(data, command, arguments)
|
31
|
+
send_message data.channel, 'pong'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
PongBot::App.instance.run
|
37
|
+
```
|
38
|
+
|
39
|
+
After [registering the bot](DEPLOYMENT.md), run with `SLACK_API_KEY=... bundle exec ruby pongbot.rb`.
|
40
|
+
|
41
|
+
### More Involved Examples
|
42
|
+
|
43
|
+
A Slack bot is commonly a combination of a vanilla web server and a websocket application that talks to the Slack RealTime API. The web server is optional, but most people will run their Slack bots on Heroku in which case a web server is required to prevent Heroku from shutting the bot down. It also makes it convenient to develop and test using `foreman`.
|
44
|
+
|
45
|
+
* [slack-mathbot](https://github.com/dblock/slack-mathbot)
|
46
|
+
|
47
|
+
### Built-In Commands
|
48
|
+
|
49
|
+
#### [bot name]
|
50
|
+
|
51
|
+
Shows bot version and links.
|
52
|
+
|
53
|
+
#### [bot name] hi
|
54
|
+
|
55
|
+
Politely says 'hi' back.
|
56
|
+
|
57
|
+
#### [bot name] help
|
58
|
+
|
59
|
+
Get help.
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
64
|
+
|
65
|
+
## Copyright and License
|
66
|
+
|
67
|
+
Copyright (c) 2015, Daniel Doubrovkine, Artsy and [Contributors](CHANGELOG.md).
|
68
|
+
|
69
|
+
This project is licensed under the [MIT License](LICENSE.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
Bundler.setup :default, :development
|
6
|
+
|
7
|
+
unless ENV['RACK_ENV'] == 'production'
|
8
|
+
require 'rspec/core'
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
|
11
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
12
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'rubocop/rake_task'
|
16
|
+
RuboCop::RakeTask.new
|
17
|
+
|
18
|
+
task default: [:rubocop, :spec]
|
19
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../..
|
3
|
+
specs:
|
4
|
+
slack-ruby-bot (0.1.0)
|
5
|
+
activesupport
|
6
|
+
giphy (~> 2.0.2)
|
7
|
+
hashie
|
8
|
+
slack-api (~> 1.1.6)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: http://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (4.2.3)
|
14
|
+
i18n (~> 0.7)
|
15
|
+
json (~> 1.7, >= 1.7.7)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
addressable (2.3.8)
|
20
|
+
eventmachine (1.0.7)
|
21
|
+
faraday (0.9.1)
|
22
|
+
multipart-post (>= 1.2, < 3)
|
23
|
+
faraday_middleware (0.9.1)
|
24
|
+
faraday (>= 0.7.4, < 0.10)
|
25
|
+
faraday_middleware-parse_oj (0.3.0)
|
26
|
+
faraday (~> 0.9.0)
|
27
|
+
faraday_middleware (~> 0.9.1)
|
28
|
+
oj (~> 2.0)
|
29
|
+
faye-websocket (0.9.2)
|
30
|
+
eventmachine (>= 0.12.0)
|
31
|
+
websocket-driver (>= 0.5.1)
|
32
|
+
giphy (2.0.2)
|
33
|
+
faraday (~> 0.9)
|
34
|
+
faraday_middleware (~> 0.9)
|
35
|
+
faraday_middleware-parse_oj (~> 0.3)
|
36
|
+
launchy (~> 2.4)
|
37
|
+
hashie (3.4.2)
|
38
|
+
i18n (0.7.0)
|
39
|
+
json (1.8.3)
|
40
|
+
launchy (2.4.3)
|
41
|
+
addressable (~> 2.3)
|
42
|
+
minitest (5.7.0)
|
43
|
+
multi_json (1.11.1)
|
44
|
+
multipart-post (2.0.0)
|
45
|
+
oj (2.12.9)
|
46
|
+
slack-api (1.1.6)
|
47
|
+
faraday (>= 0.7, < 0.10)
|
48
|
+
faraday_middleware (~> 0.8)
|
49
|
+
faye-websocket (~> 0.9.2)
|
50
|
+
multi_json (~> 1.0, >= 1.0.3)
|
51
|
+
thread_safe (0.3.5)
|
52
|
+
tzinfo (1.2.2)
|
53
|
+
thread_safe (~> 0.1)
|
54
|
+
websocket-driver (0.5.4)
|
55
|
+
websocket-extensions (>= 0.1.0)
|
56
|
+
websocket-extensions (0.1.2)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
slack-ruby-bot!
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'slack-ruby-bot'
|
2
|
+
|
3
|
+
module PongBot
|
4
|
+
class App < SlackRubyBot::App
|
5
|
+
end
|
6
|
+
|
7
|
+
class Ping < SlackRubyBot::Commands::Base
|
8
|
+
def self.call(data, _command, _arguments)
|
9
|
+
send_message data.channel, 'pong'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
PongBot::App.instance.run
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'boot'
|
5
|
+
|
6
|
+
Bundler.require :default, ENV['RACK_ENV']
|
7
|
+
|
8
|
+
Dir[File.expand_path('../../initializers', __FILE__) + '/**/*.rb'].each do |file|
|
9
|
+
require file
|
10
|
+
end
|
11
|
+
|
12
|
+
require File.expand_path('../application', __FILE__)
|
13
|
+
|
14
|
+
require 'slack_ruby_bot'
|
data/lib/config/boot.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Slack
|
2
|
+
module Request
|
3
|
+
private
|
4
|
+
|
5
|
+
alias_method :_request, :request
|
6
|
+
|
7
|
+
def request(method, path, options)
|
8
|
+
response = _request(method, path, options)
|
9
|
+
fail response['error'] unless response['ok'] if response.is_a?(Hash)
|
10
|
+
response
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module SlackRubyBot
|
2
|
+
class App
|
3
|
+
cattr_accessor :hooks
|
4
|
+
|
5
|
+
include SlackRubyBot::Hooks::Hello
|
6
|
+
include SlackRubyBot::Hooks::Message
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
SlackRubyBot.configure do |config|
|
10
|
+
config.token = ENV['SLACK_API_TOKEN'] || fail("Missing ENV['SLACK_API_TOKEN'].")
|
11
|
+
end
|
12
|
+
Slack.configure do |config|
|
13
|
+
config.token = SlackRubyBot.config.token
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
SlackRubyBot.config
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.instance
|
22
|
+
@instance ||= SlackRubyBot::App.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def run
|
26
|
+
auth!
|
27
|
+
start!
|
28
|
+
end
|
29
|
+
|
30
|
+
def stop!
|
31
|
+
client.stop
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def logger
|
37
|
+
@logger ||= begin
|
38
|
+
$stdout.sync = true
|
39
|
+
Logger.new(STDOUT)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def start!
|
44
|
+
loop do
|
45
|
+
client.start
|
46
|
+
@client = nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def client
|
51
|
+
@client ||= begin
|
52
|
+
client = Slack.realtime
|
53
|
+
hooks.each do |hook|
|
54
|
+
client.on hook do |data|
|
55
|
+
begin
|
56
|
+
send hook, data
|
57
|
+
rescue StandardError => e
|
58
|
+
logger.error e
|
59
|
+
begin
|
60
|
+
Slack.chat_postMessage(channel: data['channel'], text: e.message) if data.key?('channel')
|
61
|
+
rescue
|
62
|
+
# ignore
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
client
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def auth!
|
72
|
+
auth = Slack.auth_test
|
73
|
+
SlackRubyBot.configure do |config|
|
74
|
+
config.url = auth['url']
|
75
|
+
config.team = auth['team']
|
76
|
+
config.user = auth['user']
|
77
|
+
config.team_id = auth['team_id']
|
78
|
+
config.user_id = auth['user_id']
|
79
|
+
end
|
80
|
+
logger.info "Welcome '#{SlackRubyBot.config.user}' to the '#{SlackRubyBot.config.team}' team at #{SlackRubyBot.config.url}."
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|