From 13bde4ef240652ff14ae9dbf90e15b83f723cfef Mon Sep 17 00:00:00 2001 From: dB Date: Thu, 2 Jul 2015 15:08:47 -0400 Subject: [PATCH] Monkey patch to support operator =. --- Gemfile | 2 +- Gemfile.lock | 17 +++++++++++------ slack-mathbot.rb | 1 + slack-mathbot/hooks/message.rb | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 slack-mathbot/hooks/message.rb diff --git a/Gemfile b/Gemfile index 6b52a1b..3183ebd 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'http://rubygems.org' ruby '2.1.6' -gem 'slack-ruby-bot' +gem 'slack-ruby-bot', github: 'dblock/slack-ruby-bot' gem 'puma' gem 'sinatra' gem 'dentaku' diff --git a/Gemfile.lock b/Gemfile.lock index 3558f97..837e9dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,13 @@ +GIT + remote: git://github.com/dblock/slack-ruby-bot.git + revision: fa17932abf5ad0c5d25c652f4a46cec1d93a99d4 + specs: + slack-ruby-bot (0.2.0) + activesupport + giphy (~> 2.0.2) + hashie + slack-api (~> 1.1.6) + GEM remote: http://rubygems.org/ specs: @@ -85,11 +95,6 @@ GEM faraday_middleware (~> 0.8) faye-websocket (~> 0.9.2) multi_json (~> 1.0, >= 1.0.3) - slack-ruby-bot (0.1.0) - activesupport - giphy (~> 2.0.2) - hashie - slack-api (~> 1.1.6) thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) @@ -115,6 +120,6 @@ DEPENDENCIES rspec rubocop (= 0.31.0) sinatra - slack-ruby-bot + slack-ruby-bot! vcr webmock diff --git a/slack-mathbot.rb b/slack-mathbot.rb index a13c570..41a32ce 100644 --- a/slack-mathbot.rb +++ b/slack-mathbot.rb @@ -1,5 +1,6 @@ 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/hooks/message.rb b/slack-mathbot/hooks/message.rb new file mode 100644 index 0000000..0042bce --- /dev/null +++ b/slack-mathbot/hooks/message.rb @@ -0,0 +1,19 @@ +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