diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d87d4be --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..045d435 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: ruby +rvm: + - 2.0.0 +script: bundle exec rake +before_install: + - gem update --system +notifications: + webhooks: + urls: + - https://lita-freenode.herokuapp.com/travis diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..b4e2a20 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2b87462 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2013 Jimmy Cuadra + +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/README.md b/README.md new file mode 100644 index 0000000..b2685b2 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# lita-coin + +A handler for [Lita](http://lita.io/) that simply flips a coin and tells you the result. + +## Installation + +Add lita-coin to your Lita instance's Gemfile: + +``` ruby +gem "lita-coin" +``` + +## Usage + +``` + [You] Lita: flip a coin +[Lita] Heads! +``` + +Alternatively, you can say "toss a coin," "coin flip," or "coin toss." + +## License + +[MIT](http://opensource.org/licenses/MIT) diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..b7e9ed5 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +task :default => :spec diff --git a/lib/lita-coin.rb b/lib/lita-coin.rb new file mode 100644 index 0000000..6998bd3 --- /dev/null +++ b/lib/lita-coin.rb @@ -0,0 +1 @@ +require "lita/handlers/coin" diff --git a/lib/lita/handlers/coin.rb b/lib/lita/handlers/coin.rb new file mode 100644 index 0000000..64de7e6 --- /dev/null +++ b/lib/lita/handlers/coin.rb @@ -0,0 +1,19 @@ +require "lita" + +module Lita + module Handlers + class Coin < Handler + route(/^(?:flip|toss)\s+a\s+coin/i, :flip, command: true, help: { + "flip a coin" => "Flips a coin and tells you the results." + }) + + route(/^coin\s+(?:toss|flip)/i, :flip, command: true) + + def flip(response) + response.reply %w(Heads! Tails!).sample + end + end + + Lita.register_handler(Coin) + end +end diff --git a/lita-coin.gemspec b/lita-coin.gemspec new file mode 100644 index 0000000..cf237de --- /dev/null +++ b/lita-coin.gemspec @@ -0,0 +1,23 @@ +Gem::Specification.new do |spec| + spec.name = "lita-coin" + spec.version = "0.0.1" + spec.authors = ["Jimmy Cuadra"] + spec.email = ["jimmy@jimmycuadra.com"] + spec.description = %q{A Lita handler for flipping a coin.} + spec.summary = %q{A Lita handler for flipping a coin.} + spec.homepage = "https://github.com/jimmycuadra/lita-coin" + spec.license = "MIT" + + spec.files = `git ls-files`.split($/) + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.require_paths = ["lib"] + + spec.add_runtime_dependency "lita", "~> 2.3" + + spec.add_development_dependency "bundler", "~> 1.3" + spec.add_development_dependency "rake" + spec.add_development_dependency "rspec", ">= 2.14" + spec.add_development_dependency "simplecov" + spec.add_development_dependency "coveralls" +end diff --git a/spec/lita/handlers/coin_spec.rb b/spec/lita/handlers/coin_spec.rb new file mode 100644 index 0000000..d3f3d44 --- /dev/null +++ b/spec/lita/handlers/coin_spec.rb @@ -0,0 +1,15 @@ +require "spec_helper" + +describe Lita::Handlers::Coin, lita_handler: true do + it { routes_command("flip a coin").to(:flip) } + it { routes_command("toss a coin").to(:flip) } + it { routes_command("coin flip").to(:flip) } + it { routes_command("coin toss").to(:flip) } + + describe "#flip" do + it "responds with the results of the flip" do + send_command("flip a coin") + expect(replies.last).to match(/(?:Heads|Tails)!/) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..90f649d --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,10 @@ +require "simplecov" +require "coveralls" +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ + SimpleCov::Formatter::HTMLFormatter, + Coveralls::SimpleCov::Formatter +] +SimpleCov.start { add_filter "/spec/" } + +require "lita-coin" +require "lita/rspec"