diff --git a/Gemfile b/Gemfile index a19cb52..a9c80b8 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'http://rubygems.org' ruby '2.2.0' -gem 'slack-ruby-bot', :path => "slack-ruby-bot-0.4.4/" +gem 'slack-ruby-bot' gem 'puma' gem 'sinatra' gem 'dentaku' diff --git a/slack-ruby-bot-0.4.4/.gitignore b/slack-ruby-bot-0.4.4/.gitignore deleted file mode 100644 index 1ee1f8b..0000000 --- a/slack-ruby-bot-0.4.4/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.env -pkg -Gemfile.lock diff --git a/slack-ruby-bot-0.4.4/.rspec b/slack-ruby-bot-0.4.4/.rspec deleted file mode 100644 index 8c18f1a..0000000 --- a/slack-ruby-bot-0.4.4/.rspec +++ /dev/null @@ -1,2 +0,0 @@ ---format documentation ---color diff --git a/slack-ruby-bot-0.4.4/.rubocop.yml b/slack-ruby-bot-0.4.4/.rubocop.yml deleted file mode 100644 index bdd4025..0000000 --- a/slack-ruby-bot-0.4.4/.rubocop.yml +++ /dev/null @@ -1,6 +0,0 @@ -AllCops: - Exclude: - - vendor/**/* - - bin/**/* - -inherit_from: .rubocop_todo.yml diff --git a/slack-ruby-bot-0.4.4/.rubocop_todo.yml b/slack-ruby-bot-0.4.4/.rubocop_todo.yml deleted file mode 100644 index 7015484..0000000 --- a/slack-ruby-bot-0.4.4/.rubocop_todo.yml +++ /dev/null @@ -1,45 +0,0 @@ -# This configuration was generated by `rubocop --auto-gen-config` -# on 2015-09-23 08:45:19 -0400 using RuboCop version 0.32.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -Lint/HandleExceptions: - Enabled: false - -# Offense count: 1 -Lint/UselessAccessModifier: - Enabled: false - -# Offense count: 4 -Metrics/AbcSize: - Max: 23 - -# Offense count: 1 -Metrics/CyclomaticComplexity: - Max: 7 - -# Offense count: 85 -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Max: 142 - -# Offense count: 4 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 21 - -# Offense count: 15 -Style/Documentation: - Enabled: false - -# Offense count: 1 -# Configuration parameters: Exclude. -Style/FileName: - Enabled: false - -# Offense count: 1 -Style/ModuleFunction: - Enabled: false diff --git a/slack-ruby-bot-0.4.4/.travis.yml b/slack-ruby-bot-0.4.4/.travis.yml deleted file mode 100644 index e6ba548..0000000 --- a/slack-ruby-bot-0.4.4/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -rvm: - - 2.1.6 - diff --git a/slack-ruby-bot-0.4.4/CHANGELOG.md b/slack-ruby-bot-0.4.4/CHANGELOG.md deleted file mode 100644 index 43f22e2..0000000 --- a/slack-ruby-bot-0.4.4/CHANGELOG.md +++ /dev/null @@ -1,45 +0,0 @@ -### 0.4.4 (Next) - -* [#17](https://github.com/dblock/slack-ruby-bot/issues/17): Address bot by `name:` - [@dblock](https://githubcom/dblock). -* [#19](https://github.com/dblock/slack-ruby-bot/issues/19): Retry on `Faraday::Error::TimeoutError`, `TimeoutError` and `SSLError` - [@dblock](https://githubcom/dblock). -* [#3](https://github.com/dblock/slack-ruby-bot/issues/3): Retry on `migration_in_progress` errors during `rtm.start` - [@dblock](https://githubcom/dblock). -* Respond to direct messages without being addressed by name - [@dblock](https://githubcom/dblock). -* Added `send_gif`, to allow GIFs to be sent without text - [@maclover7](https://github.com/maclover7). - -### 0.4.3 (8/21/2015) - -* [#13](https://github.com/dblock/slack-ruby-bot/issues/13): You can now address the bot by its Slack @id - [@dblock](https://githubcom/dblock). - -### 0.4.2 (8/20/2015) - -* [#12](https://github.com/dblock/slack-ruby-bot/issues/12): Added support for bot aliases - [@dblock](https://githubcom/dblock). - -### 0.4.1 (7/25/2015) - -* Use a real client in `respond_with_slack_message` expectaions - [@dblock](https://githubcom/dblock). - -### 0.4.0 (7/25/2015) - -* Using [slack-ruby-client](https://github.com/dblock/slack-ruby-client) - [@dblock](https://githubcom/dblock). -* Use RealTime API to post messages - [@dblock](https://githubcom/dblock). - -### 0.3.1 (7/21/2015) - -* [#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). - -### 0.3.0 (7/19/2015) - -* [#5](https://github.com/dblock/slack-ruby-bot/issues/5): Added support for free-formed routes via `match` - [@dblock](https://github.com/dblock). -* [#6](https://github.com/dblock/slack-ruby-bot/issues/6): Commands and operators take blocks - [@dblock](https://github.com/dblock). -* [#4](https://github.com/dblock/slack-ruby-bot/issues/4): Messages are posted with `as_user: true` by default - [@dblock](https://github.com/dblock). - -### 0.2.0 (7/10/2015) - -* Sending `send_message` with nil or empty text will yield `Nothing to see here.` with a GIF instead of `no_text` - [@dblock](https://github.com/dblock). -* Added support for operators with `operator [name]` - [@dblock](https://github.com/dblock). -* Added support for custom commands with `command [name]` - [@dblock](https://github.com/dblock). - -### 0.1.0 (6/2/2015) - -* Initial public release - [@dblock](https://github.com/dblock). - diff --git a/slack-ruby-bot-0.4.4/CONTRIBUTING.md b/slack-ruby-bot-0.4.4/CONTRIBUTING.md deleted file mode 100644 index 810a8dd..0000000 --- a/slack-ruby-bot-0.4.4/CONTRIBUTING.md +++ /dev/null @@ -1,139 +0,0 @@ -# Contributing to SlackRubyBot - -This project is work of [many contributors](https://github.com/dblock/slack-ruby-bot/graphs/contributors). - -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). - -In the examples below, substitute your Github username for `contributor` in URLs. - -## Fork the Project - -Fork the [project on Github](https://github.com/dblock/slack-ruby-bot) and check out your copy. - -``` -git clone https://github.com/contributor/slack-ruby-bot.git -cd slack-ruby-bot -git remote add upstream https://github.com/dblock/slack-ruby-bot.git -``` - -## Bundle Install and Test - -Ensure that you can build the project and run tests. - -``` -bundle install -bundle exec rake -``` - -## Run SlackRubyBot in Development - -Create a private slack group for yourself. - -Create a new Bot Integration under [services/new/bot](http://slack.com/services/new/bot). - -![](screenshots/register-bot.png) - -On the next screen, note the API token. - -Run `SLACK_API_TOKEN= foreman start`. - -You can also create a `.env` file with `SLACK_API_TOKEN=` and just run `foreman start`. - -## Create a Topic Branch - -Make sure your fork is up-to-date and create a topic branch for your feature or bug fix. - -``` -git checkout master -git pull upstream master -git checkout -b my-feature-branch -``` - -## Write Tests - -Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. -Add to [spec](spec). - -We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix. - -## Write Code - -Implement your feature or bug fix. - -Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop). -Run `bundle exec rubocop` and fix any style issues highlighted. - -Make sure that `bundle exec rake` completes without errors. - -## Write Documentation - -Document any external behavior in the [README](README.md). - -## Update Changelog - -Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. -Make it look like every other line, including your name and link to your Github account. - -## Commit Changes - -Make sure git knows your name and email address: - -``` -git config --global user.name "Your Name" -git config --global user.email "contributor@example.com" -``` - -Writing good commit logs is important. A commit log should describe what changed and why. - -``` -git add ... -git commit -``` - -## Push - -``` -git push origin my-feature-branch -``` - -## Make a Pull Request - -Go to https://github.com/contributor/slack-ruby-bot and select your feature branch. -Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days. - -## Rebase - -If you've been working on a change for a while, rebase with upstream/master. - -``` -git fetch upstream -git rebase upstream/master -git push origin my-feature-branch -f -``` - -## Update CHANGELOG Again - -Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows. - -``` -* [#123](https://github.com/dblock/slack-ruby-bot/pull/123): Reticulated splines - [@contributor](https://github.com/contributor). -``` - -Amend your previous commit and force push the changes. - -``` -git commit --amend -git push origin my-feature-branch -f -``` - -## Check on Your Pull Request - -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. - -## Be Patient - -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! - -## Thank You - -Please do know that we really appreciate and value your time and work. We love you, really. diff --git a/slack-ruby-bot-0.4.4/DEPLOYMENT.md b/slack-ruby-bot-0.4.4/DEPLOYMENT.md deleted file mode 100644 index 734f1dc..0000000 --- a/slack-ruby-bot-0.4.4/DEPLOYMENT.md +++ /dev/null @@ -1,33 +0,0 @@ -## Installation - -Create a new Bot Integration under [services/new/bot](http://slack.com/services/new/bot). - -![](screenshots/register-bot.png) - -On the next screen, note the API token. - -### Environment - -#### SLACK_API_TOKEN - -Set SLACK_API_TOKEN from the Bot integration settings on Slack. - -``` -heroku config:add SLACK_API_TOKEN=... -``` - -#### GIPHY_API_KEY - -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. - -#### SLACK_RUBY_BOT_ALIASES - -Optional names for this bot. - -``` -heroku config:add SLACK_RUBY_BOT_ALIASES=":pong: table-tennis ping-pong" -``` - -### Heroku Idling - -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. diff --git a/slack-ruby-bot-0.4.4/Gemfile b/slack-ruby-bot-0.4.4/Gemfile deleted file mode 100644 index d65e2a6..0000000 --- a/slack-ruby-bot-0.4.4/Gemfile +++ /dev/null @@ -1,3 +0,0 @@ -source 'http://rubygems.org' - -gemspec diff --git a/slack-ruby-bot-0.4.4/LICENSE.md b/slack-ruby-bot-0.4.4/LICENSE.md deleted file mode 100644 index 81ae90d..0000000 --- a/slack-ruby-bot-0.4.4/LICENSE.md +++ /dev/null @@ -1,22 +0,0 @@ -MIT License - -Copyright (c) 2015 Daniel Doubrovkine, Artsy and Contributors - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/slack-ruby-bot-0.4.4/README.md b/slack-ruby-bot-0.4.4/README.md deleted file mode 100644 index 4fb18d5..0000000 --- a/slack-ruby-bot-0.4.4/README.md +++ /dev/null @@ -1,216 +0,0 @@ -Slack-Ruby-Bot -============== - -[![Gem Version](https://badge.fury.io/rb/slack-ruby-bot.svg)](http://badge.fury.io/rb/slack-ruby-bot) -[![Build Status](https://travis-ci.org/dblock/slack-ruby-bot.png)](https://travis-ci.org/dblock/slack-ruby-bot) - -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 introduce the bare minimum number of requirements or any sorts of limitations. It's a Slack bot boilerplate. - -## Usage - -### A Minimal Bot - -#### Gemfile - -```ruby -source 'http://rubygems.org' - -gem 'slack-ruby-bot' -``` - -#### pongbot.rb - -```ruby -require 'slack-ruby-bot' - -module PongBot - class App < SlackRubyBot::App - end - - class Ping < SlackRubyBot::Commands::Base - command 'ping' do |client, data, _match| - client.message text: 'pong', channel: data.channel - end - end -end - -PongBot::App.instance.run -``` - -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. - -![](screenshots/demo.gif) - -### A Production Bot - -A typical production Slack bot is a combination of a vanilla web server and a websocket application that talks to the Slack Real Time Messaging API. See our [Writing a Production Bot](TUTORIAL.md) tutorial for more information. - -### More Involved Examples - -The following examples of production-grade bots based on slack-ruby-bot are listed in growing order of complexity. - -* [slack-mathbot](https://github.com/dblock/slack-mathbot): Slack integration with math. -* [slack-google-bot](https://github.com/dblock/slack-google-bot): A Slack bot that searches Google, including CSE. -* [slack-aws](https://github.com/dblock/slack-aws): Slack integration with Amazon Web Services. -* [slack-gamebot](https://github.com/dblock/slack-gamebot): A generic game bot for ping-pong, chess, etc. - -### Commands and Operators - -Bots are addressed by name, they respond to commands and operators. 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. - -```ruby -class Phone < SlackRubyBot::Commands::Base - command 'call' - - def self.call(client, data, _match) - send_message client, data.channel, 'called' - end -end -``` - -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). - -```ruby -class Phone < SlackRubyBot::Commands::Base - command 'call' - command '呼び出し' - - def self.call(client, data, _match) - send_message client, data.channel, 'called' - end -end -``` - -You can combine multiple commands and use a block to implement them. - -```ruby -class Phone < SlackRubyBot::Commands::Base - command 'call', '呼び出し' do |client, data, _match| - send_message client, data.channel, 'called' - end -end -``` - -Command match data includes `match['bot']`, `match['command']` and `match['expression']`. The `bot` match always checks against the `SlackRubyBot::Config.user` and `SlackRubyBot::Config.user_id` values obtained when the bot starts. - -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`. - -```ruby -class Calculator < SlackRubyBot::Commands::Base - operator '=' do |_data, _match| - # implementation detail - end -end -``` - -Operator match data includes `match['operator']` and `match['expression']`. The `bot` match always checks against the `SlackRubyBot::Config.user` setting. - -### Bot Aliases - -A bot will always respond to its name (eg. `rubybot`) and Slack ID (eg. `@rubybot`), but you can specify multiple aliases via the `SLACK_RUBY_BOT_ALIASES` environment variable or via an explicit configuration. - -``` -SLACK_RUBY_BOT_ALIASES=:pp: table-tennis -``` - -```ruby -SlackRubyBot.configure do |config| - config.aliases = [':pong:', 'pongbot'] -end -``` - -This is particularly fun with emoji. - -![](screenshots/aliases.gif) - -Bots also will respond to a direct message, with or without the bot name in the message itself. - -![](screenshots/dms.gif) - -### Generic Routing - -Commands and operators are generic versions of bot routes. You can respond to just about anything by defining a custom route. - -```ruby -class Weather < SlackRubyBot::Commands::Base - match /^How is the weather in (?\w*)\?$/ do |client, data, match| - send_message client, data.channel, "The weather in #{match[:location]} is nice." - end -end -``` - -![](screenshots/weather.gif) - -### SlackRubyBot::Commands::Base Functions - -#### send_message(client, channel, text) - -Send text using a RealTime client to a channel. - -#### send_message_with_gif(client, channel, text, keyword) - -Send text along with a random animated GIF based on a keyword. - -## send_gif(client, channel, keyword) - -Send a random animated GIF based on a keyword. - -### Built-In Commands - -Slack-ruby-bot comes with several built-in commands. You can re-define built-in commands, normally, as described above. - -#### [bot name] - -This is also known as the `default` command. Shows bot version and links. - -#### [bot name] hi - -Politely says 'hi' back. - -#### [bot name] help - -Get help. - -### Hooks - -Hooks are event handlers and respond to Slack RTM API [events](https://api.slack.com/events), such as [hello](lib/slack-ruby-bot/hooks/hello.rb) or [message](lib/slack-ruby-bot/hooks/message.rb). You can implement your own by extending [SlackRubyBot::Hooks::Base](lib/slack-ruby-bot/hooks/base.rb). - -For example, the following hook handles [user_change](https://api.slack.com/events/user_change), an event sent when a team member updates their profile or data. This can be useful to update the local user cache when a user is renamed. - -```ruby -module MyBot - module Hooks - module UserChange - extend SlackRubyBot::Hooks::Base - - def user_change(client, data) - # data['user']['id'] contains the user ID - # data['user']['name'] contains the new user name - ... - end - end - end -end -``` - -### RSpec Shared Behaviors - -Slack-ruby-bot ships with a number of shared RSpec behaviors that can be used in your RSpec tests. Require 'slack-ruby-bot/rspec' in your `spec_helper.rb`. - -* [behaves like a slack bot](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb): A bot quacks like a Slack Ruby bot. -* [respond with slack message](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb): The bot responds with a message. -* [respond with error](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb): An exception is raised inside a bot command. - -## Contributing - -See [CONTRIBUTING](CONTRIBUTING.md). - -## Upgrading - -See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions. - -## Copyright and License - -Copyright (c) 2015, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md). - -This project is licensed under the [MIT License](LICENSE.md). diff --git a/slack-ruby-bot-0.4.4/RELEASING.md b/slack-ruby-bot-0.4.4/RELEASING.md deleted file mode 100644 index 6eb01a6..0000000 --- a/slack-ruby-bot-0.4.4/RELEASING.md +++ /dev/null @@ -1,67 +0,0 @@ -# Releasing Slack-Ruby-Bot - -There're no particular rules about when to release slack-ruby-bot. Release bug fixes frequenty, features not so frequently and breaking API changes rarely. - -### Release - -Run tests, check that all tests succeed locally. - -``` -bundle install -rake -``` - -Check that the last build succeeded in [Travis CI](https://travis-ci.org/dblock/slack-ruby-bot) for all supported platforms. - -Increment the version, modify [lib/slack-ruby-bot/version.rb](lib/slack-ruby-bot/version.rb). - -* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.2.1` to `0.2.2`). -* Increment the second number if the release contains major features or breaking API changes (eg. change `0.2.1` to `0.3.0`). - -Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version. - -``` -### 0.2.2 (7/10/2015) -``` - -Remove the line with "Your contribution here.", since there will be no more contributions to this release. - -Commit your changes. - -``` -git add CHANGELOG.md lib/slack-ruby-bot/version.rb -git commit -m "Preparing for release, 0.2.2." -git push origin master -``` - -Release. - -``` -$ rake release - -slack-ruby-bot 0.2.2 built to pkg/slack-ruby-bot-0.2.2.gem. -Tagged v0.2.2. -Pushed git commits and tags. -Pushed slack-ruby-bot 0.2.2 to rubygems.org. -``` - -### Prepare for the Next Version - -Add the next release to [CHANGELOG.md](CHANGELOG.md). - -``` -Next Release -============ - -* Your contribution here. -``` - -Increment the third version number in [lib/slack-ruby-bot/version.rb](lib/slack-ruby-bot/version.rb). - -Comit your changes. - -``` -git add CHANGELOG.md lib/slack-ruby-bot/version.rb -git commit -m "Preparing for next development iteration, 0.2.3." -git push origin master -``` diff --git a/slack-ruby-bot-0.4.4/Rakefile b/slack-ruby-bot-0.4.4/Rakefile deleted file mode 100644 index e60af49..0000000 --- a/slack-ruby-bot-0.4.4/Rakefile +++ /dev/null @@ -1,19 +0,0 @@ -require 'rubygems' -require 'bundler' -require 'bundler/gem_tasks' - -Bundler.setup :default, :development - -unless ENV['RACK_ENV'] == 'production' - require 'rspec/core' - require 'rspec/core/rake_task' - - RSpec::Core::RakeTask.new(:spec) do |spec| - spec.pattern = FileList['spec/**/*_spec.rb'] - end - - require 'rubocop/rake_task' - RuboCop::RakeTask.new - - task default: [:rubocop, :spec] -end diff --git a/slack-ruby-bot-0.4.4/TUTORIAL.md b/slack-ruby-bot-0.4.4/TUTORIAL.md deleted file mode 100644 index 8c9e719..0000000 --- a/slack-ruby-bot-0.4.4/TUTORIAL.md +++ /dev/null @@ -1,203 +0,0 @@ -## Production Bot Tutorial - -In this tutorial we'll implement [slack-mathbot](https://github.com/dblock/slack-mathbot). - -### Introduction - -A typical production Slack bot is a combination of a vanilla web server and a websocket application that talks to the [Slack Real Time Messaging API](https://api.slack.com/rtm). The web server is optional, but most people will run their Slack bots on [Heroku](https://dashboard.heroku.com) in which case a web server is required to prevent Heroku from shutting the bot down. It also makes it convenient to develop a bot and test using `foreman`. - -### Getting Started - -#### Gemfile - -Create a `Gemfile` that uses [slack-ruby-bot](https://github.com/dblock/slack-ruby-bot), [sinatra](https://github.com/sinatra/sinatra) (a web framework) and [puma](https://github.com/puma/puma) (a web server). For development we'll also use [foreman](https://github.com/theforeman/foreman) and write tests with [rspec](https://github.com/rspec/rspec). - -```ruby -source 'http://rubygems.org' - -gem 'slack-ruby-bot' -gem 'puma' -gem 'sinatra' - -group :development, :test do - gem 'rake' - gem 'foreman' -end - -group :test do - gem 'rspec' - gem 'rack-test' -end -``` - -Run `bundle install` to get all the gems. - -#### Application - -Create a folder called `slack-mathbot` and inside of it create `app.rb`. - -```ruby -module SlackMathbot - class App < SlackRubyBot::App - end -end -``` - -#### Commands - -Create a folder called `slack-mathbot/commands` and inside of it create `calculate.rb`. For now this calculator will always return 4. - -```ruby -module SlackMathbot - module Commands - class Calculate < SlackRubyBot::Commands::Base - command 'calculate' do |client, data, _match| - send_message client, data.channel, '4' - end - end - end -end -``` - -#### Require Everything - -Create a `slack-mathbot.rb` at the root and require the above files. - -```ruby -require 'slack-ruby-bot' -require 'slack-mathbot/commands/calculate' -require 'slack-mathbot/app' -``` - -#### Web Server - -We will need to keep the bot alive on Heroku, so create `web.rb`. - -```ruby -require 'sinatra/base' - -module SlackMathbot - class Web < Sinatra::Base - get '/' do - 'Math is good for you.' - end - end -end -``` - -#### Config.ru - -Tie all the pieces togehter in `config.ru` which creates a thread for the bot and runs the web server on the main thread. - -```ruby -$LOAD_PATH.unshift(File.dirname(__FILE__)) - -require 'slack-mathbot' -require 'web' - -Thread.new do - begin - SlackMathbot::App.instance.run - rescue Exception => e - STDERR.puts "ERROR: #{e}" - STDERR.puts e.backtrace - raise e - end -end - -run SlackMathbot::Web -``` - -### Create a Bot User - -In Slack administration create a new Bot Integration under [services/new/bot](http://slack.com/services/new/bot). - -![](screenshots/register-bot.png) - -On the next screen, note the API token. - -#### .env - -Create a `.env` file with the API token from above and make sure to add it to `.gitignore`. - -``` -SLACK_API_TOKEN=... -``` - -### Procfile - -Create a `Procfile` which `foreman` will use when you run the `foreman start` command below. - -``` -web: bundle exec puma -p $PORT -``` - -### Run the Bot - -Run `foreman start`. Your bot should be running. - -``` -14:32:32 web.1 | Puma starting in single mode... -14:32:32 web.1 | * Version 2.11.3 (ruby 2.1.6-p336), codename: Intrepid Squirrel -14:32:32 web.1 | * Min threads: 0, max threads: 16 -14:32:32 web.1 | * Environment: development -14:32:35 web.1 | * Listening on tcp://0.0.0.0:5000 -14:32:35 web.1 | Use Ctrl-C to stop -14:32:36 web.1 | I, [2015-07-10T14:32:36.216663 #98948] INFO -- : Welcome 'mathbot' to the 'xyz' team at https://xyz.slack.com/. -14:32:36 web.1 | I, [2015-07-10T14:32:36.766955 #98948] INFO -- : Successfully connected to https://xyz.slack.com/. -``` - -### Try - -Invite the bot to a channel via `/invite [bot name]` and send it a `calculate` command with `[bot name] calculate 2+2`. It will respond with `4` from the code above. - -### Write Tests - -#### Spec Helper - -Create `spec/spec_helper.rb` that includes the bot files and shared RSpec support from slack-ruby-bot. - -```ruby -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..')) - -require 'slack-ruby-bot/rspec' -require 'slack-mathbot' -``` - -#### Test the Bot Application - -Create a test for the bot application itself in `spec/slack-mathbot/app_spec.rb`. - -```ruby -require 'spec_helper' - -describe SlackMathbot::App do - def app - SlackMathbot::App.new - end - it_behaves_like 'a slack ruby bot' -end -``` - -#### Test a Command - -Create a test for the `calculate` command in `spec/slack-mathbot/commands/calculate_spec.rb`. The bot is addressed by its user name. - -```ruby -require 'spec_helper' - -describe SlackMathbot::Commands::Calculate do - def app - SlackMathbot::App.new - end - it 'returns 4' do - expect(message: "#{SlackRubyBot.config.user} calculate 2+2", channel: 'channel').to respond_with_slack_message('4') - end -end -``` - -See [lib/slack-ruby-bot/rspec/support/slack-ruby-bot](lib/slack-ruby-bot/rspec/support/slack-ruby-bot) for other shared RSpec behaviors. - -### Deploy - -See [DEPLOYMENT](DEPLOYMENT.md) for how to deploy your bot to production. diff --git a/slack-ruby-bot-0.4.4/UPGRADING.md b/slack-ruby-bot-0.4.4/UPGRADING.md deleted file mode 100644 index 1b73cac..0000000 --- a/slack-ruby-bot-0.4.4/UPGRADING.md +++ /dev/null @@ -1,64 +0,0 @@ -Upgrading SlackRubyBot -====================== - -### Upgrading to >= 0.4.0 - -This version uses [slack-ruby-client](https://github.com/dblock/slack-ruby-client) instead of [slack-ruby-gem](https://github.com/aki017/slack-ruby-gem). - -The command interface now takes a `client` parameter, which is the RealTime Messaging API instance. Add the new parameter to all `call` calls in classes that inherit from `SlackRubyBot::Commands::Base`. - -Before: - -```ruby -def self.call(data, match) - ... -end -``` - -After: - -```ruby -def self.call(client, data, match) - ... -end -``` - -This also applies to `command`, `operator` and `match` blocks. - -Before: - -```ruby -command 'ping' do |data, match| - ... -end -``` - -After: - -```ruby -command 'ping' do |client, data, match| - ... -end -``` - -You can now send messages directly via the RealTime Messaging API. - -```ruby -client.message text: 'text', channel: 'channel' -``` - -Otherwise you must now pass the `client` parameter to `send_message` and `send_message_with_gif`. - -```ruby -def self.call(client, data, match) - send_message client, data.channel, 'hello' -end -``` - -```ruby -def self.call(client, data, match) - send_message_with_gif client, data.channel, 'hello', 'hi' -end -``` - - diff --git a/slack-ruby-bot-0.4.4/examples/minimal/Gemfile b/slack-ruby-bot-0.4.4/examples/minimal/Gemfile deleted file mode 100644 index f9e5211..0000000 --- a/slack-ruby-bot-0.4.4/examples/minimal/Gemfile +++ /dev/null @@ -1,3 +0,0 @@ -source 'http://rubygems.org' - -gem 'slack-ruby-bot', path: '../..' diff --git a/slack-ruby-bot-0.4.4/examples/minimal/Procfile b/slack-ruby-bot-0.4.4/examples/minimal/Procfile deleted file mode 100644 index a5ac163..0000000 --- a/slack-ruby-bot-0.4.4/examples/minimal/Procfile +++ /dev/null @@ -1 +0,0 @@ -console: bundle exec ruby pongbot.rb diff --git a/slack-ruby-bot-0.4.4/examples/minimal/pongbot.rb b/slack-ruby-bot-0.4.4/examples/minimal/pongbot.rb deleted file mode 100644 index f21e133..0000000 --- a/slack-ruby-bot-0.4.4/examples/minimal/pongbot.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'slack-ruby-bot' - -module PongBot - class App < SlackRubyBot::App - end - - class Ping < SlackRubyBot::Commands::Base - def self.call(client, data, _match) - client.message text: 'pong', channel: data.channel - end - end -end - -PongBot::App.instance.run diff --git a/slack-ruby-bot-0.4.4/examples/weather/Gemfile b/slack-ruby-bot-0.4.4/examples/weather/Gemfile deleted file mode 100644 index f9e5211..0000000 --- a/slack-ruby-bot-0.4.4/examples/weather/Gemfile +++ /dev/null @@ -1,3 +0,0 @@ -source 'http://rubygems.org' - -gem 'slack-ruby-bot', path: '../..' diff --git a/slack-ruby-bot-0.4.4/examples/weather/weatherbot.rb b/slack-ruby-bot-0.4.4/examples/weather/weatherbot.rb deleted file mode 100644 index b153386..0000000 --- a/slack-ruby-bot-0.4.4/examples/weather/weatherbot.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'slack-ruby-bot' - -module WeatherBot - class App < SlackRubyBot::App - end - - class Weather < SlackRubyBot::Commands::Base - match(/^How is the weather in (?\w*)\?$/i) do |client, data, match| - send_message client, data.channel, "The weather in #{match[:location]} is nice." - end - end -end - -WeatherBot::App.instance.run diff --git a/slack-ruby-bot-0.4.4/lib/config/application.rb b/slack-ruby-bot-0.4.4/lib/config/application.rb deleted file mode 100644 index 0ba7bc2..0000000 --- a/slack-ruby-bot-0.4.4/lib/config/application.rb +++ /dev/null @@ -1,14 +0,0 @@ -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..')) -$LOAD_PATH.unshift(File.dirname(__FILE__)) - -require 'boot' - -Bundler.require :default, ENV['RACK_ENV'] - -Dir[File.expand_path('../../initializers', __FILE__) + '/**/*.rb'].each do |file| - require file -end - -require File.expand_path('../application', __FILE__) - -require 'slack_ruby_bot' diff --git a/slack-ruby-bot-0.4.4/lib/config/boot.rb b/slack-ruby-bot-0.4.4/lib/config/boot.rb deleted file mode 100644 index bae4c01..0000000 --- a/slack-ruby-bot-0.4.4/lib/config/boot.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'rubygems' -require 'bundler/setup' -require 'logger' -require 'active_support' -require 'active_support/core_ext' -require 'hashie' -require 'slack' -require 'giphy' diff --git a/slack-ruby-bot-0.4.4/lib/config/environment.rb b/slack-ruby-bot-0.4.4/lib/config/environment.rb deleted file mode 100644 index f45d5f6..0000000 --- a/slack-ruby-bot-0.4.4/lib/config/environment.rb +++ /dev/null @@ -1,3 +0,0 @@ -ENV['RACK_ENV'] ||= 'development' - -require File.expand_path('../application', __FILE__) diff --git a/slack-ruby-bot-0.4.4/lib/initializers/giphy.rb b/slack-ruby-bot-0.4.4/lib/initializers/giphy.rb deleted file mode 100644 index 8d0e328..0000000 --- a/slack-ruby-bot-0.4.4/lib/initializers/giphy.rb +++ /dev/null @@ -1,3 +0,0 @@ -Giphy::Configuration.configure do |config| - config.api_key = ENV['GIPHY_API_KEY'] || 'dc6zaTOxFJmzC' # from https://github.com/Giphy/GiphyAPI -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot.rb deleted file mode 100644 index 9cb19a4..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot.rb +++ /dev/null @@ -1,21 +0,0 @@ -require File.expand_path('../config/environment', __FILE__) - -require 'slack-ruby-bot/version' -require 'slack-ruby-bot/about' -require 'slack-ruby-bot/config' -require 'slack-ruby-bot/hooks' - -module SlackRubyBot - class << self - def configure - block_given? ? yield(Config) : Config - end - - def config - Config - end - end -end - -require 'slack-ruby-bot/commands' -require 'slack-ruby-bot/app' diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/about.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/about.rb deleted file mode 100644 index a3630dd..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/about.rb +++ /dev/null @@ -1,7 +0,0 @@ -module SlackRubyBot - ABOUT = <<-ABOUT - #{SlackRubyBot::VERSION} - https://github.com/dblock/slack-ruby-bot - https://twitter.com/dblockdotorg - ABOUT -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/app.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/app.rb deleted file mode 100644 index c688eda..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/app.rb +++ /dev/null @@ -1,111 +0,0 @@ -module SlackRubyBot - class App - cattr_accessor :hooks - - include SlackRubyBot::Hooks::Hello - include SlackRubyBot::Hooks::Message - - def initialize - SlackRubyBot.configure do |config| - config.token = ENV['SLACK_API_TOKEN'] || fail("Missing ENV['SLACK_API_TOKEN'].") - config.aliases = ENV['SLACK_RUBY_BOT_ALIASES'].split(' ') if ENV['SLACK_RUBY_BOT_ALIASES'] - end - Slack.configure do |config| - config.token = SlackRubyBot.config.token - end - end - - def config - SlackRubyBot.config - end - - def self.instance - @instance ||= SlackRubyBot::App.new - end - - def run - auth! - start! - end - - def stop! - client.stop - end - - private - - def logger - @logger ||= begin - $stdout.sync = true - Logger.new(STDOUT) - end - end - - def start! - loop do - begin - client.start! - rescue Slack::Web::Api::Error => e - logger.error e - case e.message - when 'migration_in_progress' - sleep 1 # ignore, try again - else - raise e - end - rescue Faraday::Error::TimeoutError, Faraday::Error::ConnectionFailed, Faraday::Error::SSLError => e - logger.error e - sleep 1 # ignore, try again - rescue StandardError => e - logger.error e - raise e - ensure - @client = nil - end - end - end - - def client - @client ||= begin - client = Slack::RealTime::Client.new - hooks.each do |hook| - client.on hook do |data| - begin - send hook, client, data - rescue StandardError => e - logger.error e - begin - client.message(channel: data['channel'], text: e.message) if data.key?('channel') - rescue - # ignore - end - end - end - end - client - end - end - - def auth! - auth = client.web_client.auth_test - SlackRubyBot.configure do |config| - config.url = auth['url'] - config.team = auth['team'] - config.user = auth['user'] - config.team_id = auth['team_id'] - config.user_id = auth['user_id'] - end - logger.info "Welcome '#{SlackRubyBot.config.user}' to the '#{SlackRubyBot.config.team}' team at #{SlackRubyBot.config.url}." - end - - def reset! - SlackRubyBot.configure do |config| - config.url = nil - config.team = nil - config.user = nil - config.team_id = nil - config.user_id = nil - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands.rb deleted file mode 100644 index 19979be..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'slack-ruby-bot/commands/base' -require 'slack-ruby-bot/commands/about' -require 'slack-ruby-bot/commands/help' -require 'slack-ruby-bot/commands/hi' -require 'slack-ruby-bot/commands/unknown' diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/about.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/about.rb deleted file mode 100644 index 9950c8f..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/about.rb +++ /dev/null @@ -1,12 +0,0 @@ -module SlackRubyBot - module Commands - class Default < Base - command 'about' - match(/^(?[\w[:punct:]@<>]*)$/) - - def self.call(client, data, _match) - send_message_with_gif client, data.channel, SlackRubyBot::ABOUT, 'selfie' - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/base.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/base.rb deleted file mode 100644 index d2c657d..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/base.rb +++ /dev/null @@ -1,119 +0,0 @@ -module SlackRubyBot - module Commands - class Base - class_attribute :routes - - def self.send_message(client, channel, text, options = {}) - if text && text.length > 0 - send_client_message(client, { channel: channel, text: text }.merge(options)) - else - send_message_with_gif client, channel, 'Nothing to see here.', 'nothing', options - end - end - - def self.send_message_with_gif(client, channel, text, keywords, options = {}) - get_gif_and_send({ - client: client, - channel: channel, - text: text, - keywords: keywords - }.merge(options)) - end - - def self.send_gif(client, channel, keywords, options = {}) - get_gif_and_send({ - client: client, - channel: channel, - keywords: keywords - }.merge(options)) - end - - def self.logger - @logger ||= begin - $stdout.sync = true - Logger.new(STDOUT) - end - end - - def self.default_command_name - name && name.split(':').last.downcase - end - - def self.operator(*values, &block) - values.each do |value| - match Regexp.new("^(?\\#{value})(?.*)$", Regexp::IGNORECASE), &block - end - end - - def self.command(*values, &block) - values.each do |value| - match Regexp.new("^(?[\\w[:punct:]@<>]*)[\\s]+(?#{value})$", Regexp::IGNORECASE), &block - match Regexp.new("^(?[\\w[:punct:]@<>]*)[\\s]+(?#{value})[\\s]+(?.*)$", Regexp::IGNORECASE), &block - end - end - - def self.invoke(client, data) - self.finalize_routes! - expression = parse(data) - called = false - routes.each_pair do |route, method| - match = route.match(expression) - next unless match - next if match.names.include?('bot') && !SlackRubyBot.config.name?(match['bot']) - called = true - if method - method.call(client, data, match) - elsif self.respond_to?(:call) - send(:call, client, data, match) - else - fail NotImplementedError, data.text - end - break - end - called - end - - def self.match(match, &block) - self.routes ||= {} - self.routes[match] = block - end - - private - - def self.parse(data) - text = data.text - return text unless data.channel && data.channel[0] == 'D' && data.user && data.user != SlackRubyBot.config.user_id - SlackRubyBot.config.names.each do |name| - text.downcase.tap do |td| - return text if td == name || td.starts_with?("#{name} ") - end - end - "#{SlackRubyBot.config.user} #{text}" - end - - def self.finalize_routes! - return if self.routes && self.routes.any? - command default_command_name - end - - def self.get_gif_and_send(options = {}) - options = options.dup - gif = begin - keywords = options.delete(:keywords) - Giphy.random(keywords) - rescue StandardError => e - logger.warn "Giphy.random: #{e.message}" - nil - end - client = options.delete(:client) - text = options.delete(:text) - text = [text, gif && gif.image_url.to_s].compact.join("\n") - send_client_message(client, { text: text }.merge(options)) - end - - def self.send_client_message(client, data) - client.message(data) - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/help.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/help.rb deleted file mode 100644 index 5a08842..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/help.rb +++ /dev/null @@ -1,9 +0,0 @@ -module SlackRubyBot - module Commands - class Help < Base - def self.call(client, data, _match) - send_message_with_gif client, data.channel, 'See https://github.com/dblock/slack-ruby-bot, please.', 'help' - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/hi.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/hi.rb deleted file mode 100644 index 3495c7b..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/hi.rb +++ /dev/null @@ -1,9 +0,0 @@ -module SlackRubyBot - module Commands - class Hi < Base - def self.call(client, data, _match) - send_message client, data.channel, "Hi <@#{data.user}>!" - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/unknown.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/unknown.rb deleted file mode 100644 index e9f8508..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/commands/unknown.rb +++ /dev/null @@ -1,11 +0,0 @@ -module SlackRubyBot - module Commands - class Unknown < Base - match(/^(?\w*)[\s]*(?.*)$/) - - def self.call(client, data, _match) - send_message_with_gif client, data.channel, "Sorry <@#{data.user}>, I don't understand that command!", 'idiot' - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/config.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/config.rb deleted file mode 100644 index f8ca182..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/config.rb +++ /dev/null @@ -1,21 +0,0 @@ -module SlackRubyBot - module Config - extend self - - attr_accessor :token - attr_accessor :url - attr_accessor :aliases - attr_accessor :user - attr_accessor :user_id - attr_accessor :team - attr_accessor :team_id - - def names - [user, aliases, "<@#{user_id.downcase}>", "<@#{user_id.downcase}>:", "#{user}:"].compact.flatten - end - - def name?(name) - name && names.include?(name.downcase) - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks.rb deleted file mode 100644 index 6c6c436..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'slack-ruby-bot/hooks/base' -require 'slack-ruby-bot/hooks/hello' -require 'slack-ruby-bot/hooks/message' diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks/base.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks/base.rb deleted file mode 100644 index 8fdaf22..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks/base.rb +++ /dev/null @@ -1,10 +0,0 @@ -module SlackRubyBot - module Hooks - module Base - def included(caller) - caller.hooks ||= [] - caller.hooks << name.demodulize.underscore.to_sym - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks/hello.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks/hello.rb deleted file mode 100644 index 429a41a..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks/hello.rb +++ /dev/null @@ -1,11 +0,0 @@ -module SlackRubyBot - module Hooks - module Hello - extend Base - - def hello(_client, _data) - logger.info "Successfully connected to #{SlackRubyBot.config.url}." - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks/message.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks/message.rb deleted file mode 100644 index 3f9b76c..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/hooks/message.rb +++ /dev/null @@ -1,49 +0,0 @@ -module SlackRubyBot - module Hooks - module Message - extend Base - - def message(client, data) - data = Hashie::Mash.new(data) - data.text.strip! if data.text - result = child_command_classes.detect { |d| d.invoke(client, data) } - result ||= built_in_command_classes.detect { |d| d.invoke(client, data) } - result ||= SlackRubyBot::Commands::Unknown.tap { |d| d.invoke(client, data) } - result - end - - private - - # - # All commands. - # - # @return [Array] Descendants of SlackRubyBot::Commands::Base. - # - def command_classes - SlackRubyBot::Commands::Base.descendants - end - - # - # All non-built-in, ie. custom commands. - # - # @return [Array] Non-built-in descendants of SlackRubyBot::Commands::Base. - # - def child_command_classes - command_classes.reject do |k| - k.name && k.name.starts_with?('SlackRubyBot::Commands::') - end - end - - # - # All built-in commands. - # - # @return [Array] Built-in descendants of SlackRubyBot::Commands::Base. - # - def built_in_command_classes - command_classes.select do |k| - k.name && k.name.starts_with?('SlackRubyBot::Commands::') && k != SlackRubyBot::Commands::Unknown - end - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec.rb deleted file mode 100644 index cb6dbc3..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec.rb +++ /dev/null @@ -1,12 +0,0 @@ -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..')) - -require 'rubygems' -require 'rspec' -require 'rack/test' - -require 'config/environment' -require 'slack-ruby-bot' - -Dir[File.join(File.dirname(__FILE__), 'rspec/support', '**/*.rb')].each do |file| - require file -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/fixtures/slack/auth_test.yml b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/fixtures/slack/auth_test.yml deleted file mode 100644 index 7aea1b1..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/fixtures/slack/auth_test.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://slack.com/api/auth.test - body: - string: token=token - response: - status: - code: 200 - message: OK - body: - encoding: UTF-8 - string: '{"ok":true,"url":"https:\/\/rubybot.slack.com\/","team":"team_name","user":"user_name","team_id":"TDEADBEEF","user_id":"UBAADFOOD"}' - http_version: - recorded_at: Tue, 28 Apr 2015 12:55:22 GMT diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/fixtures/slack/migration_in_progress.yml b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/fixtures/slack/migration_in_progress.yml deleted file mode 100644 index 8a331a1..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/fixtures/slack/migration_in_progress.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://slack.com/api/rtm.start - body: - string: token=token - response: - status: - code: 200 - message: OK - body: - encoding: UTF-8 - string: '{"ok":false,"error":"migration_in_progress"}' - http_version: - recorded_at: Tue, 28 Apr 2015 12:55:22 GMT -- request: - method: post - uri: https://slack.com/api/rtm.start - body: - string: token=token - response: - status: - code: 200 - message: OK - body: - encoding: UTF-8 - string: '{"ok":false,"error":"unknown"}' - http_version: - recorded_at: Tue, 28 Apr 2015 12:55:22 GMT diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb deleted file mode 100644 index 0c9ecb8..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb +++ /dev/null @@ -1,30 +0,0 @@ -shared_examples 'a slack ruby bot' do - context 'not configured' do - before do - @slack_api_token = ENV.delete('SLACK_API_TOKEN') - end - after do - ENV['SLACK_API_TOKEN'] = @slack_api_token - end - it 'requires SLACK_API_TOKEN' do - expect { subject }.to raise_error RuntimeError, "Missing ENV['SLACK_API_TOKEN']." - end - end - context 'configured', vcr: { cassette_name: 'auth_test' } do - context 'run' do - before do - subject.send(:auth!) - end - after do - subject.send(:reset!) - end - it 'succeeds auth' do - expect(subject.config.url).to eq 'https://rubybot.slack.com/' - expect(subject.config.team).to eq 'team_name' - expect(subject.config.user).to eq 'user_name' - expect(subject.config.team_id).to eq 'TDEADBEEF' - expect(subject.config.user_id).to eq 'UBAADFOOD' - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb deleted file mode 100644 index 9fdba07..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'rspec/expectations' - -RSpec::Matchers.define :respond_with_error do |error, error_message| - match do |actual| - channel, user, message = parse(actual) - allow(Giphy).to receive(:random) - begin - expect do - client = app.send(:client) - app.send(:message, client, text: message, channel: channel, user: user) - end.to raise_error error, error_message - rescue RSpec::Expectations::ExpectationNotMetError => e - @error_message = e.message - raise e - end - true - end - - failure_message do |actual| - _, _, message = parse(actual) - @error_message || "expected for '#{message}' to fail with '#{expected}'" - end - - private - - def parse(actual) - actual = { message: actual } unless actual.is_a?(Hash) - [actual[:channel] || 'channel', actual[:user] || 'user', actual[:message]] - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb deleted file mode 100644 index ce335d3..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'rspec/expectations' - -RSpec::Matchers.define :respond_with_slack_message do |expected| - match do |actual| - channel, user, message = parse(actual) - allow(Giphy).to receive(:random) - client = app.send(:client) - expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: channel, text: expected) - app.send(:message, client, text: message, channel: channel, user: user) - true - end - - private - - def parse(actual) - actual = { message: actual } unless actual.is_a?(Hash) - [actual[:channel] || 'channel', actual[:user] || 'user', actual[:message]] - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack_api_key.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack_api_key.rb deleted file mode 100644 index fdaff36..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack_api_key.rb +++ /dev/null @@ -1,5 +0,0 @@ -RSpec.configure do |config| - config.before :all do - ENV['SLACK_API_TOKEN'] ||= 'test' - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb deleted file mode 100644 index ec162ab..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb +++ /dev/null @@ -1,9 +0,0 @@ -RSpec.configure do |config| - config.before :each do - SlackRubyBot.configure do |c| - c.token = 'testtoken' - c.user = 'rubybot' - c.user_id = 'DEADBEEF' - end - end -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/vcr.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/vcr.rb deleted file mode 100644 index 98a2292..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/rspec/support/vcr.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'vcr' - -VCR.configure do |config| - config.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures/slack') - config.hook_into :webmock - # config.default_cassette_options = { record: :new_episodes } - config.configure_rspec_metadata! -end diff --git a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/version.rb b/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/version.rb deleted file mode 100644 index 6caf7b4..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack-ruby-bot/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module SlackRubyBot - VERSION = '0.4.4' -end diff --git a/slack-ruby-bot-0.4.4/lib/slack_ruby_bot.rb b/slack-ruby-bot-0.4.4/lib/slack_ruby_bot.rb deleted file mode 100644 index d0060b0..0000000 --- a/slack-ruby-bot-0.4.4/lib/slack_ruby_bot.rb +++ /dev/null @@ -1 +0,0 @@ -require 'slack-ruby-bot' diff --git a/slack-ruby-bot-0.4.4/screenshots/aliases.gif b/slack-ruby-bot-0.4.4/screenshots/aliases.gif deleted file mode 100644 index 78dbd95..0000000 Binary files a/slack-ruby-bot-0.4.4/screenshots/aliases.gif and /dev/null differ diff --git a/slack-ruby-bot-0.4.4/screenshots/demo.gif b/slack-ruby-bot-0.4.4/screenshots/demo.gif deleted file mode 100644 index 67ea7f6..0000000 Binary files a/slack-ruby-bot-0.4.4/screenshots/demo.gif and /dev/null differ diff --git a/slack-ruby-bot-0.4.4/screenshots/dms.gif b/slack-ruby-bot-0.4.4/screenshots/dms.gif deleted file mode 100644 index 3bae331..0000000 Binary files a/slack-ruby-bot-0.4.4/screenshots/dms.gif and /dev/null differ diff --git a/slack-ruby-bot-0.4.4/screenshots/register-bot.png b/slack-ruby-bot-0.4.4/screenshots/register-bot.png deleted file mode 100644 index 391a201..0000000 Binary files a/slack-ruby-bot-0.4.4/screenshots/register-bot.png and /dev/null differ diff --git a/slack-ruby-bot-0.4.4/screenshots/weather.gif b/slack-ruby-bot-0.4.4/screenshots/weather.gif deleted file mode 100644 index 8253897..0000000 Binary files a/slack-ruby-bot-0.4.4/screenshots/weather.gif and /dev/null differ diff --git a/slack-ruby-bot-0.4.4/slack-ruby-bot.gemspec b/slack-ruby-bot-0.4.4/slack-ruby-bot.gemspec deleted file mode 100644 index d2cf0e3..0000000 --- a/slack-ruby-bot-0.4.4/slack-ruby-bot.gemspec +++ /dev/null @@ -1,28 +0,0 @@ -$LOAD_PATH.push File.expand_path('../lib', __FILE__) -require 'slack-ruby-bot/version' - -Gem::Specification.new do |s| - s.name = 'slack-ruby-bot' - s.version = SlackRubyBot::VERSION - s.authors = ['Daniel Doubrovkine'] - s.email = 'dblock@dblock.org' - s.platform = Gem::Platform::RUBY - s.required_rubygems_version = '>= 1.3.6' - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- spec/*`.split("\n") - s.require_paths = ['lib'] - s.homepage = 'http://github.com/dblock/slack-ruby-bot' - s.licenses = ['MIT'] - s.summary = 'The easiest way to write a Slack bot in Ruby.' - s.add_dependency 'hashie' - s.add_dependency 'slack-ruby-client' - s.add_dependency 'activesupport' - s.add_dependency 'giphy', '~> 2.0.2' - s.add_dependency 'websocket-driver', '~> 0.5.4' - s.add_development_dependency 'rake' - s.add_development_dependency 'rspec' - s.add_development_dependency 'rack-test' - s.add_development_dependency 'vcr' - s.add_development_dependency 'webmock' - s.add_development_dependency 'rubocop', '0.32.1' -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/app_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/app_spec.rb deleted file mode 100644 index f918f1b..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/app_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::App do - def app - SlackRubyBot::App.new - end - it_behaves_like 'a slack ruby bot' - context 'retries on rtm.start errors' do - let(:client) { Slack::RealTime::Client.new } - let(:logger) { subject.send :logger } - before do - allow(subject).to receive(:sleep) - expect(Slack::RealTime::Client).to receive(:new).twice.and_return(client) - expect(logger).to receive(:error).twice - end - it 'migration_in_progress', vcr: { cassette_name: 'migration_in_progress' } do - expect do - subject.send :start! - end.to raise_error Slack::Web::Api::Error, 'unknown' - end - [Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError, Faraday::Error::SSLError].each do |err| - it "#{err}" do - expect(client).to receive(:start!) { fail err, 'Faraday' } - expect(client).to receive(:start!) { fail 'unknown' } - expect do - subject.send :start! - end.to raise_error 'unknown' - end - end - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/about_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/about_spec.rb deleted file mode 100644 index ec7ab87..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/about_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands::Default do - def app - SlackRubyBot::App.new - end - it 'lowercase' do - expect(message: SlackRubyBot.config.user).to respond_with_slack_message(SlackRubyBot::ABOUT) - end - it 'upcase' do - expect(message: SlackRubyBot.config.user.upcase).to respond_with_slack_message(SlackRubyBot::ABOUT) - end - it 'name:' do - expect(message: "#{SlackRubyBot.config.user}:").to respond_with_slack_message(SlackRubyBot::ABOUT) - end - it 'id' do - expect(message: "<@#{SlackRubyBot.config.user_id}>").to respond_with_slack_message(SlackRubyBot::ABOUT) - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/aliases_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/aliases_spec.rb deleted file mode 100644 index f3c79e8..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/aliases_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot do - def app - SlackRubyBot::App.new - end - before do - ENV['SLACK_RUBY_BOT_ALIASES'] = ':emoji: alias' - end - after do - ENV.delete('SLACK_RUBY_BOT_ALIASES') - end - it 'responds to emoji' do - expect(message: ':emoji: hi').to respond_with_slack_message('Hi <@user>!') - end - it 'responds to an alias' do - expect(message: 'alias hi').to respond_with_slack_message('Hi <@user>!') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_precedence_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_precedence_spec.rb deleted file mode 100644 index 0a9cd05..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_precedence_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'tomato' do |client, data, match| - send_message client, data.channel, "#{match[:command]}: #{match[:expression]}" - end - - command 'tomatoes' do |client, data, match| - send_message client, data.channel, "#{match[:command]}: #{match[:expression]}" - end - end - end - def app - SlackRubyBot::App.new - end - it 'matches commands' do - expect(message: "#{SlackRubyBot.config.user} tomato red").to respond_with_slack_message('tomato: red') - expect(message: "#{SlackRubyBot.config.user} tomatoes green").to respond_with_slack_message('tomatoes: green') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_spaces_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_spaces_spec.rb deleted file mode 100644 index 5b8d3fe..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_spaces_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'space' do |client, data, match| - send_message client, data.channel, "#{match[:command]}: #{match[:expression]}" - end - end - end - def app - SlackRubyBot::App.new - end - it 'matches leading spaces' do - expect(message: " #{SlackRubyBot.config.user} space red").to respond_with_slack_message('space: red') - end - it 'matches trailing spaces' do - expect(message: "#{SlackRubyBot.config.user} space red ").to respond_with_slack_message('space: red') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_spec.rb deleted file mode 100644 index 2bb3d70..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'sayhi' - command 'saybye' - - def self.call(client, data, match) - send_message client, data.channel, "#{match[:command]}: #{match[:expression]}" - end - end - end - def app - SlackRubyBot::App.new - end - it 'supports multiple commands' do - expect(message: "#{SlackRubyBot.config.user} sayhi arg1 arg2").to respond_with_slack_message('sayhi: arg1 arg2') - expect(message: "#{SlackRubyBot.config.user} saybye arg1 arg2").to respond_with_slack_message('saybye: arg1 arg2') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_with_block_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_with_block_spec.rb deleted file mode 100644 index 303950f..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/commands_with_block_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'sayhi' do |client, data, match| - send_message client, data.channel, "#{match[:command]}: #{match[:expression]}" - end - - command 'one', 'two' do |client, data, match| - send_message client, data.channel, "#{match[:command]}: #{match[:expression]}" - end - end - end - def app - SlackRubyBot::App.new - end - it 'supports multiple commands' do - expect(message: "#{SlackRubyBot.config.user} sayhi arg1 arg2").to respond_with_slack_message('sayhi: arg1 arg2') - expect(message: "#{SlackRubyBot.config.user} one arg1 arg2").to respond_with_slack_message('one: arg1 arg2') - expect(message: "#{SlackRubyBot.config.user} two arg1 arg2").to respond_with_slack_message('two: arg1 arg2') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/direct_messages_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/direct_messages_spec.rb deleted file mode 100644 index 757a1a8..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/direct_messages_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot do - def app - SlackRubyBot::App.new - end - context 'it responds to direct messages' do - it 'with bot name' do - expect(message: "#{SlackRubyBot.config.user} hi", channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!') - end - it 'with bot name capitalized' do - expect(message: "#{SlackRubyBot.config.user.upcase} hi", channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!') - end - it 'with bot user id' do - expect(message: "<@#{SlackRubyBot.config.user_id}> hi", channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!') - end - it 'without bot name' do - expect(message: 'hi', channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!') - end - end - context 'it responds to direct name calling' do - it 'with bot name' do - expect(message: "#{SlackRubyBot.config.user}", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT) - end - it 'with bot name capitalized' do - expect(message: "#{SlackRubyBot.config.user.upcase}", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT) - end - it 'with bot user id' do - expect(message: "<@#{SlackRubyBot.config.user_id}>", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT) - end - it 'with bot user id and a colon' do - expect(message: "<@#{SlackRubyBot.config.user_id}>:", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT) - end - it 'with bot user id and a colon and a space' do - expect(message: "<@#{SlackRubyBot.config.user_id}>: ", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT) - end - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/empty_text_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/empty_text_spec.rb deleted file mode 100644 index 1f61e0c..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/empty_text_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'empty_text' - - def self.call(client, data, _match) - send_message client, data.channel, nil - end - end - end - def app - SlackRubyBot::App.new - end - let(:client) { app.send(:client) } - it 'sends default text' do - allow(Giphy).to receive(:random) - expect(SlackRubyBot::Commands::Base).to receive(:send_message_with_gif).with(client, 'channel', 'Nothing to see here.', 'nothing', {}) - app.send(:message, client, text: "#{SlackRubyBot.config.user} empty_text", channel: 'channel', user: 'user') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/help_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/help_spec.rb deleted file mode 100644 index b01d61e..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/help_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands::Help do - def app - SlackRubyBot::App.new - end - it 'help' do - expect(message: "#{SlackRubyBot.config.user} help").to respond_with_slack_message('See https://github.com/dblock/slack-ruby-bot, please.') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/hi_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/hi_spec.rb deleted file mode 100644 index f6d7a73..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/hi_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands::Hi do - def app - SlackRubyBot::App.new - end - it 'says hi' do - expect(message: "#{SlackRubyBot.config.user} hi").to respond_with_slack_message('Hi <@user>!') - end - it 'says hi to bot:' do - expect(message: "#{SlackRubyBot.config.user}: hi").to respond_with_slack_message('Hi <@user>!') - end - it 'says hi to @bot' do - expect(message: "<@#{SlackRubyBot.config.user_id}> hi").to respond_with_slack_message('Hi <@user>!') - end - it 'says hi to @bot: ' do - expect(message: "<@#{SlackRubyBot.config.user_id}>: hi").to respond_with_slack_message('Hi <@user>!') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/nil_message_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/nil_message_spec.rb deleted file mode 100644 index e035529..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/nil_message_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'nil_text' - - def self.call(_client, data, _match) - send_message cilent, data.channel, nil - end - end - end - def app - SlackRubyBot::App.new - end - let(:client) { app.send(:client) } - it 'ignores nil messages' do - allow(Giphy).to receive(:random) - expect(SlackRubyBot::Commands::Base).to_not receive(:send_message_with_gif) - app.send(:message, client, text: nil, channel: 'channel', user: 'user') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/not_implemented_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/not_implemented_spec.rb deleted file mode 100644 index aa9c219..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/not_implemented_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands::Base do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'not_implemented' - end - end - def app - SlackRubyBot::App.new - end - it 'raises not implemented' do - expect(message: "#{SlackRubyBot.config.user} not_implemented").to respond_with_error(NotImplementedError, 'rubybot not_implemented') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/operators_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/operators_spec.rb deleted file mode 100644 index 1f6f6d7..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/operators_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - operator '=' - operator '-' - - def self.call(client, data, match) - send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}" - end - end - end - def app - SlackRubyBot::App.new - end - it 'supports operators' do - expect(message: '=2+2').to respond_with_slack_message('=: 2+2') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/operators_with_block_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/operators_with_block_spec.rb deleted file mode 100644 index 09e8170..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/operators_with_block_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - operator '=' do |client, data, match| - send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}" - end - - operator '+', '-' do |client, data, match| - send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}" - end - end - end - def app - SlackRubyBot::App.new - end - it 'supports operator blocks' do - expect(message: '=2+2').to respond_with_slack_message('=: 2+2') - expect(message: '+2+2').to respond_with_slack_message('+: 2+2') - expect(message: '-2+2').to respond_with_slack_message('-: 2+2') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/send_gif_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/send_gif_spec.rb deleted file mode 100644 index badd60b..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/send_gif_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'send_gif_spec' do |client, data, _match| - send_gif client, data.channel, 'dummy' - end - end - end - def app - SlackRubyBot::App.new - end - let(:client) { app.send(:client) } - let(:gif_image_url) { 'http://media2.giphy.com/media/pzOijFsdDrsS4/giphy.gif' } - it 'sends a gif' do - gif = Giphy::RandomGif.new('image_url' => gif_image_url) - expect(Giphy).to receive(:random).and_return(gif) - expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: gif_image_url) - app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user') - end - it 'eats up the error' do - expect(Giphy).to receive(:random) { fail 'oh no!' } - expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: '') - app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user') - end - it 'eats up nil gif' do - expect(Giphy).to receive(:random).and_return(nil) - expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: '') - app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/send_message_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/send_message_spec.rb deleted file mode 100644 index ef658b4..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/send_message_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'send_message_spec' do |client, data, match| - send_message client, data.channel, match['expression'] - end - end - end - def app - SlackRubyBot::App.new - end - let(:client) { app.send(:client) } - it 'sends a message' do - expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message') - app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_spec message", channel: 'channel', user: 'user') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb deleted file mode 100644 index eb9d321..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'send_message_with_gif_spec' do |client, data, match| - send_message_with_gif client, data.channel, match['expression'], 'dummy' - end - end - end - def app - SlackRubyBot::App.new - end - let(:client) { app.send(:client) } - let(:gif_image_url) { 'http://media2.giphy.com/media/pzOijFsdDrsS4/giphy.gif' } - it 'sends a message with gif' do - gif = Giphy::RandomGif.new('image_url' => gif_image_url) - expect(Giphy).to receive(:random).and_return(gif) - expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: "message\n#{gif_image_url}") - app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user') - end - it 'eats up the error' do - expect(Giphy).to receive(:random) { fail 'oh no!' } - expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message') - app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user') - end - it 'eats up nil gif' do - expect(Giphy).to receive(:random).and_return(nil) - expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message') - app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/unknown_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/unknown_spec.rb deleted file mode 100644 index 6cf25e2..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/commands/unknown_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot::Commands::Unknown do - def app - SlackRubyBot::App.new - end - let(:client) { app.send(:client) } - it 'invalid command' do - expect(message: "#{SlackRubyBot.config.user} foobar").to respond_with_slack_message("Sorry <@user>, I don't understand that command!") - end - it 'does not respond to sad face' do - expect(SlackRubyBot::Commands::Base).to_not receive(:send_message) - SlackRubyBot::App.new.send(:message, client, text: ':((') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb deleted file mode 100644 index 46e8f31..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'spec_helper' - -describe RSpec do - let! :command do - Class.new(SlackRubyBot::Commands::Base) do - command 'raise' - - def self.call(_client, _data, match) - fail ArgumentError, match[:command] - end - end - end - def app - SlackRubyBot::App.new - end - it 'respond_with_error' do - expect(message: "#{SlackRubyBot.config.user} raise").to respond_with_error(ArgumentError, 'raise') - end -end diff --git a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/version_spec.rb b/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/version_spec.rb deleted file mode 100644 index 09f65db..0000000 --- a/slack-ruby-bot-0.4.4/spec/slack-ruby-bot/version_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' - -describe SlackRubyBot do - it 'has a version' do - expect(SlackRubyBot::VERSION).to_not be nil - end -end diff --git a/slack-ruby-bot-0.4.4/spec/spec_helper.rb b/slack-ruby-bot-0.4.4/spec/spec_helper.rb deleted file mode 100644 index 833f3be..0000000 --- a/slack-ruby-bot-0.4.4/spec/spec_helper.rb +++ /dev/null @@ -1 +0,0 @@ -require 'slack-ruby-bot/rspec'