From fb2e3402ba9a164ba2bb313319aa38f892fd7c79 Mon Sep 17 00:00:00 2001 From: Accessd Date: Wed, 27 Apr 2016 20:24:58 +0300 Subject: [PATCH] show commands command WIP --- lib/slack-ruby-bot/commands.rb | 1 + lib/slack-ruby-bot/commands/commands.rb | 27 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 lib/slack-ruby-bot/commands/commands.rb diff --git a/lib/slack-ruby-bot/commands.rb b/lib/slack-ruby-bot/commands.rb index 19979be..fa1b4f8 100644 --- a/lib/slack-ruby-bot/commands.rb +++ b/lib/slack-ruby-bot/commands.rb @@ -2,4 +2,5 @@ require 'slack-ruby-bot/commands/about' require 'slack-ruby-bot/commands/help' require 'slack-ruby-bot/commands/hi' +require 'slack-ruby-bot/commands/commands' require 'slack-ruby-bot/commands/unknown' diff --git a/lib/slack-ruby-bot/commands/commands.rb b/lib/slack-ruby-bot/commands/commands.rb new file mode 100644 index 0000000..e052c9a --- /dev/null +++ b/lib/slack-ruby-bot/commands/commands.rb @@ -0,0 +1,27 @@ +module SlackRubyBot + module Commands + class Commands < Base + BUILTIN_COMMAND_CLASSES = [SlackRubyBot::Commands::Help, SlackRubyBot::Commands::Hi].freeze + + class << self + def call(client, data, _match) + commands = (BUILTIN_COMMAND_CLASSES + external_command_classes).map { |c| c.routes.keys }.flatten + client.say(channel: data.channel, text: "*Possible commands:*\n#{commands.join("\n")}") + end + + private + + def command_classes + SlackRubyBot::Commands::Base.descendants + end + + def external_command_classes + command_classes.reject do |k| + k.name && k.name.start_with?('SlackRubyBot::Commands') || k == SlackRubyBot::Bot + end + end + end + + end + end +end