LoginSignup
2
2

More than 5 years have passed since last update.

Hubotくんに最近追加したネタほど多く発言してもらう

Last updated at Posted at 2016-03-15

Why

最近追加したネタほど内輪ウケが良いから。

How

重み付けには random-weighted-choice を使います。weight: Math.pow(1.1, i) + 1の部分でそれぞれの発言に適当に重みを付けています。追加した発言の数や目的によっていい感じにしてください。

npm install random-weighted-choice --save
scripts/example.coffee
  robot.hear /hi/i, (res) ->
    sayArr = [
      'あーいまいっさんせっ'
      (...発言たくさん..)
      '卒業'
    ]
    rwc = require('random-weighted-choice')
    weightedSayArr = sayArr.map (v, i) ->
      return { weight: Math.pow(1.1, i) + 1, id: v }
    res.reply rwc(weightedSayArr)
myhubot> myhubot: hi
myhubot> Shell: 卒業
2
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
2
2