1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Hubotに予測できないタイミングで発言して貰う

Posted at

予期せず人間との連携プレーを果たしたりしてとてもよいです。

実装方法

cronとtimeを入れてね。
npm install cron time --save

要は1分毎にガチャ引いて、当たったら発言するというだけです。

scripts/cron.coffee
cronJob = require('cron').CronJob
random = require('hubot').Response::random

module.exports = (robot) ->
  randomTalk = new cronJob
    cronTime: '0 * 0-2,10-23 * * *' # ここでBOTが起きてる時間を調整
    timeZone: "Asia/Tokyo"
    onTick: () =>
      envelope = room: "#channel_name" # チャンネル名
      sayArr = [ # 発言リスト
        'ほげほげ'
        'ふがふが'
      ]
      if Math.random() < 0.005 # ここの数字を調整して、発言頻度を変える
        say = random sayArr
        robot.send envelope, say
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?