Skip to content

Commit

Permalink
show commands command WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
accessd committed Apr 27, 2016
1 parent 5fa81fe commit fb2e340
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/slack-ruby-bot/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
27 changes: 27 additions & 0 deletions lib/slack-ruby-bot/commands/commands.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fb2e340

Please sign in to comment.