API タタいて云々というあたり、へろへろながらも動くようになった模様。
体調崩してるから、なのかどうかは不明ですが
- 変数参照を
$
でヤッてたりとか
してて超微妙。あと、連続起動の残り時間が 57m remaining
になってますが、ここから減らなくなってるみたいなので上手くヤれてるのかどうか。
定時に天気予報を
流すナニの実装を例示しておきます。weather-ja をパクッてます。
cron = require('cron').CronJob
dateFormat = require('dateformat')
module.exports = (robot) ->
# *(sec) *(min) *(hour) *(day) *(month) *(day of the week)
new cron
cronTime: '0 30 6 * * *'
onTick: ->
robot.http('http://weather.livedoor.com/forecast/webservice/json/v1')
.query(city: "471010")
.header('Accept', 'application/json')
.get() (err, res, body) ->
if err
msg.send('天気の取得に失敗しました')
return
result = JSON.parse(body)
forecastTime = new Date(result.publicTime)
robot.send {room: "#general"}, "【お天気情報 那覇】\n" +
"■ #{dateFormat(forecastTime, "yyyy年mm月dd日HH時MM分")}の予報です\n" +
"予報 : #{result.forecasts[0].telop}\n" +
"#{result.description.text}\n" +
"詳しい情報は下記を参照\n\n" +
"#{result.link}"
start: true
timeZone: "Asia/Tokyo"