gpt4 book ai didi

hubot - Hubot如何在没有任何命令的情况下定期运行功能?

转载 作者:行者123 更新时间:2023-12-04 23:21:24 26 4
gpt4 key购买 nike

我正在尝试为hubot制作一个功能,每5分钟向一个房间发送一条消息,无需任何命令,仅由他自己。

module.exports = (robot, scripts) ->
setTimeout () ->
setInterval () ->
msg.send "foo"
, 5 * 60 * 1000
, 5 * 60 * 1000

我需要改变什么?

最佳答案

使用节点-cron。

$ npm install --save cron time

您的脚本应如下所示:
# Description:
# Defines periodic executions

module.exports = (robot) ->
cronJob = require('cron').CronJob
tz = 'America/Los_Angeles'
new cronJob('0 0 9 * * 1-5', workdaysNineAm, null, true, tz)
new cronJob('0 */5 * * * *', everyFiveMinutes, null, true, tz)

room = 12345678

workdaysNineAm = ->
robot.emit 'slave:command', 'wake everyone up', room

everyFiveMinutes = ->
robot.messageRoom room, 'I will nag you every 5 minutes'

更多细节: https://leanpub.com/automation-and-monitoring-with-hubot/read#leanpub-auto-periodic-task-execution

关于hubot - Hubot如何在没有任何命令的情况下定期运行功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25210281/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com