wechaty / plugin-contrib

Wechaty Plugin Ecosystem Contrib Package
https://paka.dev/npm/wechaty-plugin-contrib
Apache License 2.0
33 stars 12 forks source link

NewPlugin: Crontab #22

Open huan opened 4 years ago

huan commented 4 years ago

Like the following code from our Friday BOT demonstrated: (original author: @qhduan )

import cron from 'node-cron'

interface CRONConfig {
  time: string,
  reply: string
}

const CRON_CONFIG: CRONConfig[] = [
  {
    reply: '星期一了,如果主席还没发活动总结的话要注意了',
    /**
     * 定时任务
     *     ┌─────────────── second (optional)
     *     │ ┌───────────── minute
     *     │ │ ┌─────────── hour
     *     │ │ │  ┌──────── day of month
     *     │ │ │  │ ┌────── month
     *     │ │ │  │ │ ┌──── day of week
     *     │ │ │  │ │ │
     *     │ │ │  │ │ │
     *     * * *  * * *      // */
    time: '0 0 19 * * 1',
  },
]

/**
 * TODO: Huan(202006)
 */
export async function crontab () {
  for (const cronConfig of CRON_CONFIG) {
    cron.schedule(cronConfig.time, async () => {
      // await Chatops.instance().say(cronConfig.reply)
    })
  }
}

See: