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.

49 lines
1.3 KiB

9 years ago
  1. module SlackRubyBot
  2. module Hooks
  3. module Message
  4. extend Base
  5. def message(client, data)
  6. data = Hashie::Mash.new(data)
  7. data.text.strip! if data.text
  8. result = child_command_classes.detect { |d| d.invoke(client, data) }
  9. result ||= built_in_command_classes.detect { |d| d.invoke(client, data) }
  10. result ||= SlackRubyBot::Commands::Unknown.tap { |d| d.invoke(client, data) }
  11. result
  12. end
  13. private
  14. #
  15. # All commands.
  16. #
  17. # @return [Array] Descendants of SlackRubyBot::Commands::Base.
  18. #
  19. def command_classes
  20. SlackRubyBot::Commands::Base.descendants
  21. end
  22. #
  23. # All non-built-in, ie. custom commands.
  24. #
  25. # @return [Array] Non-built-in descendants of SlackRubyBot::Commands::Base.
  26. #
  27. def child_command_classes
  28. command_classes.reject do |k|
  29. k.name && k.name.starts_with?('SlackRubyBot::Commands::')
  30. end
  31. end
  32. #
  33. # All built-in commands.
  34. #
  35. # @return [Array] Built-in descendants of SlackRubyBot::Commands::Base.
  36. #
  37. def built_in_command_classes
  38. command_classes.select do |k|
  39. k.name && k.name.starts_with?('SlackRubyBot::Commands::') && k != SlackRubyBot::Commands::Unknown
  40. end
  41. end
  42. end
  43. end
  44. end