repost/plugins/commands/at.rb
2015-04-14 17:01:06 +02:00

23 lines
753 B
Ruby

require 'json'
require 'time'
Client.register_command("at") { |args|
now = []
recently = []
r_msg = ""
h = JSON.parse(Net::HTTP.get(URI(Config[:commands][:at][:url])))
h["users"].each { |u|
if (Time.now.to_i - u["timestamp"]) > 600 then
recently << u["login"]
else
now << u["login"]
end
}
r_msg += "now: #{now.join(' ')}#{Config[:commands][:at][:separator]} " if not now.empty?
r_msg += "recently: #{recently.join(' ')}#{Config[:commands][:at][:separator]} " if not recently.empty?
r_msg += Config[:commands][:at][:empty] if now.empty? and recently.empty?
r_msg += "unknown: #{h["unknown"]}#{Config[:commands][:at][:separator]} " if h["unknown"] > 0
r_msg
}