-
-
Notifications
You must be signed in to change notification settings - Fork 187
/
hello.rb
35 lines (27 loc) · 850 Bytes
/
hello.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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