【发布时间】:2012-06-27 03:22:49
【问题描述】:
我正在考虑制作一个基于 Hubot 时钟的通知器(想想“现在是 5 点,该回家了!”但不那么烦人并且出于不同的原因)。在 Hubot 脚本中执行此类操作的最佳方法是什么?
[edit] 下面是一个使用 node-cron 的示例:
TIMEZONE = "America/New_York"
QUITTING_TIME = '0 0 17 * * 2-6' # M-F 5pm
ROOM = "Dev"
cronJob = require('cron').CronJob
module.exports = (robot) ->
gohome = new cronJob QUITTING_TIME,
->
robot.messageRoom ROOM, "It's 5! Go home!"
null
true
TIMEZONE
依赖:
"cron": "0.3.3",
"time": "0.8.2"
【问题讨论】:
-
这个代码是否让 cronJob 在 Hubot 启动时自动运行?
-
@Hlung 是的,当脚本被加载时。
-
我遇到了一些奇怪的问题,即 messageRoom 无法在 cron 作业回调中工作。我最终使用了 robots.send。
标签: node.js coffeescript hubot