Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HubotでIRC botをつくろう

mattak
July 23, 2014

HubotでIRC botをつくろう

Hubot勉強会 2014/07/23

mattak

July 23, 2014
Tweet

More Decks by mattak

Other Decks in Programming

Transcript

  1. Hubot? • Human + Robot = Hubot ? • Githubࣾ੡ͷChat

    bot ! • ݴޠ: Coffeescript • ؀ڥ: HipChat, IRC, Twitter, Gtalk, Skype, Linger,… • ύοέʔδ؅ཧ: npm
  2. install -> create -> launch $ npm install -g hubot

    coffee-script $ hubot —create myhubot $ cd myhubot $ bin/hubot —name myhubot myhubot> myhubot help …. default ͩͱShell্Ͱىಈ͠·͢ɻ
  3. 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Ͱͷىಈ
  4. defaultͰ΋৭ʑͰ͖ΔΑ ը૾ Hubot> @Hubot image me ੢ॅ఼ youtube: Hubot> @Hubot

    youtube me ͪΐͬͱ͓࣌ؒΑΖ͍͠Ͱ͔͢ ݴޠม׵: Hubot> @Hubot translate me from japanese into english δϣδϣ Ξχϝʔγϣϯgif: Hubot> @Hubot animate me খ໺ࣉখ࡙
  5. 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.
  6. scriptͷίϝϯτ https:/ /github.com/github/hubot-scripts#readme # Description # <description of the scripts

    functionality> # # Dependencies: # "<module name>": "<module version>" # # Configuration: # LIST_OF_ENV_VARS_TO_SET # # Commands: # hubot <trigger> - <what the respond trigger does> # <trigger> - <what the hear trigger does> # # Notes: # <optional notes required for the script> # # Author: # <github username of the original script author> ॻ͘ͱhelpʹग़Δʂ
  7. 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
  8. 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: ೚ҙԠ౴ܥ)
  9. tips3 { "user": { "id": "1", "name": "Shell", "room": "Shell"

    }, "text": "@Hubot test", "id": "messageId", "done": false, "room": "Shell" } ൃݴ಺༰: msg.message bot໊: robot.name
  10. ؆୯Ͱ͢ ొ࿥: $ npm adduser ެ։: $ npm publish ֬ೝ:

    $ npm info hubot-hello-ninja ಈ࡞֬ೝ: $ npm install /your/module/path