Slide 1

Slide 1 text

HubotͰ IRC BotΛͭ͘Ζ͏ 2014 / 07 / 23 @mattak

Slide 2

Slide 2 text

AGENDA 1. Hubot ͱ͸ʁ 2. Hubot ͷ࡞Γํ 3. Hubot ͰεΫϦϓτΛॻ͘ 4. εΫϦϓτΛެ։͢Δ

Slide 3

Slide 3 text

Hubot?

Slide 4

Slide 4 text

Hubot? • Human + Robot = Hubot ? • Githubࣾ੡ͷChat bot ! • ݴޠ: Coffeescript • ؀ڥ: HipChat, IRC, Twitter, Gtalk, Skype, Linger,… • ύοέʔδ؅ཧ: npm

Slide 5

Slide 5 text

ಛ௃1: ͍ΖΜͳαʔϏεͰಈ͘

Slide 6

Slide 6 text

ಛ௃2: moduleԽͰ͖Δ Adapter tinyspec/hubot-slack nandub/hubot-irc miyagawa/hubot-lingr script hubot-ascii-faces hubot-cron hubot-yo

Slide 7

Slide 7 text

ಛ௃3: redisͰঢ়ଶ؅ཧ - BotΛ࠶ىಈͯ͠΋େৎ෉ / / data set robot.brain.data[“user”] = 0; ! / / data save robot.brain.save();

Slide 8

Slide 8 text

Ͳ͏΍ͬͯ࡞Δ?

Slide 9

Slide 9 text

install -> create -> launch $ npm install -g hubot coffee-script $ hubot —create myhubot $ cd myhubot $ bin/hubot —name myhubot myhubot> myhubot help …. default ͩͱShell্Ͱىಈ͠·͢ɻ

Slide 10

Slide 10 text

IRC΁ͷରԠ $ npm install hubot-irc —save && npm install $ HUBOT_IRC_SERVER=irc.example.com \ HUBOT_IRC_ROOMS=“#room1,#room2” \ HUBOT_IRC_NICK=“myhubot” \ HUBOT_IRC_UNFLOOD=“true” \ bin/hubot -a irc —name myhubot HUBOT_IRC_SEND_NOTICE_MODE = “true” noticeͰͷىಈ

Slide 11

Slide 11 text

hubotͷݺͼํ myhubot> myhubot help myhubot> @myhubot help myhubot> MYHUBOT help myhubot> myhubot: help

Slide 12

Slide 12 text

defaultͰ΋৭ʑͰ͖ΔΑ ը૾ Hubot> @Hubot image me ੢ॅ఼ youtube: Hubot> @Hubot youtube me ͪΐͬͱ͓࣌ؒΑΖ͍͠Ͱ͔͢ ݴޠม׵: Hubot> @Hubot translate me from japanese into english δϣδϣ Ξχϝʔγϣϯgif: Hubot> @Hubot animate me খ໺ࣉখ࡙

Slide 13

Slide 13 text

pluginͷΠϯετʔϧ $ npm install hubot-cron —save $ cat external-scripts.json [“hubot-cron”] npm install ͯ͠ɺexternal-scripts.jsonʹهड़͢Δ͚ͩ.

Slide 14

Slide 14 text

scriptΛॻ͘ʂ

Slide 15

Slide 15 text

scripts $ ls scripts auth.coffee google-images.coffee httpd.coffee ping.coffee roles.coffee storage.coffee youtube.coffee events.coffee help.coffee maps.coffee pugme.coffee rules.coffee translate.coffee ਅࣅ͠ͳ͕Βɺscripts/ ҎԼʹॻ͚͹OK.

Slide 16

Slide 16 text

scriptͷίϝϯτ https:/ /github.com/github/hubot-scripts#readme # Description # # # Dependencies: # "": "" # # Configuration: # LIST_OF_ENV_VARS_TO_SET # # Commands: # hubot - # - # # Notes: # # # Author: # ॻ͘ͱhelpʹग़Δʂ

Slide 17

Slide 17 text

scriptͷத਎ module.exports = (robot) -> robot.respond /PING$/i, (msg) -> msg.send "PONG" ! robot.respond /ADAPTER$/i, (msg) -> msg.send robot.adapterName ! robot.respond /ECHO (.*)$/i, (msg) -> msg.send msg.match[1] ! robot.respond /TIME$/i, (msg) -> msg.send "Server time is: #{new Date()}" ! robot.respond /DIE$/i, (msg) -> msg.send "Goodbye, cruel world." process.exit 0

Slide 18

Slide 18 text

tips1 msg.send “Guten morgen!” ൃݴ͢Δ msg.reply “ͳΜͰ΍ͶΜʂ” ฦ౴͢Δ Hubot> @Hubot tukkomi Hubot> Shell: “ͳΜͰ΍ͶΜʂ” Hubot> Guten morgen!

Slide 19

Slide 19 text

tips2 robot.hear /hear/i, (msg) -> msg.send “hear” Ԡ౴1 robot.respond /respond/i, (msg) -> msg.send “respond” Ԡ౴2 Hubot> @Hubot hear Hubot> hear Hubot> @Hubot respond Hubot> respond Hubot> respond Hubot> hear Hubot> hear (respond: @Hubot Ͱ࢝ΊΔίϚϯυܥ) (hear: ೚ҙԠ౴ܥ)

Slide 20

Slide 20 text

tips3 { "user": { "id": "1", "name": "Shell", "room": "Shell" }, "text": "@Hubot test", "id": "messageId", "done": false, "room": "Shell" } ൃݴ಺༰: msg.message bot໊: robot.name

Slide 21

Slide 21 text

moduleԽͯ͠ެ։͢Δ!

Slide 22

Slide 22 text

࣮ࡍʹͭͬͯ͘Έͨ • https:/ /github.com/mattak/hubot-hello-ninja • https:/ /www.npmjs.org/package/hubot-hello-ninja ࢀߟ: • https:/ /github.com/sakatam/hubot-yo • https:/ /github.com/miyagawa/hubot-cron

Slide 23

Slide 23 text

؆୯Ͱ͢ ొ࿥: $ npm adduser ެ։: $ npm publish ֬ೝ: $ npm info hubot-hello-ninja ಈ࡞֬ೝ: $ npm install /your/module/path

Slide 24

Slide 24 text

HubotΦεεϝʂ ͲΜͲΜmoduleԽ͠Α͏ʂ

Slide 25

Slide 25 text

࣌ؒ͋ΔͷͰDEMO https:/ /github.com/mattak/ninja-bot