module HelpReply
Constants
- AUTHOR_NOTE
- STYLE_TITLE
Public Class Methods
Source
# File lib/help_reply.rb, line 22 def self.build_help_text(plugins_dir:, topic: nil, list_commands:) entries = list_commands.call(plugins_dir: plugins_dir) if topic && !topic.to_s.strip.empty? root = topic.to_s.strip.downcase.split(/\s+/, 2).first.to_s if HelpSections.section?(root) return build_help_text_for_section(root, entries: entries) end return build_help_text_for_topic(topic, entries: entries) end build_help_text_index(entries: entries) end
Source
# File lib/help_reply.rb, line 60 def self.build_help_text_for_section(section_id, entries:) matches = HelpSections.entries_for_section(section_id, entries: entries) return "No commands in #{section_id} section" if matches.empty? config = HelpSections.section_config(section_id) body = matches.map { |entry| format_entry(entry[:command], entry[:description]) } lines = [ IrcFormat.report_header(tag: "HELP", title: config[:label], style: STYLE_TITLE), *body, IrcFormat.report_footer("#{matches.length} commands", "!help for sections") ] lines.join("\n") end
Source
# File lib/help_reply.rb, line 75 def self.build_help_text_for_topic(topic, entries:) root = topic.to_s.strip.downcase.split(/\s+/, 2).first.to_s matches = entries.select do |entry| command = entry[:command].to_s.downcase command == root || command.start_with?("#{root} ") end return "No help for !#{topic}" if matches.empty? body = matches.sort_by { |entry| entry[:command] } .map { |entry| format_entry(entry[:command], entry[:description]) } lines = [ IrcFormat.report_header(tag: "HELP", title: "!#{root}", style: STYLE_TITLE), *body, IrcFormat.report_footer("#{matches.length} commands", "!help for sections") ] lines.join("\n") end
Source
# File lib/help_reply.rb, line 36 def self.build_help_text_index(entries:) grouped = HelpSections.group_entries(entries) if grouped.empty? return [ IrcFormat.report_header(tag: "HELP", title: "Rabbot commands", style: STYLE_TITLE), "No commands found", AUTHOR_NOTE ].join("\n") end lines = [ IrcFormat.report_header(tag: "HELP", title: "Rabbot commands", style: STYLE_TITLE), *HelpSections.section_index_lines(grouped), IrcFormat.report_footer( "#{entries.length} commands", "#{grouped.length} sections", "!help <section|command>" ), AUTHOR_NOTE ] lines.join("\n") end
Source
# File lib/help_reply.rb, line 13 def self.format_entry(command, description) description = description.to_s.strip if description.empty? "!#{command}" else "!#{command} - #{description}" end end