Sha256: 712b588dfc0be793cebe14c4110508fe69a8b3da25875a34b81babbc5380b78c

Contents?: true

Size: 850 Bytes

Versions: 7

Compression:

Stored size: 850 Bytes

Contents

# frozen_string_literal: true

module SlackRubyBot
  module Hooks
    class Hello
      attr_accessor :logger, :connected_at

      def initialize(logger)
        self.logger = logger
      end

      def call(client, _data)
        return unless client&.team

        new_connected_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
        log = [
          'Successfully',
          connected_at ? 'reconnected' : 'connected',
          "team #{client.team.name} (#{client.team.id}) to https://#{client.team.domain}.slack.com",
          connected_at ? "after #{last_connection_till(new_connected_at)}s" : nil
        ].compact.join(' ') + '.'

        logger.info log

        self.connected_at = new_connected_at
      end

      private

      def last_connection_till(time)
        (time - connected_at).round(2)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
slackrb-0.17.1 lib/slack-ruby-bot/hooks/hello.rb
slackrb-0.17.0 lib/slack-ruby-bot/hooks/hello.rb
slack-ruby-bot-0.16.1 lib/slack-ruby-bot/hooks/hello.rb
slack-ruby-bot-0.16.0 lib/slack-ruby-bot/hooks/hello.rb
slack-ruby-bot-0.15.0 lib/slack-ruby-bot/hooks/hello.rb
slack-ruby-bot-0.14.0 lib/slack-ruby-bot/hooks/hello.rb
slack-ruby-bot-0.13.0 lib/slack-ruby-bot/hooks/hello.rb