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.

64 lines
1.6 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. if solution != nil
  38. # Prettify equivalency
  39. solution[0].sub! "~~", ""
  40. puts solution
  41. send_message client, _data.channel, solution[0]
  42. else
  43. decimal = pods["Decimal approximation"]
  44. if decimal != nil
  45. puts decimal
  46. send_message client, _data.channel, decimal[0]
  47. end
  48. end
  49. end
  50. end
  51. end
  52. end
  53. end
  54. end