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"