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.

33 lines
989 B

  1. module SlackMathbot
  2. module Hooks
  3. module Message
  4. extend Base
  5. def message(data)
  6. data = Hashie::Mash.new(data)
  7. bot_name, command, arguments = parse_command(data.text)
  8. return unless bot_name == SlackMathbot.config.user
  9. klass = command_to_class(command || 'Default')
  10. klass.call data, command, arguments
  11. end
  12. private
  13. def parse_command(text)
  14. return unless text
  15. text = '= ' + text[1..text.length] if text[0] == '='
  16. parts = text.split.reject(&:blank?)
  17. if parts && parts[0] == '='
  18. parts[0] = SlackMathbot.config.user
  19. parts.insert 1, 'calculate'
  20. end
  21. [parts.first.downcase, parts[1].try(:downcase), parts[2..parts.length]] if parts && parts.any?
  22. end
  23. def command_to_class(command)
  24. klass = "SlackMathbot::Commands::#{command.titleize}".constantize rescue nil
  25. klass || SlackMathbot::Commands::Unknown
  26. end
  27. end
  28. end
  29. end