Skip to content

Commit

Permalink
Booyahkasha
Browse files Browse the repository at this point in the history
  • Loading branch information
Ændrew Rininsland committed Nov 23, 2013
0 parents commit 573f417
Show file tree
Hide file tree
Showing 22 changed files with 896 additions and 0 deletions.
2 changes: 2 additions & 0 deletions screamcat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.DS_Store*
1 change: 1 addition & 0 deletions screamcat/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bin/hubot -a campfire -n Hubot
157 changes: 157 additions & 0 deletions screamcat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Hubot

This is a version of GitHub's Campfire bot, hubot. He's pretty cool.

This version is designed to be deployed on [Heroku][heroku]. This README was generated for you by hubot to help get you started. Definitely update and improve to talk about your own instance, how to use and deploy, what functionality he has, etc!

[heroku]: http://www.heroku.com

### Testing Hubot Locally

You can test your hubot by running the following.

% bin/hubot

You'll see some start up output about where your scripts come from and a
prompt.

[Sun, 04 Dec 2011 18:41:11 GMT] INFO Loading adapter shell
[Sun, 04 Dec 2011 18:41:11 GMT] INFO Loading scripts from /home/tomb/Development/hubot/scripts
[Sun, 04 Dec 2011 18:41:11 GMT] INFO Loading scripts from /home/tomb/Development/hubot/src/scripts
Hubot>

Then you can interact with hubot by typing `hubot help`.

Hubot> hubot help

Hubot> animate me <query> - The same thing as `image me`, except adds a few
convert me <expression> to <units> - Convert expression to given units.
help - Displays all of the help commands that Hubot knows about.
...


### Scripting

Take a look at the scripts in the `./scripts` folder for examples.
Delete any scripts you think are useless or boring. Add whatever functionality you
want hubot to have. Read up on what you can do with hubot in the [Scripting Guide](https://github.com/github/hubot/blob/master/docs/scripting.md).

### Redis Persistence

If you are going to use the `redis-brain.coffee` script from `hubot-scripts`
(strongly suggested), you will need to add the Redis to Go addon on Heroku which requires a verified
account or you can create an account at [Redis to Go][redistogo] and manually
set the `REDISTOGO_URL` variable.

% heroku config:add REDISTOGO_URL="..."

If you don't require any persistence feel free to remove the
`redis-brain.coffee` from `hubot-scripts.json` and you don't need to worry
about redis at all.

[redistogo]: https://redistogo.com/

## Adapters

Adapters are the interface to the service you want your hubot to run on. This
can be something like Campfire or IRC. There are a number of third party
adapters that the community have contributed. Check
[Hubot Adapters][hubot-adapters] for the available ones.

If you would like to run a non-Campfire or shell adapter you will need to add
the adapter package as a dependency to the `package.json` file in the
`dependencies` section.

Once you've added the dependency and run `npm install` to install it you can
then run hubot with the adapter.

% bin/hubot -a <adapter>

Where `<adapter>` is the name of your adapter without the `hubot-` prefix.

[hubot-adapters]: https://github.com/github/hubot/blob/master/docs/adapters.md

## hubot-scripts

There will inevitably be functionality that everyone will want. Instead
of adding it to hubot itself, you can submit pull requests to
[hubot-scripts][hubot-scripts].

To enable scripts from the hubot-scripts package, add the script name with
extension as a double quoted string to the `hubot-scripts.json` file in this
repo.

[hubot-scripts]: https://github.com/github/hubot-scripts

## external-scripts

Tired of waiting for your script to be merged into `hubot-scripts`? Want to
maintain the repository and package yourself? Then this added functionality
maybe for you!

Hubot is now able to load scripts from third-party `npm` packages! To enable
this functionality you can follow the following steps.

1. Add the packages as dependencies into your `package.json`
2. `npm install` to make sure those packages are installed

To enable third-party scripts that you've added you will need to add the package
name as a double quoted string to the `external-scripts.json` file in this repo.

## Deployment

% heroku create --stack cedar
% git push heroku master
% heroku ps:scale app=1

If your Heroku account has been verified you can run the following to enable
and add the Redis to Go addon to your app.

% heroku addons:add redistogo:nano

If you run into any problems, checkout Heroku's [docs][heroku-node-docs].

You'll need to edit the `Procfile` to set the name of your hubot.

More detailed documentation can be found on the
[deploying hubot onto Heroku][deploy-heroku] wiki page.

### Deploying to UNIX or Windows

If you would like to deploy to either a UNIX operating system or Windows.
Please check out the [deploying hubot onto UNIX][deploy-unix] and
[deploying hubot onto Windows][deploy-windows] wiki pages.

[heroku-node-docs]: http://devcenter.heroku.com/articles/node-js
[deploy-heroku]: https://github.com/github/hubot/blob/master/docs/deploying/heroku.md
[deploy-unix]: https://github.com/github/hubot/blob/master/docs/deploying/unix.md
[deploy-windows]: https://github.com/github/hubot/blob/master/docs/deploying/unix.md

## Campfire Variables

If you are using the Campfire adapter you will need to set some environment
variables. Refer to the documentation for other adapters and the configuraiton
of those, links to the adapters can be found on [Hubot Adapters][hubot-adapters].

Create a separate Campfire user for your bot and get their token from the web
UI.

% heroku config:add HUBOT_CAMPFIRE_TOKEN="..."

Get the numeric IDs of the rooms you want the bot to join, comma delimited. If
you want the bot to connect to `https://mysubdomain.campfirenow.com/room/42`
and `https://mysubdomain.campfirenow.com/room/1024` then you'd add it like this:

% heroku config:add HUBOT_CAMPFIRE_ROOMS="42,1024"

Add the subdomain hubot should connect to. If you web URL looks like
`http://mysubdomain.campfirenow.com` then you'd add it like this:

% heroku config:add HUBOT_CAMPFIRE_ACCOUNT="mysubdomain"

[hubot-adapters]: https://github.com/github/hubot/blob/master/docs/adapters.md

## Restart the bot

You may want to get comfortable with `heroku logs` and `heroku restart`
if you're having issues.
7 changes: 7 additions & 0 deletions screamcat/bin/hubot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

npm install
export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"

exec node_modules/.bin/hubot "$@"

3 changes: 3 additions & 0 deletions screamcat/bin/hubot.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

npm install && node_modules\.bin\hubot.cmd %*
1 change: 1 addition & 0 deletions screamcat/external-scripts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions screamcat/hubot-scripts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["redis-brain.coffee", "shipit.coffee"]
35 changes: 35 additions & 0 deletions screamcat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "hosted-hubot",
"version": "2.6.3",

"author": "GitHub Inc.",

"keywords": [
"github",
"hubot",
"campfire",
"bot"
],

"description": "A simple helpful robot for your Company",

"licenses": [{
"type": "MIT",
"url": "https://github.com/github/hubot/raw/master/LICENSE"
}],

"repository" : {
"type": "git",
"url": "https://github.com/github/hubot.git"
},

"dependencies": {
"hubot": ">= 2.6.0 < 3.0.0",
"hubot-scripts": ">= 2.5.0 < 3.0.0"
},

"engines": {
"node": ">= 0.8.x",
"npm": ">= 1.1.x"
}
}
114 changes: 114 additions & 0 deletions screamcat/scripts/auth.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Description:
# Auth allows you to assign roles to users which can be used by other scripts
# to restrict access to Hubot commands
#
# Dependencies:
# None
#
# Configuration:
# HUBOT_AUTH_ADMIN - A comma separate list of user IDs
#
# Commands:
# hubot <user> has <role> role - Assigns a role to a user
# hubot <user> doesn't have <role> role - Removes a role from a user
# hubot what role does <user> have - Find out what roles are assigned to a specific user
# hubot who has admin role - Find out who's an admin and can assign roles
#
# Notes:
# * Call the method: robot.auth.hasRole(msg.envelope.user,'<role>')
# * returns bool true or false
#
# * the 'admin' role can only be assigned through the environment variable
# * roles are all transformed to lower case
#
# * The script assumes that user IDs will be unique on the service end as to
# correctly identify a user. Names were insecure as a user could impersonate
# a user
#
# Author:
# alexwilliamsca, tombell

module.exports = (robot) ->

unless process.env.HUBOT_AUTH_ADMIN?
robot.logger.warning 'The HUBOT_AUTH_ADMIN environment variable not set'

if process.env.HUBOT_AUTH_ADMIN?
admins = process.env.HUBOT_AUTH_ADMIN.split ','
else
admins = []

class Auth
hasRole: (user, roles) ->
user = robot.brain.userForId(user.id)
if user? and user.roles?
roles = [roles] if typeof roles is 'string'
for role in roles
return true if role in user.roles
return false

usersWithRole: (role) ->
users = []
for own key, user of robot.brain.data.users
if robot.auth.hasRole(msg.envelope.user, role)
users.push(user)
users

robot.auth = new Auth

robot.respond /@?(.+) (has) (["'\w: -_]+) (role)/i, (msg) ->
name = msg.match[1].trim()
newRole = msg.match[3].trim().toLowerCase()

unless name.toLowerCase() in ['', 'who', 'what', 'where', 'when', 'why']
user = robot.brain.userForName(name)
return msg.reply "#{name} does not exist" unless user?
user.roles or= []

if newRole in user.roles
msg.reply "#{name} already has the '#{newRole}' role."
else
if newRole is 'admin'
msg.reply "Sorry, the 'admin' role can only be defined in the HUBOT_AUTH_ADMIN env variable."
else
myRoles = msg.message.user.roles or []
if msg.message.user.id.toString() in admins
user.roles.push(newRole)
msg.reply "Ok, #{name} has the '#{newRole}' role."

robot.respond /@?(.+) (doesn't have|does not have) (["'\w: -_]+) (role)/i, (msg) ->
name = msg.match[1].trim()
newRole = msg.match[3].trim().toLowerCase()

unless name.toLowerCase() in ['', 'who', 'what', 'where', 'when', 'why']
user = robot.brain.userForName(name)
return msg.reply "#{name} does not exist" unless user?
user.roles or= []

if newRole is 'admin'
msg.reply "Sorry, the 'admin' role can only be removed from the HUBOT_AUTH_ADMIN env variable."
else
myRoles = msg.message.user.roles or []
if msg.message.user.id.toString() in admins
user.roles = (role for role in user.roles when role isnt newRole)
msg.reply "Ok, #{name} doesn't have the '#{newRole}' role."

robot.respond /(what role does|what roles does) @?(.+) (have)\?*$/i, (msg) ->
name = msg.match[2].trim()
user = robot.brain.userForName(name)
return msg.reply "#{name} does not exist" unless user?
user.roles or= []

if user.id.toString() in admins
isAdmin = ' and is also an admin'
else
isAdmin = ''
msg.reply "#{name} has the following roles: #{user.roles.join(', ')}#{isAdmin}."

robot.respond /who has admin role\?*$/i, (msg) ->
adminNames = []
for admin in admins
user = robot.brain.userForId(admin)
adminNames.push user.name if user?

msg.reply "The following people have the 'admin' role: #{adminNames.join(', ')}"
19 changes: 19 additions & 0 deletions screamcat/scripts/events.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Description:
# Event system related utilities
#
# Commands:
# hubot fake event <event> - Triggers the <event> event for debugging reasons
#
# Events:
# debug - {user: <user object to send message to>}

util = require 'util'

module.exports = (robot) ->

robot.respond /FAKE EVENT (.*)/i, (msg) ->
msg.send "fake event '#{msg.match[1]}' triggered"
robot.emit msg.match[1], {user: msg.message.user}

robot.on 'debug', (event) ->
robot.send event.user, util.inspect event
44 changes: 44 additions & 0 deletions screamcat/scripts/google-images.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Description:
# A way to interact with the Google Images API.
#
# Commands:
# hubot image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
# hubot animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
# hubot mustache me <url> - Adds a mustache to the specified URL.
# hubot mustache me <query> - Searches Google Images for the specified query and mustaches it.

module.exports = (robot) ->
robot.respond /(image|img)( me)? (.*)/i, (msg) ->
imageMe msg, msg.match[3], (url) ->
msg.send url

robot.respond /animate( me)? (.*)/i, (msg) ->
imageMe msg, msg.match[2], true, (url) ->
msg.send url

robot.respond /(?:mo?u)?sta(?:s|c)he?(?: me)? (.*)/i, (msg) ->
type = Math.floor(Math.random() * 3)
mustachify = "http://mustachify.me/#{type}?src="
imagery = msg.match[1]

if imagery.match /^https?:\/\//i
msg.send "#{mustachify}#{imagery}"
else
imageMe msg, imagery, false, true, (url) ->
msg.send "#{mustachify}#{url}"

imageMe = (msg, query, animated, faces, cb) ->
cb = animated if typeof animated == 'function'
cb = faces if typeof faces == 'function'
q = v: '1.0', rsz: '8', q: query, safe: 'active'
q.imgtype = 'animated' if typeof animated is 'boolean' and animated is true
q.imgtype = 'face' if typeof faces is 'boolean' and faces is true
msg.http('http://ajax.googleapis.com/ajax/services/search/images')
.query(q)
.get() (err, res, body) ->
images = JSON.parse(body)
images = images.responseData?.results
if images?.length > 0
image = msg.random images
cb "#{image.unescapedUrl}#.png"

Loading

0 comments on commit 573f417

Please sign in to comment.