Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Added SpaceAPI support for Hubot. #1176

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/scripts/spaceapi.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Description:
# Get the open/close status of the configured hackerspace.
#
# Dependencies:
# None
#
# Configuration:
# HUBOT_SPACEAPI_URL
#
# Commands:
# hubot status - Displays the hackerspace status
#
# Author:
# apfohl

module.exports = (robot) ->
robot.respond /status/i, (msg) ->
msg.http(process.env.HUBOT_SPACEAPI_URL)
.get() (err, res, body) ->
if err
msg.send "Encountered an error :( #{err}"
return
data = JSON.parse(body)
status = data.space

if data.api == "0.13"

if data.state && data.state.open
status += ' is open'
else
status += ' is closed'

if data.state && data.state.lastchange
status += ' since ' + (new Date(data.state.lastchange * 1000))

else

if data.open
status += ' is open'
else
status += ' is closed'

if data.lastchange
status += ' since ' + (new Date(data.lastchange * 1000))

msg.send status