From c148fc9b9efd85b2dec9279e4a495c8edc3e1002 Mon Sep 17 00:00:00 2001 From: Daniel Muckerman Date: Fri, 9 Oct 2015 17:16:55 -0400 Subject: [PATCH] Testing... Well, test --- Gemfile | 2 +- slack-mathbot/commands.rb | 1 + slack-mathbot/commands/test.rb | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 slack-mathbot/commands/test.rb diff --git a/Gemfile b/Gemfile index a9c80b8..a1f9a13 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -ruby '2.2.0' +ruby '2.2.3' gem 'slack-ruby-bot' gem 'puma' diff --git a/slack-mathbot/commands.rb b/slack-mathbot/commands.rb index defec04..3fb026b 100644 --- a/slack-mathbot/commands.rb +++ b/slack-mathbot/commands.rb @@ -1,3 +1,4 @@ require 'slack-mathbot/commands/calculate' require 'slack-mathbot/commands/about' require 'slack-mathbot/commands/help' +require 'slack-mathbot/commands/test' diff --git a/slack-mathbot/commands/test.rb b/slack-mathbot/commands/test.rb new file mode 100644 index 0000000..6ca4e0b --- /dev/null +++ b/slack-mathbot/commands/test.rb @@ -0,0 +1,21 @@ +module SlackMathbot + module Commands + class Test < SlackRubyBot::Commands::Base + operator ']' + command 'test' + + def self.call(client, data, match) + send_message client, data.channel, match + result = Dentaku::Calculator.new.evaluate(match[:expression]) if match.names.include?('expression') + result = result.to_s if result + if result && result.length > 0 + send_message client, data.channel, result + else + send_message client, data.channel, 'Got nothing.' + end + rescue StandardError => e + send_message client, data.channel, "Sorry, #{e.message}." + end + end + end +end