12
13

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-scriptsAdvent Calendar 2013

Day 3

Hubot-scriptsのmsg.randomを学ぶ

Last updated at Posted at 2013-12-03

チャット相手が毎回同じ応答を返してくるとすぐ飽きますよね。

私:「おはよう」
hubot:「やっほー」
私:「おはよう」
hubot:「やっほー」
私:「おはよう」
hubot:「やっほー」
    :

こんな感じではやる気がなくなってきます。今回はランダムに応答を返すという方法を試してみましょう。

シンプルなランダムに応答を返すスクリプト

こんにちはに対して、ランダムに答えるscriptを紹介します。

randommes.coffee
module.exports = (robot) ->
  robot.hear /こんにちは/, (msg) ->
    msg.send msg.random ["ちわー", "こんにちはっ", "ちゃーす", "こ、こんにちは"]

ポイントは msg.send の後の、msg.randomです。msg.randomに配列を渡すと、その中からランダムに応答を返してくれます。

結構簡単ですよね。

12
13
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
12
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?