git ssb

0+

Dominic / ssb-irc



Tree: 5ac8bb7a7bad5b9d3faa6072d1c0ac79eed73642

Files: 5ac8bb7a7bad5b9d3faa6072d1c0ac79eed73642 / index.js

1149 bytesRaw
1var ssb = require('./ssb')
2var IRC = require('./irc')
3//this should just wrap the stuff in util.js
4
5exports.init = function (sbot, config) {
6 //
7 var n = 2
8 //load current state
9 var state = ssb.init(sbot, process.argv[2] || sbot.id, next)
10 var irc = IRC(config, next)
11
12
13 function notify (note) {
14 irc.say(
15 note.type == 'channel'
16 ? IRC.toChannel(note.target)
17 : note.target
18 ,
19 ssb.render(note, ssb.link(note.id, config))
20 )
21 }
22
23 function next (err, state) {
24 if(--n) return
25 //XXX: properly persist state with a flumeview?
26
27 //make sure we have joined every channel
28 for(var k in state.channels) {
29 var channel = state.channels[k]
30 IRC.join(irc, channel)
31 }
32
33 //only notify about live posts.
34 //this may cut out if the connection to IRC drops
35 //though, since
36
37 pull(
38 sbot.createLogStream({live: true}),
39 pull.drain(function (msg) {
40 if(msg.sync) return
41 var a = tests.reduce(function (found, test) {
42 return found.concat(exports.match(state, msg) || [])
43 }, [])
44
45 if(a.length)
46 a.forEach(notify)
47 })
48 )
49 }
50}
51
52
53

Built with git-ssb-web