lib/lita/handlers/help.rb in lita-2.7.2 vs lib/lita/handlers/help.rb in lita-3.0.0
- old
+ new
@@ -1,16 +1,13 @@
module Lita
+ # A namespace to hold all subclasses of {Handler}.
module Handlers
# Provides online help about Lita commands for users.
class Help < Handler
route(/^help\s*(.+)?/, :help, command: true, help: {
- "help" => %{
-Lists help information for terms and command the robot will respond to.
-}.gsub(/\n/, ""),
- "help COMMAND" => %{
-Lists help information for terms or commands that begin with COMMAND.
-}.gsub(/\n/, "")
+ "help" => t("help.help_value"),
+ t("help.help_command_key") => t("help.help_command_value")
})
# Outputs help information about Lita commands.
# @param response [Lita::Response] The response object.
# @return [void]
@@ -29,23 +26,19 @@
end
end
# Creates an array of help info for all registered routes.
def build_help(response)
- output = []
-
- Lita.handlers.each do |handler|
- handler.routes.each do |route|
- route.help.each do |command, description|
- next unless authorized?(response.user, route.required_groups)
- command = "#{name}: #{command}" if route.command?
- output << "#{command} - #{description}"
+ Lita.handlers.map do |handler|
+ handler.routes.map do |route|
+ route.help.map do |command, description|
+ if authorized?(response.user, route.required_groups)
+ help_command(route, command, description)
+ end
end
end
- end
-
- output
+ end.flatten.compact
end
# Filters the help output by an optional command.
def filter_help(output, response)
filter = response.matches[0][0]
@@ -53,9 +46,15 @@
if filter
output.select { |line| /(?:@?#{name}[:,]?)?#{filter}/i === line }
else
output
end
+ end
+
+ # Formats an individual command's help message.
+ def help_command(route, command, description)
+ command = "#{name}: #{command}" if route.command?
+ "#{command} - #{description}"
end
# The way the bot should be addressed in order to trigger a command.
def name
Lita.config.robot.mention_name || Lita.config.robot.name