A Slack Bot that pulls Pixiv information and posts the full image(s) into Slack, with iOS shortcuts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

  1. module SlackMathbot
  2. module Commands
  3. class Calculator < SlackRubyBot::Commands::Base
  4. operator '=' do |client, _data, _match|
  5. # Set API key (donut steal)
  6. Wolfram.appid = "R3KHQ2-2T2769PP4P"
  7. # Get equation part of argument
  8. eq = _match[1..-1]
  9. # Get results from Wolfram Alpha
  10. result = Wolfram.fetch(eq[1])
  11. # Get hash of results
  12. hash = Wolfram::HashPresenter.new(result).to_hash
  13. # Debug output hash
  14. puts hash
  15. # Breakdown hash
  16. pods = hash[:pods]
  17. # Try for results
  18. result = pods["Result"]
  19. puts result
  20. # If result exists
  21. if result != nil
  22. # Prettify equivalency
  23. result[0].sub! "~~", ""
  24. send_message client, _data.channel, result[0]
  25. else
  26. # If result doesn't exist, look for the real solution
  27. solution = pods["Real solution"]
  28. puts solution
  29. # If the real solution exists
  30. if solution != nil
  31. # Prettify equivalency
  32. solution[0].sub! "~~", ""
  33. send_message client, _data.channel, solution[0]
  34. else
  35. # Check the other possible name for real solutions
  36. solution = pods["Real solutions"]
  37. # Prettify equivalency
  38. solution[0].sub! "~~", ""
  39. puts solution
  40. send_message client, _data.channel, solution[0]
  41. end
  42. end
  43. end
  44. end
  45. end
  46. end