Skip to content

Commit

Permalink
Fix #9 (remove sort function)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryosan-470 committed Oct 12, 2016
1 parent 7dfee27 commit c302e96
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions scripts/ctftime.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
CTFTIME_API_URL = "https://ctftime.org/api/v1"
moment = require "moment"

# sleep function from https://jsfiddle.net/axjw668v/8/
sleep = (delay) ->
start = new Date().getTime()
while new Date().getTime() < start + delay
true

module.exports = (robot) ->
robot.hear /ctftime event/, (msg) ->
limit = 3
Expand All @@ -23,13 +29,10 @@ module.exports = (robot) ->
msg.send "Nothing event"
else
events = JSON.parse body
# sort key is event.start
sortEvents = (a, b) ->
a.start > b.start
events.sort sortEvents
for event in events
# Hide offline event
if event.location == ""
sleep(500) # 0.5
robot.emit 'slack.attachment',
message: msg.message
content: [
Expand Down

0 comments on commit c302e96

Please sign in to comment.