module Lita
  module Handlers
    class Netping < Handler
      route(
        /^ping\s(?<target>.+)/,
        :ping,
        command: true,
        help: {
          t('help.ping.syntax') => t('help.ping.desc')
        }
      )

      def ping(response)
        target = response.match_data['target']

        response.reply(format(target, ping_target(target)))
      end

      private

      def format(host, result)
        if result
          t('ping.success', host: host)
        else
          t('ping.fail', host: host)
        end
      end

      def ping_target(host)
        Net::Ping::External.new(host).ping
      end
    end

    Lita.register_handler(Netping)
  end
end

module Lita
  module Handlers
    class Netping < Handler
      route(
        /^ping\s(?<target>.+)/,
        :ping,
        command: true,
        help: {
          t('help.ping.syntax') => t('help.ping.desc')
        }
      )

      def ping(response)
        target = response.match_data['target']

        response.reply(format(target, ping_target(target)))
      end

      private

      def format(host, result)
        if result
          t('ping.success', host: host)
        else
          t('ping.fail', host: host)
        end
      end

      def ping_target(host)
        p = Net::Ping::External.new(host)
        p.ping(host, 1, 1, 1)
      end
    end

    Lita.register_handler(Netping)
  end
end

Add a shorter timeout, this should be user-accessible at some point.
Add a shorter timeout, this should be user-accessible at some point.
