LoginSignup
5
6

More than 5 years have passed since last update.

Hubot cron定期実行、外部プログラム呼び出し

Posted at

Hubotスクリプトのメモ。

cronで定期実行

cron.coffee
cronJob  = require('cron').CronJob

module.exports = (robot) ->
    new cronJob
        cronTime: "0 0 * * * 1-5" # 月〜金の毎時00分に実行
        onTick: -> robot.send {room: "general"}, '(; ・`ω・´)'
        start: true
        timeZone: "Asia/Tokyo"

node-cron 使う。
https://github.com/ncb000gt/node-cron

$ npm install cron time

外部プログラム呼び出し

bot宛に送信されたテキストを外部プログラムに投げて出力テキストをしゃべらせる

ext_command.coffee
child_process = require 'child_process'

module.exports = (robot) ->
    robot.respond /(.+?)$/, (msg) ->
        child_process.exec "./my_program #{msg.match[1]}", (error, stdout, stderr) ->
      if !error
        output = stdout+''
        msg.send output
      else
        msg.send "error"
5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6