-
Notifications
You must be signed in to change notification settings - Fork 6
/
npm.js
51 lines (40 loc) · 1.28 KB
/
npm.js
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
41
42
43
44
45
46
47
48
49
50
51
const npmMaintainers = require('npm-maintainers-au')
, NpmPublishStream = require('npm-publish-stream')
, NpmMaintainerFilterStream = require('./npm-maintainer-filter-stream')
var maintainerFilterStream = new NpmMaintainerFilterStream()
, streaming = false
function handleNpmData (data) {
var desc = (data.doc.description || '')
, msg
if (desc.length > 128)
desc = desc.substring(0, 127) + '…'
msg = '[npm] '
+ data.id + '@' + data.doc['dist-tags'].latest
+ ' <http://npm.im/' + data.id + '>: '
+ desc
+ ' (' + data.doc.versions[data.doc['dist-tags'].latest].maintainers
.map(function (m) { return '@' + m.name }).join(', ') + ')'
this.say('#polyhack', msg)
}
function updateMaintainers () {
npmMaintainers(function (err, data) {
if (err)
return console.log(err)
if (!data.length)
return
data = data.map(function (u) { return u.npmLogin })
maintainerFilterStream.setMaintainers(data)
})
}
function init (bot) {
if (!streaming) {
new NpmPublishStream()
.on('error', console.log)
.pipe(maintainerFilterStream)
.on('data', handleNpmData.bind(bot))
streaming = true
setInterval(updateMaintainers, 1000 * 60 * 60 * 6)
updateMaintainers()
}
}
module.exports.init = init