@moqada/hubot-schedule-helper
v1.0.0
Published
Helper of Hubot Scripts for implementing schedule tasks
Downloads
2
Readme
hubot-schedule-helper
Helper of Hubot Scripts for implementing schedule tasks.
You can implement scheduled tasks to your hubot scripts easily. And, scheduled tasks are stored to "Hubot brain".
Installation
npm install --save @moqada/hubot-schedule-helper
Usage
See example scripts. More detail, see API Document.
{Scheduler, Job} = require '@moqada/hubot-schedule-helper'
# You must define your Job class extending Job
class AwesomeJob extends Job
# You must implement exec method
exec: (robot) ->
envelope = @getEnvelope()
{message} = @meta
robot.send envelope, message
module.exports = (robot) ->
scheduler = new Scheduler({robot, job: AwesomeJob})
# Add scheduled job (send 'hello! hello!' at every 6 o'clock)
robot.respond /add/i, (res) ->
{user} = res.message
meta = {message: 'hello! hello!'}
pattern = '* 6 * * *' # every 6 o'clock
job = scheduler.createJob({pattern, user, meta})
# Cancel target job
robot.respond /cancel (\d+)$/i, (res) ->
[id] = res.match.slice(1)
scheduler.cancelJob(id)
# List job
robot.respond /list$/i, (res) ->
msgs = []
for job of scheduler.jobs
msgs.push "#{job.id}: \"#{job.pattern}\" #{job.getRoom()} #{job.meta.message}"
res.send msgs.join('\n')
# Update target job
robot.respond /update (\d+) (.+)$/i, (res) ->
[id, message] = res.match.slice(1)
meta = {message}
scheduler.updateJob(id, meta)
Related
This module's code is greatly inspired by hubot-schdule.