From 02d675bd5fe34f43e46d998ac3ab639e00d4e7d5 Mon Sep 17 00:00:00 2001 From: kev Date: Wed, 11 Jan 2017 02:12:23 +0800 Subject: [PATCH] update hubot --- hubot/Dockerfile | 4 +- hubot/README.md | 8 ++- hubot/data/example.coffee | 106 ++++++++++++++++++++++++++++++++++++++ hubot/docker-compose.yml | 2 + 4 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 hubot/data/example.coffee diff --git a/hubot/Dockerfile b/hubot/Dockerfile index b9aab92..014c7a7 100644 --- a/hubot/Dockerfile +++ b/hubot/Dockerfile @@ -5,7 +5,7 @@ FROM node:slim MAINTAINER kev -ENV HUBOT_NAME=hubot +ENV HUBOT_NAME=Hubot ENV HUBOT_ADAPTER=slack ENV HUBOT_DESCRIPTION=$HUBOT_NAME-$HUBOT_ADAPTER ENV HUBOT_SLACK_TOKEN= @@ -28,6 +28,6 @@ RUN set -xe \ && npm install hubot-$HUBOT_ADAPTER --save \ && sed -i -r 's/^\s+#//' scripts/example.coffee -VOLUME /home/hobot +VOLUME /home/hobot/scripts CMD ["./bin/hubot", "--adapter", "slack"] diff --git a/hubot/README.md b/hubot/README.md index 243d47f..218d817 100644 --- a/hubot/README.md +++ b/hubot/README.md @@ -3,15 +3,18 @@ hubot ![](https://badge.imagelayers.io/vimagick/hubot:latest.svg) -[hubot][1] is a customizable, life embetterment robot commissioned by github. +[Hubot][1] is a customizable, life embetterment robot commissioned by github. +Hubot's power comes through [scripts][3]. ## docker-compse.yml ```yaml hubot: image: vimagick/hubot + volumes: + - ./data:/home/hubot/scripts environment: - - HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx + - HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx restart: always ``` @@ -19,3 +22,4 @@ hubot: [1]: https://hubot.github.com/ [2]: https://my.slack.com/services/new/hubot +[3]: https://github.com/github/hubot/blob/master/docs/scripting.md diff --git a/hubot/data/example.coffee b/hubot/data/example.coffee new file mode 100644 index 0000000..d877cc1 --- /dev/null +++ b/hubot/data/example.coffee @@ -0,0 +1,106 @@ +# Description: +# Example scripts for you to examine and try out. +# +# Notes: +# They are commented out by default, because most of them are pretty silly and +# wouldn't be useful and amusing enough for day to day huboting. +# Uncomment the ones you want to try and experiment with. +# +# These are from the scripting documentation: https://github.com/github/hubot/blob/master/docs/scripting.md + +module.exports = (robot) -> + + robot.hear /badger/i, (res) -> + res.send "Badgers? BADGERS? WE DON'T NEED NO STINKIN BADGERS" + + robot.respond /open the (.*) doors/i, (res) -> + doorType = res.match[1] + if doorType is "pod bay" + res.reply "I'm afraid I can't let you do that." + else + res.reply "Opening #{doorType} doors" + + robot.hear /I like pie/i, (res) -> + res.emote "makes a freshly baked pie" + + lulz = ['lol', 'rofl', 'lmao'] + + robot.respond /lulz/i, (res) -> + res.send res.random lulz + + robot.topic (res) -> + res.send "#{res.message.text}? That's a Paddlin'" + + + enterReplies = ['Hi', 'Target Acquired', 'Firing', 'Hello friend.', 'Gotcha', 'I see you'] + leaveReplies = ['Are you still there?', 'Target lost', 'Searching'] + + robot.enter (res) -> + res.send res.random enterReplies + robot.leave (res) -> + res.send res.random leaveReplies + + answer = process.env.HUBOT_ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING + + robot.respond /what is the answer to the ultimate question of life/, (res) -> + unless answer? + res.send "Missing HUBOT_ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING in environment: please set and try again" + return + res.send "#{answer}, but what is the question?" + + robot.respond /you are a little slow/, (res) -> + setTimeout () -> + res.send "Who you calling 'slow'?" + , 60 * 1000 + + annoyIntervalId = null + + robot.respond /annoy me/, (res) -> + if annoyIntervalId + res.send "AAAAAAAAAAAEEEEEEEEEEEEEEEEEEEEEEEEIIIIIIIIHHHHHHHHHH" + return + + res.send "Hey, want to hear the most annoying sound in the world?" + annoyIntervalId = setInterval () -> + res.send "AAAAAAAAAAAEEEEEEEEEEEEEEEEEEEEEEEEIIIIIIIIHHHHHHHHHH" + , 1000 + + robot.respond /unannoy me/, (res) -> + if annoyIntervalId + res.send "GUYS, GUYS, GUYS!" + clearInterval(annoyIntervalId) + annoyIntervalId = null + else + res.send "Not annoying you right now, am I?" + + + robot.router.post '/hubot/chatsecrets/:room', (req, res) -> + room = req.params.room + data = JSON.parse req.body.payload + secret = data.secret + + robot.messageRoom room, "I have a secret: #{secret}" + + res.send 'OK' + + robot.error (err, res) -> + robot.logger.error "DOES NOT COMPUTE" + + if res? + res.reply "DOES NOT COMPUTE" + + robot.respond /have a soda/i, (res) -> + # Get number of sodas had (coerced to a number). + sodasHad = robot.brain.get('totalSodas') * 1 or 0 + + if sodasHad > 4 + res.reply "I'm too fizzy.." + + else + res.reply 'Sure!' + + robot.brain.set 'totalSodas', sodasHad+1 + + robot.respond /sleep it off/i, (res) -> + robot.brain.set 'totalSodas', 0 + res.reply 'zzzzz' diff --git a/hubot/docker-compose.yml b/hubot/docker-compose.yml index 9c26964..6776a11 100644 --- a/hubot/docker-compose.yml +++ b/hubot/docker-compose.yml @@ -1,5 +1,7 @@ hubot: image: vimagick/hubot + volumes: + - ./data:/home/hubot/scripts environment: - HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx restart: always