Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 40 lines (34 sloc) 0.914 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
# Description:
# None
#
# Dependencies:
# "cradle": "0.6.3"
#
# Configuration:
# HUBOT_COUCHDB_URL
#
# Commands:
# None
#
# Author:
# Vrtak-CZ

Url = require "url"
cradle = require "cradle"

# sets up hooks to persist all messages into couchdb.
module.exports = (robot) ->
info = Url.parse process.env.HUBOT_COUCHDB_URL || 'http://localhost:5984'
if info.auth
auth = info.auth.split(":")
client = new(cradle.Connection) info.hostname, info.port, auth:
username: auth[0]
password: auth[1]
else
client = new(cradle.Connection)(info.hostname, info.port)

db = client.database(if info.pathname != '/' then info.pathname.slice(1) else "hubot-storage")

robot.hear /.*$/i, (msg) ->
message = msg.message
message.date = new Date

# ignore topic and other messages
return if typeof message.user.id == 'undefined'

db.save message, (err, res) ->
if err then console.error(err)
Something went wrong with that request. Please try again.