@ -0,0 +1,16 @@ | |||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | |||
require 'slack-numberman' | |||
require 'web' | |||
Thread.new do | |||
begin | |||
SlackNumberman::App.instance.run | |||
rescue Exception => e | |||
STDERR.puts "ERROR: #{e}" | |||
STDERR.puts e.backtrace | |||
raise e | |||
end | |||
end | |||
run SlackNumberman::Web |
@ -1 +1 @@ | |||
console: bundle exec ruby numberman.rb | |||
web: bundle exec puma -p $PORT |
@ -1,50 +0,0 @@ | |||
require 'slack-ruby-bot' | |||
require 'wolfram' | |||
module NumberManBot | |||
class App < SlackRubyBot::App | |||
end | |||
class Weather < SlackRubyBot::Commands::Base | |||
match(/^How is the weather in (?<location>\w*)\?$/i) do |client, data, match| | |||
send_message client, data.channel, "The weather in #{match[:location]} is nice." | |||
end | |||
end | |||
class Calculator < SlackRubyBot::Commands::Base | |||
operator '=' do |client, _data, _match| | |||
# implementation detail | |||
Wolfram.appid = "R3KHQ2-2T2769PP4P" | |||
eq = _match[1..-1] | |||
result = Wolfram.fetch(eq[1]) | |||
# to see the result as a hash of pods and assumptions: | |||
hash = Wolfram::HashPresenter.new(result).to_hash | |||
puts hash | |||
pods = hash[:pods] | |||
result = pods["Result"] | |||
#solution = pods["Real solutions"] | |||
puts result | |||
if result != nil | |||
result[0].sub! "~~", "≈" | |||
send_message client, _data.channel, result[0] | |||
else | |||
solution = pods["Real solution"] | |||
puts solution | |||
if solution != nil | |||
solution[0].sub! "~~", "≈" | |||
send_message client, _data.channel, solution[0] | |||
else | |||
solution = pods["Real solutions"] | |||
solution[0].sub! "~~", "≈" | |||
puts solution | |||
send_message client, _data.channel, solution[0] | |||
end | |||
end | |||
end | |||
end | |||
end | |||
NumberManBot::App.instance.run |
@ -0,0 +1,4 @@ | |||
require 'slack-ruby-bot' | |||
require 'wolfram' | |||
require 'slack-numberman/commands/calculate' | |||
require 'slack-numberman/app' |
@ -0,0 +1,4 @@ | |||
module SlackNumberman | |||
class App < SlackRubyBot::App | |||
end | |||
end |
@ -0,0 +1,54 @@ | |||
module SlackMathbot | |||
module Commands | |||
class Calculator < SlackRubyBot::Commands::Base | |||
operator '=' do |client, _data, _match| | |||
# Set API key (donut steal) | |||
Wolfram.appid = "R3KHQ2-2T2769PP4P" | |||
# Get equation part of argument | |||
eq = _match[1..-1] | |||
# Get results from Wolfram Alpha | |||
result = Wolfram.fetch(eq[1]) | |||
# Get hash of results | |||
hash = Wolfram::HashPresenter.new(result).to_hash | |||
# Debug output hash | |||
puts hash | |||
# Breakdown hash | |||
pods = hash[:pods] | |||
# Try for results | |||
result = pods["Result"] | |||
puts result | |||
# If result exists | |||
if result != nil | |||
# Prettify equivalency | |||
result[0].sub! "~~", "≈" | |||
send_message client, _data.channel, result[0] | |||
else | |||
# If result doesn't exist, look for the real solution | |||
solution = pods["Real solution"] | |||
puts solution | |||
# If the real solution exists | |||
if solution != nil | |||
# Prettify equivalency | |||
solution[0].sub! "~~", "≈" | |||
send_message client, _data.channel, solution[0] | |||
else | |||
# Check the other possible name for real solutions | |||
solution = pods["Real solutions"] | |||
# Prettify equivalency | |||
solution[0].sub! "~~", "≈" | |||
puts solution | |||
send_message client, _data.channel, solution[0] | |||
end | |||
end | |||
end | |||
end | |||
end | |||
end |
@ -0,0 +1,9 @@ | |||
require 'sinatra/base' | |||
module SlackMathbot | |||
class Web < Sinatra::Base | |||
get '/' do | |||
'Math is good for you.' | |||
end | |||
end | |||
end |