Browse Source

Trying for a clean slate

master
Daniel Muckerman 9 years ago
parent
commit
bcc44e5d3a
33 changed files with 14 additions and 585 deletions
  1. +0
    -3
      CHANGELOG.md
  2. +0
    -139
      CONTRIBUTING.md
  3. +0
    -29
      DEPLOYMENT.md
  4. +1
    -18
      Gemfile
  5. +0
    -119
      Gemfile.lock
  6. +0
    -22
      LICENSE.md
  7. +1
    -1
      Procfile
  8. +0
    -46
      README.md
  9. +0
    -18
      Rakefile
  10. +0
    -6
      app.json
  11. +0
    -16
      config.ru
  12. +12
    -4
      numberman.rb
  13. BIN
      screenshots/example.gif
  14. BIN
      screenshots/register-bot.png
  15. BIN
      screenshots/two-plus-two.gif
  16. +0
    -5
      slack-mathbot.rb
  17. +0
    -7
      slack-mathbot/about.rb
  18. +0
    -4
      slack-mathbot/app.rb
  19. +0
    -4
      slack-mathbot/commands.rb
  20. +0
    -11
      slack-mathbot/commands/about.rb
  21. +0
    -13
      slack-mathbot/commands/echo.rb
  22. +0
    -9
      slack-mathbot/commands/help.rb
  23. +0
    -3
      slack-mathbot/version.rb
  24. +0
    -8
      spec/slack-mathbot/app_spec.rb
  25. +0
    -13
      spec/slack-mathbot/commands/about_spec.rb
  26. +0
    -22
      spec/slack-mathbot/commands/calculate_spec.rb
  27. +0
    -10
      spec/slack-mathbot/commands/help_spec.rb
  28. +0
    -10
      spec/slack-mathbot/commands/hi_spec.rb
  29. +0
    -15
      spec/slack-mathbot/commands/unknown_spec.rb
  30. +0
    -7
      spec/slack-mathbot/version_spec.rb
  31. +0
    -9
      spec/spec_helper.rb
  32. +0
    -5
      spec/support/slack_mathbot.rb
  33. +0
    -9
      web.rb

+ 0
- 3
CHANGELOG.md View File

@ -1,3 +0,0 @@
### 0.1.0 (Next)
* Initial public release - [@dblock](https://github.com/dblock).

+ 0
- 139
CONTRIBUTING.md View File

@ -1,139 +0,0 @@
# Contributing to SlackMathbot
This project is work of [many contributors](https://github.com/dblock/slack-mathbot/graphs/contributors).
You're encouraged to submit [pull requests](https://github.com/dblock/slack-mathbot/pulls), [propose features and discuss issues](https://github.com/dblock/slack-mathbot/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-mathbot) and check out your copy.
```
git clone https://github.com/contributor/slack-mathbot.git
cd slack-mathbot
git remote add upstream https://github.com/dblock/slack-mathbot.git
```
## Bundle Install and Test
Ensure that you can build the project and run tests.
```
bundle install
bundle exec rake
```
## Run SlackMathbot 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=<your API token> foreman start`.
You can also create a `.env` file with `SLACK_API_TOKEN=<your 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-mathbot 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-mathbot/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.

+ 0
- 29
DEPLOYMENT.md View File

@ -1,29 +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.
## Deploy Slack-Mathbot
[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
### Environment
#### SLACK_API_TOKEN
Set SLACK_API_TOKEN from the Bot integration settings on Slack.
```
heroku config:add SLACK_API_TOKEN=...
```
#### GIPHY_API_KEY
Slack-Mathbot 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.
### 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.

+ 1
- 18
Gemfile View File

@ -1,21 +1,4 @@
source 'http://rubygems.org'
ruby '2.2.3'
gem 'slack-ruby-bot'
gem 'puma'
gem 'sinatra'
gem 'dentaku'
group :development, :test do
gem 'rake', '~> 10.4'
gem 'rubocop', '0.31.0'
gem 'foreman'
end
group :test do
gem 'rspec'
gem 'rack-test'
gem 'vcr'
gem 'webmock'
end
gem 'wolfram'

+ 0
- 119
Gemfile.lock View File

@ -1,119 +0,0 @@
GEM
remote: http://rubygems.org/
specs:
activesupport (4.2.3)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.8)
ast (2.0.0)
astrolabe (1.3.1)
parser (~> 2.2)
crack (0.4.2)
safe_yaml (~> 1.0.0)
dentaku (1.2.6)
diff-lcs (1.2.5)
eventmachine (1.0.7)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.9.2)
faraday (>= 0.7.4, < 0.10)
faraday_middleware-parse_oj (0.3.0)
faraday (~> 0.9.0)
faraday_middleware (~> 0.9.1)
oj (~> 2.0)
faye-websocket (0.10.0)
eventmachine (>= 0.12.0)
websocket-driver (>= 0.5.1)
foreman (0.78.0)
thor (~> 0.19.1)
giphy (2.0.2)
faraday (~> 0.9)
faraday_middleware (~> 0.9)
faraday_middleware-parse_oj (~> 0.3)
launchy (~> 2.4)
hashie (3.4.2)
i18n (0.7.0)
json (1.8.3)
launchy (2.4.3)
addressable (~> 2.3)
minitest (5.7.0)
multipart-post (2.0.0)
oj (2.12.10)
parser (2.2.2.6)
ast (>= 1.1, < 3.0)
powerpack (0.1.1)
puma (2.12.2)
rack (1.6.4)
rack-protection (1.5.3)
rack
rack-test (0.6.3)
rack (>= 1.0)
rainbow (2.0.0)
rake (10.4.2)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
rubocop (0.31.0)
astrolabe (~> 1.3)
parser (>= 2.2.2.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.7.5)
safe_yaml (1.0.4)
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
slack-ruby-bot (0.4.0)
activesupport
giphy (~> 2.0.2)
hashie
slack-ruby-client
websocket-driver (~> 0.5.4)
slack-ruby-client (0.1.0)
eventmachine
faraday
faraday_middleware
faye-websocket
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)
vcr (2.9.3)
webmock (1.21.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
websocket-driver (0.5.4)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
PLATFORMS
ruby
DEPENDENCIES
dentaku
foreman
puma
rack-test
rake (~> 10.4)
rspec
rubocop (= 0.31.0)
sinatra
slack-ruby-bot
vcr
webmock

+ 0
- 22
LICENSE.md View File

@ -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.

+ 1
- 1
Procfile View File

@ -1 +1 @@
web: bundle exec puma -p $PORT
console: bundle exec ruby numberman.rb

+ 0
- 46
README.md View File

@ -1,46 +0,0 @@
Slack-Mathbot
=============
[![Build Status](https://travis-ci.org/dblock/slack-mathbot.png)](https://travis-ci.org/dblock/slack-mathbot)
A math bot for Slack. Math is good for you.
![](screenshots/two-plus-two.gif)
## Installation
See [DEPLOYMENT](DEPLOYMENT.md).
## Usage
Invite your bot to a channel. Do math by starting a message with an equal sign.
![](screenshots/example.gif)
### Commands
#### mathbot calculate [expression]
Calculates an expression, currently just basic math. See [Dentaku](https://github.com/rubysolo/dentaku) for what's supported.
#### mathbot
Shows MathBot version and links.
#### mathbot hi
Politely says 'hi' back.
#### mathbot help
Get help.
## Contributing
See [CONTRIBUTING](CONTRIBUTING.md).
## Copyright and License
Copyright (c) 2015, Daniel Doubrovkine, Artsy and [Contributors](CHANGELOG.md).
This project is licensed under the [MIT License](LICENSE.md).

+ 0
- 18
Rakefile View File

@ -1,18 +0,0 @@
require 'rubygems'
require 'bundler'
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

+ 0
- 6
app.json View File

@ -1,6 +0,0 @@
{
"name": "Math bot for Slack",
"description": "Slack integration with math.",
"respository": "https://github.com/dblock/slack-mathbot",
"keywords": ["slack", "integration", "math"],
}

+ 0
- 16
config.ru View File

@ -1,16 +0,0 @@
$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

slack-mathbot/commands/calculate.rb → numberman.rb View File

@ -1,9 +1,10 @@
module SlackMathbot
module Commands
class Calculate < SlackRubyBot::Commands::Base
require 'slack-ruby-bot'
require 'wolfram'
module NumberManBot
class App < SlackRubyBot::App
operator '='
command 'calculate'
def self.call(client, data, match)
puts match[:expression]
result = Dentaku::Calculator.new.evaluate(match[:expression])
@ -17,6 +18,13 @@ module SlackMathbot
rescue StandardError => e
send_message client, data.channel, "Sorry, #{e.message}."
end
end
class Ping < SlackRubyBot::Commands::Base
def self.call(client, data, _match)
client.message text: 'pong', channel: data.channel
end
end
end
NumberManBot::App.instance.run

BIN
screenshots/example.gif View File

Before After
Width: 894  |  Height: 584  |  Size: 930 KiB

BIN
screenshots/register-bot.png View File

Before After
Width: 997  |  Height: 519  |  Size: 57 KiB

BIN
screenshots/two-plus-two.gif View File

Before After
Width: 721  |  Height: 150  |  Size: 18 KiB

+ 0
- 5
slack-mathbot.rb View File

@ -1,5 +0,0 @@
require 'slack-ruby-bot'
require 'slack-mathbot/version'
require 'slack-mathbot/about'
require 'slack-mathbot/commands'
require 'slack-mathbot/app'

+ 0
- 7
slack-mathbot/about.rb View File

@ -1,7 +0,0 @@
module SlackMathbot
ABOUT = <<-ABOUT
#{SlackMathbot::VERSION}
https://github.com/dblock/slack-mathbot
https://twitter.com/dblockdotorg
ABOUT
end

+ 0
- 4
slack-mathbot/app.rb View File

@ -1,4 +0,0 @@
module SlackMathbot
class App < SlackRubyBot::App
end
end

+ 0
- 4
slack-mathbot/commands.rb View File

@ -1,4 +0,0 @@
require 'slack-mathbot/commands/calculate'
require 'slack-mathbot/commands/echo'
require 'slack-mathbot/commands/about'
require 'slack-mathbot/commands/help'

+ 0
- 11
slack-mathbot/commands/about.rb View File

@ -1,11 +0,0 @@
module SlackMathbot
module Commands
class Default < SlackRubyBot::Commands::Base
match(/^(?<bot>\w*)$/)
def self.call(client, data, _match)
send_message client, data.channel, SlackMathbot::ABOUT
end
end
end
end

+ 0
- 13
slack-mathbot/commands/echo.rb View File

@ -1,13 +0,0 @@
module SlackMathbot
module Commands
class Echo < SlackRubyBot::Commands::Base
command 'echo'
def self.call(client, data, match)
send_message client, data.channel, match[:expression]
rescue StandardError => e
send_message client, data.channel, "Sorry, #{e.message}."
end
end
end
end

+ 0
- 9
slack-mathbot/commands/help.rb View File

@ -1,9 +0,0 @@
module SlackMathbot
module Commands
class Help < SlackRubyBot::Commands::Base
def self.call(client, data, _match)
send_message client, data.channel, 'See https://github.com/dblock/slack-mathbot, please.'
end
end
end
end

+ 0
- 3
slack-mathbot/version.rb View File

@ -1,3 +0,0 @@
module SlackMathbot
VERSION = '0.1.0'
end

+ 0
- 8
spec/slack-mathbot/app_spec.rb View File

@ -1,8 +0,0 @@
require 'spec_helper'
describe SlackMathbot::App do
def app
SlackMathbot::App.new
end
it_behaves_like 'a slack ruby bot'
end

+ 0
- 13
spec/slack-mathbot/commands/about_spec.rb View File

@ -1,13 +0,0 @@
require 'spec_helper'
describe SlackMathbot::Commands::Default do
def app
SlackMathbot::App.new
end
it 'mathbot' do
expect(message: 'mathbot').to respond_with_slack_message(SlackMathbot::ABOUT)
end
it 'Mathbot' do
expect(message: 'Mathbot').to respond_with_slack_message(SlackMathbot::ABOUT)
end
end

+ 0
- 22
spec/slack-mathbot/commands/calculate_spec.rb View File

@ -1,22 +0,0 @@
require 'spec_helper'
describe SlackMathbot::Commands::Calculate do
def app
SlackMathbot::App.new
end
it 'adds two numbers' do
expect(message: 'mathbot calculate 2+2', channel: 'channel').to respond_with_slack_message('4')
end
it 'adds two numbers via =' do
expect(message: '= 2+2', channel: 'channel').to respond_with_slack_message('4')
end
it 'adds two numbers via = without a space' do
expect(message: '=2+2', channel: 'channel').to respond_with_slack_message('4')
end
it 'sends something without an answer' do
expect(message: 'mathbot calculate pi', channel: 'channel').to respond_with_slack_message('Got nothing.')
end
it 'reports division by zero' do
expect(message: 'mathbot calculate 1/0', channel: 'channel').to respond_with_slack_message('Sorry, divided by 0.')
end
end

+ 0
- 10
spec/slack-mathbot/commands/help_spec.rb View File

@ -1,10 +0,0 @@
require 'spec_helper'
describe SlackMathbot::Commands::Help do
def app
SlackMathbot::App.new
end
it 'help' do
expect(message: 'mathbot help').to respond_with_slack_message('See https://github.com/dblock/slack-mathbot, please.')
end
end

+ 0
- 10
spec/slack-mathbot/commands/hi_spec.rb View File

@ -1,10 +0,0 @@
require 'spec_helper'
describe SlackRubyBot::Commands::Hi do
def app
SlackMathbot::App.new
end
it 'says hi' do
expect(message: 'mathbot hi').to respond_with_slack_message('Hi <@user>!')
end
end

+ 0
- 15
spec/slack-mathbot/commands/unknown_spec.rb View File

@ -1,15 +0,0 @@
require 'spec_helper'
describe SlackRubyBot::Commands::Unknown do
def app
SlackMathbot::App.new
end
let(:client) { app.send(:client) }
it 'invalid command' do
expect(message: 'mathbot 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)
SlackMathbot::App.new.send(:message, client, text: ':((')
end
end

+ 0
- 7
spec/slack-mathbot/version_spec.rb View File

@ -1,7 +0,0 @@
require 'spec_helper'
describe SlackMathbot do
it 'has a version' do
expect(SlackMathbot::VERSION).to_not be nil
end
end

+ 0
- 9
spec/spec_helper.rb View File

@ -1,9 +0,0 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
require 'slack-ruby-bot/rspec'
Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|
require file
end
require 'slack-mathbot'

+ 0
- 5
spec/support/slack_mathbot.rb View File

@ -1,5 +0,0 @@
RSpec.configure do |config|
config.before do
SlackRubyBot.config.user = 'mathbot'
end
end

+ 0
- 9
web.rb View File

@ -1,9 +0,0 @@
require 'sinatra/base'
module SlackMathbot
class Web < Sinatra::Base
get '/' do
'Math is good for you.'
end
end
end

Loading…
Cancel
Save