Hubotの紹介
「DevOpsDay Tokyo 2013」でGitHub社のエンジニアが紹介していた「Hubot」について少し使ってみたので、紹介します。
#「DevOpsDay Tokyo 2013」については以下を参照。
「DevOpsDay Tokyo 2013」に行ってきました - なみひらブログ
Hubotってなに?
GitHub社が開発したbotフレームワークです。Hubotはチャットルームに駐在しており、開発者はそのHubotに作業を依頼して、Hubotが処理を行います。また、Hubotにcron的な定期実行の仕組みを導入することができます。GitHubのエンジニアはこのことを「ChatOps」と呼んでいました。
Hubotの処理の種類(AI力)は、JavaScriptやCoffeeScriptで拡張できます。
以下がHubotを紹介した分かりやすいパワポです。
以下がGitHub社の方のパワポです。
Hubotの動作例
Hubotの動作の例を挙げてみます。※自分が「おっ!すごい」と思った機能です。Hubotには、以下の機能がデフォルトで入っています。
Hubot map me <query> - Returns a map view of the area returned by `query`.「query」部分に地名を入れると、その地図を教えてくれます。
実際にIRCでHubotに訊いてみましょう。
00:00 (namihira) hubot map me shibuya 00:00 (hubot) http://maps.google.com/maps/api/staticmap?markers=shibuya&size=400x400&maptype=roadmap&sensor=false&format=png 00:00 (hubot) http://maps.google.com/maps?q=shibuya&hl=en&sll=37.0625,-95.677068&sspn=73.579623,100.371094&vpsrc=0&hnear=shibuya&t=m&z=11
Hubotが丁寧に画像付きで教えてくれます(*´Д`*)↓
View Larger Map
Hubotのデフォルトの機能一覧です。
00:00 (namihira) hubot help 00:00 (hubot) Events: 00:00 (hubot) debug - {user: <user object to send message to>} 00:00 (hubot) hubot <user> doesn't have <role> role - Removes a role from a user 00:00 (hubot) hubot <user> has <role> role - Assigns a role to a user 00:00 (hubot) hubot <user> is a badass guitarist - assign a role to a user 00:00 (hubot) hubot <user> is not a badass guitarist - remove a role from a user 00:00 (hubot) hubot animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead. 00:00 (hubot) hubot convert me <expression> to <units> - Convert expression to given units. 00:00 (hubot) hubot die - End hubot process 00:00 (hubot) hubot echo <text> - Reply back with <text> 00:00 (hubot) hubot fake event <event> - Triggers the <event> event for debugging reasons 00:00 (hubot) hubot help - Displays all of the help commands that hubot knows about. 00:00 (hubot) hubot help <query> - Displays all help commands that match <query>. 00:00 (hubot) hubot image me <query> - The Original. Queries Google Images for <query> and returns a random top result. 00:00 (hubot) hubot map me <query> - Returns a map view of the area returned by `query`. 00:00 (hubot) hubot math me <expression> - Calculate the given expression. 00:00 (hubot) hubot mustache me <query> - Searches Google Images for the specified query and mustaches it. 00:00 (hubot) hubot mustache me <url> - Adds a mustache to the specified URL. 00:00 (hubot) hubot ping - Reply with pong 00:00 (hubot) hubot pug bomb N - get N pugs 00:00 (hubot) hubot pug me - Receive a pug 00:00 (hubot) hubot show storage - Display the contents that are persisted in the brain 00:00 (hubot) hubot show users - Display all users that hubot knows about 00:00 (hubot) hubot the rules - Make sure hubot still knows the rules. 00:00 (hubot) hubot time - Reply with current time 00:00 (hubot) hubot translate me <phrase> - Searches for a translation for the <phrase> and then prints that bad boy out. 00:00 (hubot) hubot translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional 00:00 (hubot) hubot what role does <user> have - Find out what roles are assigned to a specific user 00:00 (hubot) hubot who has admin role - Find out who's an admin and can assign roles 00:00 (hubot) hubot who is <user> - see what roles a user has 00:00 (hubot) hubot youtube me <query> - Searches YouTube for the query and returns the video embed link.
Hubotを賢くしてみる(機能拡張)
上記のデフォルト機能だけでなく、スクリプトを追加すればどんどんHubotを賢くすることができます(機能拡張)。例えば、「Hubotにあいさつがしたい!(´・Д・`)」という場合、以下のスクリプトをフォルダに配置するだけです。(この例は、いつもの”Hello World”みたいなものです。)
- hello.coffee
# Description: # Greeting # # Commands: # hubot hello - Greeting. # Examples: # hubot hello module.exports = (robot) -> robot.respond /hello/, (msg) -> msg.send "Hello!"
ファイルを配置し、Hubotを再起動すると実行できるようになります。またhelpを見てみましょう。
00:00 (namihira) hubot help (中略) 00:00 (hubot) hubot hello - Greeting. (中略)
コマンドとして追加されています。では実行してみます。
00:00 (namihira) hubot hello 00:00 (hubot) Hello!
あいさつしてくれるようになった(*´Д`*)
こんな感じに簡単に機能拡張できます。
Hubotの使いどころ
Hubotは機能拡張できるので、いろいろなことに利用できます。以下に例を挙げてみます。(GitHub社での利用例も含む)- Hubotに他の開発者の今何しているかを訊く。※いちいちスケジューラ開きたくない\(^o^)/
- Hubotにおひる時間/メニューを訊く。※意外と気になる\(^o^)/
- Hubotにあの人は誰か訊く。ユーザの本当の名前を訊く。※ログイン名がニックネームだと誰か分からない\(^o^)/
- Hubotにデプロイをお願いする(環境の番人)。※みんな勝手にデプロイ環境いじらないで\(^o^)/
などなど。