Skip to content

Commit e2ff95a

Browse files
committedApr 23, 2015
Initial commit
0 parents  commit e2ff95a

10 files changed

+387
-0
lines changed
 

‎.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store*
3+
.hubot_history

‎Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: bin/hubot --adapter slack

‎README.md

+214
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# hubot
2+
3+
hubot is a chat bot built on the [Hubot][hubot] framework. It was
4+
initially generated by [generator-hubot][generator-hubot], and configured to be
5+
deployed on [Heroku][heroku] to get you up and running as quick as possible.
6+
7+
This README is intended to help get you started. Definitely update and improve
8+
to talk about your own instance, how to use and deploy, what functionality he
9+
has, etc!
10+
11+
[heroku]: http://www.heroku.com
12+
[hubot]: http://hubot.github.com
13+
[generator-hubot]: https://github.com/github/generator-hubot
14+
15+
### Running hubot Locally
16+
17+
You can test your hubot by running the following, however some plugins will not
18+
behave as expected unless the [environment variables](#configuration) they rely
19+
upon have been set.
20+
21+
You can start hubot locally by running:
22+
23+
% bin/hubot
24+
25+
You'll see some start up output and a prompt:
26+
27+
[Sat Feb 28 2015 12:38:27 GMT+0000 (GMT)] INFO Using default redis on localhost:6379
28+
hubot>
29+
30+
Then you can interact with hubot by typing `hubot help`.
31+
32+
hubot> hubot help
33+
hubot animate me <query> - The same thing as `image me`, except adds [snip]
34+
hubot help - Displays all of the help commands that hubot knows about.
35+
...
36+
37+
### Configuration
38+
39+
A few scripts (including some installed by default) require environment
40+
variables to be set as a simple form of configuration.
41+
42+
Each script should have a commented header which contains a "Configuration"
43+
section that explains which values it requires to be placed in which variable.
44+
When you have lots of scripts installed this process can be quite labour
45+
intensive. The following shell command can be used as a stop gap until an
46+
easier way to do this has been implemented.
47+
48+
grep -o 'hubot-[a-z0-9_-]\+' external-scripts.json | \
49+
xargs -n1 -i sh -c 'sed -n "/^# Configuration/,/^#$/ s/^/{} /p" \
50+
$(find node_modules/{}/ -name "*.coffee")' | \
51+
awk -F '#' '{ printf "%-25s %s\n", $1, $2 }'
52+
53+
How to set environment variables will be specific to your operating system.
54+
Rather than recreate the various methods and best practices in achieving this,
55+
it's suggested that you search for a dedicated guide focused on your OS.
56+
57+
### Scripting
58+
59+
An example script is included at `scripts/example.coffee`, so check it out to
60+
get started, along with the [Scripting Guide](scripting-docs).
61+
62+
For many common tasks, there's a good chance someone has already one to do just
63+
the thing.
64+
65+
[scripting-docs]: https://github.com/github/hubot/blob/master/docs/scripting.md
66+
67+
### external-scripts
68+
69+
There will inevitably be functionality that everyone will want. Instead of
70+
writing it yourself, you can use existing plugins.
71+
72+
Hubot is able to load plugins from third-party `npm` packages. This is the
73+
recommended way to add functionality to your hubot. You can get a list of
74+
available hubot plugins on [npmjs.com](npmjs) or by using `npm search`:
75+
76+
% npm search hubot-scripts panda
77+
NAME DESCRIPTION AUTHOR DATE VERSION KEYWORDS
78+
hubot-pandapanda a hubot script for panda responses =missu 2014-11-30 0.9.2 hubot hubot-scripts panda
79+
...
80+
81+
82+
To use a package, check the package's documentation, but in general it is:
83+
84+
1. Use `npm install --save` to add the package to `package.json` and install it
85+
2. Add the package name to `external-scripts.json` as a double quoted string
86+
87+
You can review `external-scripts.json` to see what is included by default.
88+
89+
##### Advanced Usage
90+
91+
It is also possible to define `external-scripts.json` as an object to
92+
explicitly specify which scripts from a package should be included. The example
93+
below, for example, will only activate two of the six available scripts inside
94+
the `hubot-fun` plugin, but all four of those in `hubot-auto-deploy`.
95+
96+
```json
97+
{
98+
"hubot-fun": [
99+
"crazy",
100+
"thanks"
101+
],
102+
"hubot-auto-deploy": "*"
103+
}
104+
```
105+
106+
**Be aware that not all plugins support this usage and will typically fallback
107+
to including all scripts.**
108+
109+
[npmjs]: https://www.npmjs.com
110+
111+
### hubot-scripts
112+
113+
Before hubot plugin packages were adopted, most plugins were held in the
114+
[hubot-scripts][hubot-scripts] package. Some of these plugins have yet to be
115+
migrated to their own packages. They can still be used but the setup is a bit
116+
different.
117+
118+
To enable scripts from the hubot-scripts package, add the script name with
119+
extension as a double quoted string to the `hubot-scripts.json` file in this
120+
repo.
121+
122+
[hubot-scripts]: https://github.com/github/hubot-scripts
123+
124+
## Persistence
125+
126+
If you are going to use the `hubot-redis-brain` package (strongly suggested),
127+
you will need to add the Redis to Go addon on Heroku which requires a verified
128+
account or you can create an account at [Redis to Go][redistogo] and manually
129+
set the `REDISTOGO_URL` variable.
130+
131+
% heroku config:add REDISTOGO_URL="..."
132+
133+
If you don't need any persistence feel free to remove the `hubot-redis-brain`
134+
from `external-scripts.json` and you don't need to worry about redis at all.
135+
136+
[redistogo]: https://redistogo.com/
137+
138+
## Adapters
139+
140+
Adapters are the interface to the service you want your hubot to run on, such
141+
as Campfire or IRC. There are a number of third party adapters that the
142+
community have contributed. Check [Hubot Adapters][hubot-adapters] for the
143+
available ones.
144+
145+
If you would like to run a non-Campfire or shell adapter you will need to add
146+
the adapter package as a dependency to the `package.json` file in the
147+
`dependencies` section.
148+
149+
Once you've added the dependency with `npm install --save` to install it you
150+
can then run hubot with the adapter.
151+
152+
% bin/hubot -a <adapter>
153+
154+
Where `<adapter>` is the name of your adapter without the `hubot-` prefix.
155+
156+
[hubot-adapters]: https://github.com/github/hubot/blob/master/docs/adapters.md
157+
158+
## Deployment
159+
160+
% heroku create --stack cedar
161+
% git push heroku master
162+
163+
If your Heroku account has been verified you can run the following to enable
164+
and add the Redis to Go addon to your app.
165+
166+
% heroku addons:add redistogo:nano
167+
168+
If you run into any problems, checkout Heroku's [docs][heroku-node-docs].
169+
170+
You'll need to edit the `Procfile` to set the name of your hubot.
171+
172+
More detailed documentation can be found on the [deploying hubot onto
173+
Heroku][deploy-heroku] wiki page.
174+
175+
### Deploying to UNIX or Windows
176+
177+
If you would like to deploy to either a UNIX operating system or Windows.
178+
Please check out the [deploying hubot onto UNIX][deploy-unix] and [deploying
179+
hubot onto Windows][deploy-windows] wiki pages.
180+
181+
[heroku-node-docs]: http://devcenter.heroku.com/articles/node-js
182+
[deploy-heroku]: https://github.com/github/hubot/blob/master/docs/deploying/heroku.md
183+
[deploy-unix]: https://github.com/github/hubot/blob/master/docs/deploying/unix.md
184+
[deploy-windows]: https://github.com/github/hubot/blob/master/docs/deploying/unix.md
185+
186+
## Campfire Variables
187+
188+
If you are using the Campfire adapter you will need to set some environment
189+
variables. If not, refer to your adapter documentation for how to configure it,
190+
links to the adapters can be found on [Hubot Adapters][hubot-adapters].
191+
192+
Create a separate Campfire user for your bot and get their token from the web
193+
UI.
194+
195+
% heroku config:add HUBOT_CAMPFIRE_TOKEN="..."
196+
197+
Get the numeric IDs of the rooms you want the bot to join, comma delimited. If
198+
you want the bot to connect to `https://mysubdomain.campfirenow.com/room/42`
199+
and `https://mysubdomain.campfirenow.com/room/1024` then you'd add it like
200+
this:
201+
202+
% heroku config:add HUBOT_CAMPFIRE_ROOMS="42,1024"
203+
204+
Add the subdomain hubot should connect to. If you web URL looks like
205+
`http://mysubdomain.campfirenow.com` then you'd add it like this:
206+
207+
% heroku config:add HUBOT_CAMPFIRE_ACCOUNT="mysubdomain"
208+
209+
[hubot-adapters]: https://github.com/github/hubot/blob/master/docs/adapters.md
210+
211+
## Restart the bot
212+
213+
You may want to get comfortable with `heroku logs` and `heroku restart` if
214+
you're having issues.

‎bin/hubot

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
npm install
6+
export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"
7+
8+
exec node_modules/.bin/hubot --name "hubot" "$@"

‎bin/hubot.cmd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
npm install && node_modules\.bin\hubot.cmd --name "hubot" %*

‎external-scripts.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
"hubot-diagnostics",
3+
"hubot-help",
4+
"hubot-heroku-keepalive",
5+
"hubot-google-images",
6+
"hubot-google-translate",
7+
"hubot-pugme",
8+
"hubot-maps",
9+
"hubot-redis-brain",
10+
"hubot-rules",
11+
"hubot-shipit",
12+
"hubot-youtube"
13+
]

‎hubot-scripts.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

‎package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "hubot",
3+
"version": "0.0.0",
4+
"private": true,
5+
"author": "Gustavo Barbosa <gustavocsb@gmail.com>",
6+
"description": "A simple helpful robot for your Company",
7+
"dependencies": {
8+
"hubot": "^2.12.0",
9+
"hubot-diagnostics": "0.0.1",
10+
"hubot-google-images": "^0.1.4",
11+
"hubot-google-translate": "^0.1.0",
12+
"hubot-help": "^0.1.1",
13+
"hubot-heroku-keepalive": "0.0.4",
14+
"hubot-maps": "0.0.2",
15+
"hubot-pugme": "^0.1.0",
16+
"hubot-redis-brain": "0.0.2",
17+
"hubot-rules": "^0.1.0",
18+
"hubot-scripts": "^2.5.16",
19+
"hubot-shipit": "^0.2.0",
20+
"hubot-slack": "^3.3.0",
21+
"hubot-youtube": "^0.1.2"
22+
},
23+
"engines": {
24+
"node": "0.10.x"
25+
}
26+
}

‎scripts/example.coffee

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Description:
2+
# Example scripts for you to examine and try out.
3+
#
4+
# Notes:
5+
# They are commented out by default, because most of them are pretty silly and
6+
# wouldn't be useful and amusing enough for day to day huboting.
7+
# Uncomment the ones you want to try and experiment with.
8+
#
9+
# These are from the scripting documentation: https://github.com/github/hubot/blob/master/docs/scripting.md
10+
11+
module.exports = (robot) ->
12+
13+
# robot.hear /badger/i, (res) ->
14+
# res.send "Badgers? BADGERS? WE DON'T NEED NO STINKIN BADGERS"
15+
#
16+
# robot.respond /open the (.*) doors/i, (res) ->
17+
# doorType = res.match[1]
18+
# if doorType is "pod bay"
19+
# res.reply "I'm afraid I can't let you do that."
20+
# else
21+
# res.reply "Opening #{doorType} doors"
22+
#
23+
# robot.hear /I like pie/i, (res) ->
24+
# res.emote "makes a freshly baked pie"
25+
#
26+
# lulz = ['lol', 'rofl', 'lmao']
27+
#
28+
# robot.respond /lulz/i, (res) ->
29+
# res.send res.random lulz
30+
#
31+
# robot.topic (res) ->
32+
# res.send "#{res.message.text}? That's a Paddlin'"
33+
#
34+
#
35+
# enterReplies = ['Hi', 'Target Acquired', 'Firing', 'Hello friend.', 'Gotcha', 'I see you']
36+
# leaveReplies = ['Are you still there?', 'Target lost', 'Searching']
37+
#
38+
# robot.enter (res) ->
39+
# res.send res.random enterReplies
40+
# robot.leave (res) ->
41+
# res.send res.random leaveReplies
42+
#
43+
# answer = process.env.HUBOT_ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING
44+
#
45+
# robot.respond /what is the answer to the ultimate question of life/, (res) ->
46+
# unless answer?
47+
# res.send "Missing HUBOT_ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING in environment: please set and try again"
48+
# return
49+
# res.send "#{answer}, but what is the question?"
50+
#
51+
# robot.respond /you are a little slow/, (res) ->
52+
# setTimeout () ->
53+
# res.send "Who you calling 'slow'?"
54+
# , 60 * 1000
55+
#
56+
# annoyIntervalId = null
57+
#
58+
# robot.respond /annoy me/, (res) ->
59+
# if annoyIntervalId
60+
# res.send "AAAAAAAAAAAEEEEEEEEEEEEEEEEEEEEEEEEIIIIIIIIHHHHHHHHHH"
61+
# return
62+
#
63+
# res.send "Hey, want to hear the most annoying sound in the world?"
64+
# annoyIntervalId = setInterval () ->
65+
# res.send "AAAAAAAAAAAEEEEEEEEEEEEEEEEEEEEEEEEIIIIIIIIHHHHHHHHHH"
66+
# , 1000
67+
#
68+
# robot.respond /unannoy me/, (res) ->
69+
# if annoyIntervalId
70+
# res.send "GUYS, GUYS, GUYS!"
71+
# clearInterval(annoyIntervalId)
72+
# annoyIntervalId = null
73+
# else
74+
# res.send "Not annoying you right now, am I?"
75+
#
76+
#
77+
# robot.router.post '/hubot/chatsecrets/:room', (req, res) ->
78+
# room = req.params.room
79+
# data = JSON.parse req.body.payload
80+
# secret = data.secret
81+
#
82+
# robot.messageRoom room, "I have a secret: #{secret}"
83+
#
84+
# res.send 'OK'
85+
#
86+
# robot.error (err, res) ->
87+
# robot.logger.error "DOES NOT COMPUTE"
88+
#
89+
# if res?
90+
# res.reply "DOES NOT COMPUTE"
91+
#
92+
# robot.respond /have a soda/i, (res) ->
93+
# # Get number of sodas had (coerced to a number).
94+
# sodasHad = robot.brain.get('totalSodas') * 1 or 0
95+
#
96+
# if sodasHad > 4
97+
# res.reply "I'm too fizzy.."
98+
#
99+
# else
100+
# res.reply 'Sure!'
101+
#
102+
# robot.brain.set 'totalSodas', sodasHad+1
103+
#
104+
# robot.respond /sleep it off/i, (res) ->
105+
# robot.brain.set 'totalSodas', 0
106+
# res.reply 'zzzzz'

0 commit comments

Comments
 (0)
Please sign in to comment.