Skip to content

Commit

Permalink
Merge pull request #7 from g0tiu5a/fix-ctftime
Browse files Browse the repository at this point in the history
Hide offline event at `ctftime events`
  • Loading branch information
ryosan-470 committed Apr 5, 2016
2 parents b599db0 + ccf61e4 commit 4efc422
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions scripts/ctftime.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ module.exports = (robot) ->
robot.hear /ctftime event/, (msg) ->
limit = 3
start = new Date().getTime()
finish = start + 604800000 # 7 days later

start = Math.floor(start / 1000)
finish = Math.floor(finish / 1000)
url = CTFTIME_API_URL + "/events/?limit=#{limit}&start=#{start}&finish=#{finish}"
# 最大直近3つのイベントを表示する
url = CTFTIME_API_URL + "/events/?limit=#{limit}&start=#{start}"
http = msg.http url
http.get() (err, res, body) ->
if res.statusCode is 404
Expand All @@ -25,40 +24,41 @@ module.exports = (robot) ->
else
events = JSON.parse body
for event in events
robot.emit 'slack.attachment',
message: msg.message
content: [
{
fallback: "#{event.title} - #{event.url}"
title: event.title
title_link: event.url

fields: [
{
title: "format"
value: event.format
short: true
},
{
title: "weight"
value: event.weight
short: true
},
{
title: "start"
value: moment(event.start).format("YYYY/MM/DD HH:mm:ssZ")
short: true
},
{
title: "finish"
value: moment(event.finish).format("YYYY/MM/DD HH:mm:ssZ")
short: true
}
]
# Hide offline event
if event.location == ""
robot.emit 'slack.attachment',
message: msg.message
content: [
{
fallback: "#{event.title} - #{event.url}"
title: event.title
title_link: event.url

color: "#F35A00"
}
]
fields: [
{
title: "format"
value: event.format
short: true
},
{
title: "weight"
value: event.weight
short: true
},
{
title: "start"
value: moment(event.start).format("YYYY/MM/DD HH:mm:ssZ")
short: true
},
{
title: "finish"
value: moment(event.finish).format("YYYY/MM/DD HH:mm:ssZ")
short: true
}
]
color: "#F35A00"
}
]

robot.hear /ctftime ours/, (msg) ->
OUR_TEAM_ID = 16931 # Team g0tiu5a ID
Expand Down

0 comments on commit 4efc422

Please sign in to comment.