LoginSignup
217

More than 5 years have passed since last update.

Hubotとはなにか?

Hubotは、文字列のコマンドを受け付け、指定されたコマンドに応じた処理を実行し、結果を表示する機能を提供するプログラムです。
この動作はシェルと同様なので、Hubotをシェルとみなすこともできます。
Hubotに対してコマンドを入力するのは、コンソールから、またはアダプタが提供されたチャットから行うことができます。単にHubotの動作を試したいだけならば、コンソールから試せます。

この記事では、Hubotをインストールし、コンソールから使ってみる手順を説明します。

Hubotのインストール

node.js, redisが必要です。これらがインストールされてない場合は、まずインストールしてください。

OSXであれば、Homebrewを利用してインストールできます。

brew install node redis

あらかじめredisを起動しておきましょう。

redis-server &

Hubotのインストールは基本、公式サイトに書かれてるように、npmを使ってインストールします。

npm install -g hubot coffee-script

Hubotをインストールすると、hubotコマンドが提供されます。hubotコマンドを使って、独自のHubot環境を構築できます。

hubot --create myhubot

このコマンドは、myhubotというディレクトリを作り、その中にHubot環境を作ります。

これでHubotを使う準備ができました。以下のコマンドを入力して、Hubotを起動してください。Hubotプロンプトが表示されます。

cd myhubot
bin/hubot
Hubot>

組み込みのスクリプトを実行してみる

Hubotへのコマンドの入力は、多くの場合、先頭に hubot と入力することで行います。hubot help<Enter>と入力してみましょう。

Hubot> hubot help
Hubot> Events:
debug - {user: <user object to send message to>}
Hubot <user> doesn't have <role> role - Removes a role from a user
Hubot <user> has <role> role - Assigns a role to a user
Hubot <user> is a badass guitarist - assign a role to a user
Hubot <user> is not a badass guitarist - remove a role from a user
Hubot animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
Hubot convert me <expression> to <units> - Convert expression to given units.
Hubot die - End Hubot process
Hubot echo <text> - Reply back with <text>
Hubot fake event <event> - Triggers the <event> event for debugging reasons
Hubot help - Displays all of the help commands that Hubot knows about.
Hubot help <query> - Displays all help commands that match <query>.
Hubot image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
Hubot map me <query> - Returns a map view of the area returned by `query`.
Hubot math me <expression> - Calculate the given expression.
Hubot mustache me <query> - Searches Google Images for the specified query and mustaches it.
Hubot mustache me <url> - Adds a mustache to the specified URL.
Hubot ping - Reply with pong
Hubot pug bomb N - get N pugs
Hubot pug me - Receive a pug
Hubot show storage - Display the contents that are persisted in the brain
Hubot show users - Display all users that Hubot knows about
Hubot the rules - Make sure Hubot still knows the rules.
Hubot time - Reply with current time
Hubot translate me <phrase> - Searches for a translation for the <phrase> and then prints that bad boy out.
Hubot translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional
Hubot what role does <user> have - Find out what roles are assigned to a specific user
Hubot who has admin role - Find out who's an admin and can assign roles
Hubot who is <user> - see what roles a user has
Hubot youtube me <query> - Searches YouTube for the query and returns the video embed link.
ship it - Display a motivation squirrel

コマンドリファレンスが表示されました。Hubotのコマンドの実体は、scripts ディレクトリにあるCoffeeScriptファイルです。scriptsディレクトリにファイルを追加することで、コマンドを追加することができます。以下では、今の時点で実行できるコマンドをいくつか実行してみます。

Hubot> hubot animate me partyhard
Hubot> http://images3.wikia.nocookie.net/__cb20070824174846/uncyclopedia/images/5/58/PARTYHARD4.gif#.png

インターネットからアニメーションgifを検索し、URLを表示します。

Hubot> hubot mustach me obama
Hubot> http://mustachify.me/2?src=http://www.tothetick.com/wp-content/uploads/2013/08/Obama4.jpg#.png

ひげをはやします。

Hubot> hubot ping
Hubot> PONG

ピンポンができます。

Hubot> hubot pug bomb
Hubot> http://24.media.tumblr.com/tumblr_maxm4ecVNq1qjmqavo1_500.jpg
Hubot> http://29.media.tumblr.com/tumblr_lsvczkC8e01qzgqodo1_500.jpg
Hubot> http://24.media.tumblr.com/tumblr_lhowz2fAnC1qaa50yo1_500.jpg
Hubot> http://28.media.tumblr.com/tumblr_ltyzizUm3t1qb08qmo1_500.png
Hubot> http://29.media.tumblr.com/tumblr_lsu0igEEtP1qiys5ao1_500.png

かわいいパグの画像を多数表示します。

Hubot> hubot the rules
Hubot> 1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.
2. A robot must obey any orders given to it by human beings, except where such orders would conflict with the First Law.
3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.

ロボット三原則を教えてくれます。

Hubot> hubot time
Hubot> Server time is: Tue Dec 03 2013 02:50:16 GMT+0900 (JST)

現在時刻を教えてくれます。

Hubot> ship it
Hubot> http://d2f8dzk2mhcqts.cloudfront.net/0772_PEW_Roundup/09_Squirrel.jpg

かわいいリスの画像を表示します。

Hubot> hubot die
Hubot> Goodbye, cruel world.

プログラムを終了します。

以上です。Hubotは簡単に使えることがわかりましたね。ぜひインストールしてみてください。

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
217