Class: UpTime

Inherits:
Rubot::Core::Command show all
Defined in:
lib/template/commands/up_time.rb

Instance Method Summary collapse

Methods inherited from Rubot::Core::Command

#initialize, #protected?, #run

Constructor Details

This class inherits a constructor from Rubot::Core::Command

Instance Method Details

#execute(server, message, options) ⇒ Object



4
5
6
# File 'lib/template/commands/up_time.rb', line 4

def execute(server, message, options)
  server.msg(message.destination, seconds_to_words(Time.now - server.connected_at))
end

#seconds_to_words(seconds) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/template/commands/up_time.rb', line 8

def seconds_to_words(seconds)
  time = "#{(seconds % 60).to_i} seconds"
  
  minutes = seconds / 60
  
  if minutes >= 1
    hours = minutes / 60
    time.insert(0, "#{(minutes % 60).to_i} minutes ")
    
    if hours >= 1
      days = hours / 24
      time.insert(0, "#{(hours % 24).to_i} hours ")
      
      if days >= 1
        time.insert(0, "#{days.to_i} days ")
      end
    end
  end
  
  time
end