LoginSignup
5
4

More than 5 years have passed since last update.

Hubot | core scripts から学ぶ Hubot で出来ること

Posted at

Hubot | core scripts から学ぶ Hubot で出来ること

概要

core scripts から、Hubot で出来ることを学びます

Hubot インストール時に付属している、 core scripts から
Hubot でどんなことが出来るのかを学びます。

core scripts
https://github.com/github/hubot/tree/master/src/scripts

※これらはあくまで典型例であり、Hubotでできることの範囲はとても広大だと思います

テキストに反応してテキストを返却する

最もオーソドックスな用途。
core scripts の例は以下。

script 処理内容 ソースコード
ping PONGを返却 ping.coffee
the rules ロボットの3原則を返却 rules.coffee

画像, 動画, アニメーションGIFのURLを返却する

core scripts の例は以下。

script 処理内容 ソースコード
pug me http://pugme.herokuapp.com から取得したパグ画像のURLを返却 pugme.coffee
pug bomb N http://pugme.herokuapp.com パグ画像のURLをN件返却 pugme.coffee
animate me <query> queryの条件に応じたアニメーションGIFを返却する google-images.coffee
youtube me <query> queryの条件に応じた youtube の動画URLを返却する youtube.coffee

など。

robot.brain の記憶機能を利用する

単発のメッセージではなく、何かしらデータを保持する機能は robot.brain を利用する。

core scripts の例は以下。

script 処理内容 ソースコード
<user> is a <role> ユーザーに role を割り当てる。設定した値は robot brain に保存される roles.coffee
<user> is not <role> ユーザーに role を解除する。設定した値は robot brain から削除される roles.coffee
who is <user> 指定ユーザーに割り当てられている role を全て表示する roles.coffee

Hubotサーバーを操作、情報を取得

Hubotサーバーに対して何かしらの操作をしたり、サーバーの情報を取得する。

script 処理内容 ソースコード
die Hubot 自身プロセスを終了する ping.coffee
time サーバー時間を返却する ping.coffee

外部サービスの機能を利用する

上述の画像や動画の取得も内部的にはこの形式を利用している。

script 処理内容 ソースコード
image me <query> queryの条件に応じた画像を google API で取得し、URLを返却する google-images.coffee
animate me <query> queryの条件に応じたアニメーション画像を google API で取得し、URLを返却する google-images.coffee
map me <query> queryの条件に応じたアニメーション画像を google API で取得し、URLを返却する maps.coffee
mustache me <query> queryの条件に応じた髭の画像を http://mustachify.me/ から取得し、URLを返却する google-images.coffee

Hubotに関する情報を取得する

Hubotサーバーに対して何かしらの操作をしたり、サーバーの情報を取得する。

script 処理内容 ソースコード
show storage hubot.brainの内容 storage.coffee
show users Hubotが把握しているユーザーの一覧 storage.coffee

など。

参照

core scripts GitHub
https://github.com/github/hubot/tree/master/src/scripts

5
4
1

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
5
4