From 59e3b1d6c58ac6aa2c35e3491cfcde93b483166e Mon Sep 17 00:00:00 2001 From: dblock Date: Thu, 9 Jul 2015 15:24:08 -0400 Subject: [PATCH] Remove the monkey-patch for supporting operators. --- Gemfile.lock | 40 ++++++++++++++--------------- slack-mathbot.rb | 1 - slack-mathbot/commands/calculate.rb | 2 ++ slack-mathbot/hooks/message.rb | 19 -------------- 4 files changed, 22 insertions(+), 40 deletions(-) delete mode 100644 slack-mathbot/hooks/message.rb diff --git a/Gemfile.lock b/Gemfile.lock index 837e9dd..e836747 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/dblock/slack-ruby-bot.git - revision: fa17932abf5ad0c5d25c652f4a46cec1d93a99d4 + revision: 8385892c5ff6b7860435ca4b1f46017bb45175db specs: slack-ruby-bot (0.2.0) activesupport @@ -28,7 +28,7 @@ GEM eventmachine (1.0.7) faraday (0.9.1) multipart-post (>= 1.2, < 3) - faraday_middleware (0.9.1) + faraday_middleware (0.9.2) faraday (>= 0.7.4, < 0.10) faraday_middleware-parse_oj (0.3.0) faraday (~> 0.9.0) @@ -50,34 +50,34 @@ GEM launchy (2.4.3) addressable (~> 2.3) minitest (5.7.0) - multi_json (1.11.1) + multi_json (1.11.2) multipart-post (2.0.0) oj (2.12.9) parser (2.3.0.pre.2) ast (>= 1.1, < 3.0) powerpack (0.1.1) - puma (2.11.0) + puma (2.11.3) rack (>= 1.1, < 2.0) - rack (1.6.0) + 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.2.0) - rspec-core (~> 3.2.0) - rspec-expectations (~> 3.2.0) - rspec-mocks (~> 3.2.0) - rspec-core (3.2.3) - rspec-support (~> 3.2.0) - rspec-expectations (3.2.1) + rspec (3.3.0) + rspec-core (~> 3.3.0) + rspec-expectations (~> 3.3.0) + rspec-mocks (~> 3.3.0) + rspec-core (3.3.1) + rspec-support (~> 3.3.0) + rspec-expectations (3.3.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.2.0) - rspec-mocks (3.2.1) + rspec-support (~> 3.3.0) + rspec-mocks (3.3.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.2.0) - rspec-support (3.2.2) + rspec-support (~> 3.3.0) + rspec-support (3.3.0) rubocop (0.31.0) astrolabe (~> 1.3) parser (>= 2.2.2.1, < 3.0) @@ -86,10 +86,10 @@ GEM ruby-progressbar (~> 1.4) ruby-progressbar (1.7.5) safe_yaml (1.0.4) - sinatra (1.4.5) + sinatra (1.4.6) rack (~> 1.4) rack-protection (~> 1.4) - tilt (~> 1.3, >= 1.3.4) + tilt (>= 1.3, < 3) slack-api (1.1.6) faraday (>= 0.7, < 0.10) faraday_middleware (~> 0.8) @@ -97,14 +97,14 @@ GEM multi_json (~> 1.0, >= 1.0.3) thor (0.19.1) thread_safe (0.3.5) - tilt (1.4.1) + 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-driver (0.6.0) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) diff --git a/slack-mathbot.rb b/slack-mathbot.rb index 41a32ce..a13c570 100644 --- a/slack-mathbot.rb +++ b/slack-mathbot.rb @@ -1,6 +1,5 @@ require 'slack-ruby-bot' require 'slack-mathbot/version' require 'slack-mathbot/about' -require 'slack-mathbot/hooks/message' require 'slack-mathbot/commands' require 'slack-mathbot/app' diff --git a/slack-mathbot/commands/calculate.rb b/slack-mathbot/commands/calculate.rb index 27e7083..1a495af 100644 --- a/slack-mathbot/commands/calculate.rb +++ b/slack-mathbot/commands/calculate.rb @@ -1,6 +1,8 @@ module SlackMathbot module Commands class Calculate < SlackRubyBot::Commands::Base + operator '=' + def self.call(data, _command, arguments) result = Dentaku::Calculator.new.evaluate(arguments.join) result = result.to_s if result diff --git a/slack-mathbot/hooks/message.rb b/slack-mathbot/hooks/message.rb deleted file mode 100644 index 0042bce..0000000 --- a/slack-mathbot/hooks/message.rb +++ /dev/null @@ -1,19 +0,0 @@ -module SlackRubyBot - module Hooks - module Message - private - - # TODO: remove monkey-patch - def parse_command(text) - return unless text - text = '= ' + text[1..text.length] if text[0] == '=' - parts = text.split.reject(&:blank?) - if parts && parts[0] == '=' - parts[0] = SlackRubyBot.config.user - parts.insert 1, 'calculate' - end - [parts.first.downcase, parts[1].try(:downcase), parts[2..parts.length]] if parts && parts.any? - end - end - end -end