Sha256: eef719531c7a5790f8081ca63e09389e436a303b24217c81bc0d698711161f21

Contents?: true

Size: 848 Bytes

Versions: 3

Compression:

Stored size: 848 Bytes

Contents

module Cognition
  module Plugins
    class Default < Cognition::Plugins::Base
      # rubocop:disable Lint/AmbiguousRegexpLiteral
      match /^ping/i, :pong, help: {
        "ping" => "Test if the endpoint is responding. Returns PONG."
      }

      match /^help\s*(?<command>.*)/i, :help, help: {
        "help" => "Lists all commands with help",
        "help <command>" => "Lists help for <command>"
      }
      # rubocop:enable Lint/AmbiguousRegexpLiteral

      def pong(*)
        "PONG"
      end

      def help(msg, match_data = nil)
        type = msg.metadata[:type] ||= "text"
        if match_data[:command].nil? || match_data[:command].empty?
          @help = bot.help
        else
          @help = bot.help.find_all { |text| text.match match_data[:command] }
        end
        render(type: type)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cognition-2.0.7 lib/cognition/plugins/default.rb
cognition-2.0.6 lib/cognition/plugins/default.rb
cognition-2.0.5 lib/cognition/plugins/default.rb