Class: HelpPlugin

Inherits:
Campfire::PollingBot::Plugin show all
Defined in:
lib/campfire/polling_bot/plugins/help/help_plugin.rb

Overview

Plugin to display available commands for each plugin

Constant Summary

Constants inherited from Campfire::PollingBot::Plugin

Campfire::PollingBot::Plugin::HALT

Instance Attribute Summary

Attributes inherited from Campfire::PollingBot::Plugin

#bot, #config

Instance Method Summary collapse

Methods inherited from Campfire::PollingBot::Plugin

accepts, #accepts?, accepts?, bot, bot=, directory, directory=, inherited, #initialize, load_all, load_plugin_classes, #logger, logger, priority, #priority, requires_config, requires_config?, #requires_config?, setup_database, subclasses, #to_s

Constructor Details

This class inherits a constructor from Campfire::PollingBot::Plugin

Instance Method Details

#helpObject

return array of available commands and descriptions



25
26
27
# File 'lib/campfire/polling_bot/plugins/help/help_plugin.rb', line 25

def help
  [['help', "this message"]]
end

#process(message) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/campfire/polling_bot/plugins/help/help_plugin.rb', line 6

def process(message)
  person = message.person
  case message.command
  when /help(?:\s(.*))?/i
    if $1
      name = $1
      plugin = plugin_helps.keys.find do |k|
        k =~ /(#{name}|#{name.gsub(/s$/i, '')})(plugin)?/i
      end
      matched_helps = { plugin => plugin_helps[plugin] } if plugin
    end
    matched_helps ||= plugin_helps

    bot.paste msg_for(matched_helps)
    return HALT
  end
end