Class: RSlack::HelpAction

Inherits:
Action
  • Object
show all
Defined in:
lib/rslack/actions/help.rb

Instance Attribute Summary

Attributes inherited from Action

#bot

Instance Method Summary collapse

Methods inherited from Action

#initialize, #memory, route

Constructor Details

This class inherits a constructor from RSlack::Action

Instance Method Details

#help(msg) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rslack/actions/help.rb', line 11

def help(msg)
  options = msg.var.options
  routes  = bot.routes.select { |r| r.helptext || options.to_s.split.include?('--all') }

  content = StringIO.new
  content.puts "```"
  routes.map do |route|
    prefix = [(bot.name unless route.matchall), route.regexp.inspect].compact.join(' ') + ':'
    indent = (prefix.size / 4 + 1) * 4

    content.print "#{prefix.ljust(indent)}"
    content.print "`#{route.helptext}`" if route.helptext
    content.puts
  end
  content.puts "```"

  bot.reply(msg, text: content.string)
end