项目作者: matsukaz

项目描述 :
A hubot script to schedule a message in both cron-style and datetime-based format pattern
高级语言: CoffeeScript
项目地址: git://github.com/matsukaz/hubot-schedule.git
创建时间: 2015-01-15T06:41:44Z
项目社区:https://github.com/matsukaz/hubot-schedule

开源协议:MIT License

下载


hubot-schedule

README_ja.md

NPM version

NPM

hubot-schedule is a message scheduler runs on hubot.

It allows you to schedule a message in both cron-style and datetime-based format pattern.
It is for time-based scheduling, not interval-based scheduling.

Since hubot-schedule uses node-schedule to manage schedule, some of the cron features are not supported.
Please see node-schedule for more details.

This script is greatly inspired by hubot-cron.
At first, I wanted a datetime-based scheduler.
As I start developing this, I noticed that node-schedule also suppports cron-style scheduling, so I changed my mind to develop a scheduler that supports both cron-style and datetime-based format.

Note

for Slack users

If you are using slack adapter such as hubot-slack, please use v4.2.2 or later.
v4.2.1 sometimes fails to add new schedule.

Installation

Add hubot-schedule to your package.json.

  1. "dependencies": {
  2. "hubot-schedule": "~0.7.0"
  3. }

Run npm install.

  1. $ npm install

Add hubot-schedule to external-scripts.json.

  1. > cat external-scripts.json
  2. > ["hubot-schedule"]

Usage

  1. Hubot> hubot help schedule
  2. Hubot schedule [add|new] "<cron pattern>(,<utc offset>)" <message> - Schedule a message that runs recurrently
  3. Hubot schedule [add|new] "<datetime pattern>" <message> - Schedule a message that runs on a specific date and time
  4. Hubot schedule [add|new] #<room> "<cron pattern>(,<utc offset>)" <message> - Schedule a message to a specific room that runs recurrently
  5. Hubot schedule [add|new] #<room> "<datetime pattern>" <message> - Schedule a message to a specific room that runs on a specific date and time
  6. Hubot schedule [cancel|del|delete|remove] <id> - Cancel the schedule
  7. Hubot schedule [upd|update] <id> <message> - Update scheduled message
  8. Hubot schedule env - Show hubot schedule environments
  9. Hubot schedule list #<room> - List all scheduled messages for specified room
  10. Hubot schedule list - List all scheduled messages for current room
  11. Hubot schedule list all - List all scheduled messages for any rooms
  12. Hubot> hubot schedule add "2015-01-16 10:00" Let's release this script!
  13. 6738: Schedule created
  14. Hubot> hubot schedule add "0 10 * * 1-5" Don't forget to brew coffee :)
  15. 9735: Schedule created
  16. Hubot> hubot schedule list
  17. 6738: [ 2015-01-16 10:00:00 +09:00 ] #Shell Let's release this script!
  18. 9735: [ 0 10 * * 1-5 ] #Shell Don't forget to brew coffee :)
  19. Hubot> hubot schedule update 6738 Let's release this module and share with everyone!
  20. 6738: Scheduled message updated
  21. Hubot> hubot schedule list
  22. 6738: [ 2015-01-16 10:00:00 +09:00 ] #Shell Let's release this script and share with everyone!
  23. 9735: [ 0 10 * * 1-5 ] #Shell Don't forget to brew coffee :)
  24. Let's release this script and share with everyone!
  25. (Hubot posts the message at 2015-01-16 10:00:00 and schedule will be removed automatically)
  26. Hubot> hubot schedule del 9735
  27. 9735: Schedule canceled
  28. Hubot> hubot schedule list
  29. Message is not scheduled
  30. Hubot> hubot schedule add "0 10 * * 1-5" hubot image me coffee
  31. 9735: Schedule created
  32. (hubot can process messages sent by hubot-schedule, so you can ask hubot to do something at the scheduled time, like post an image of coffee.)

If you need to persist scheduled messages, use hubot-brain persistent module like hubot-redis-brain.

How to use UTC Offset

If OS timezone is set to Asia/Tokyo(UTC Offset would be “+09:00”)

  1. Hubot> hubot schedule env
  2. DEBUG = false
  3. DONT_RECEIVE = false
  4. DENY_EXTERNAL_CONTROL = false
  5. LIST_REPLACE_TEXT = {"@":"[@]"}
  6. DEFAULT_UTC_OFFSET_FOR_CRON = "+09:00"
  7. Hubot> hubot schedule add "2019-08-05 10:00 +02:00" use UTC Offset for datetime-based format pattern
  8. 2914: Schedule created
  9. Hubot> hubot schedule add "0 10 * * 1-5, +02:00" use UTC Offset for cron-style format pattern
  10. 4291: Schedule created
  11. Hubot> hubot schedule list
  12. 2914: [ 2019-08-05 17:00:00 +09:00 ] #Shell use UTC Offset for datetime-based format pattern (listed schedules are shown using OS timezone)
  13. 4291: [ 0 10 * * 1-5, +02:00 ] #Shell use UTC Offset for cron-style format pattern

Configuration

HUBOT_SCHEDULE_DEBUG

Setting environment variable HUBOT_SCHEDULE_DEBUG=1 will show some debug messages.

HUBOT_SCHEDULE_DENY_EXTERNAL_CONTROL

Setting environment variable HUBOT_SCHEDULE_DENY_EXTERNAL_CONTROL=1 will deny schedule control from other rooms.

HUBOT_SCHEDULE_DONT_RECEIVE

Setting environment variable HUBOT_SCHEDULE_DONT_RECEIVE=1 will disable hubot not to process messages sent by hubot-schedule.

HUBOT_SCHEDULE_LIST_REPLACE_TEXT

Setting environment variable HUBOT_SCHEDULE_LIST_REPLACE_TEXT='<stringified json>' will configure the text replacement used when listing scheduled messages.
Default configuration is '{"@":"[@]"}'.

HUBOT_SCHEDULE_UTC_OFFSET_FOR_CRON

Setting environment variable HUBOT_SCHEDULE_UTC_OFFSET_FOR_CRON='<string format UTC Offset(e.g. "+09:00")>' will set default UTC Offset for cron-style format pattern.
If not set, OS timezone’s offset would be used.

Copyright 2015 Masakazu Matsushita.

Licensed under the MIT License.