git ssb

0+

Dominic / ssb-irc



Tree: 79475b914bb4109c2c52e9c4fc8569b0e48e87df

Files: 79475b914bb4109c2c52e9c4fc8569b0e48e87df / 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 function next (err, state) {
13 if(--n) return
14 //XXX: properly persist state with a flumeview?
15
16 //make sure we have joined every channel
17 for(var k in state.channels) {
18 var channel = state.channels[k]
19 IRC.join(irc, channel)
20 }
21
22 //only notify about live posts.
23 //this may cut out if the connection to IRC drops
24 //though, since
25
26 function notify (note) {
27 irc.say(
28 note.type == 'channel'
29 ? IRC.toChannel(note.target)
30 : note.target
31 ,
32 ssb.render(note, ssb.link(note.id, config))
33 )
34 }
35
36 pull(
37 sbot.createLogStream({live: true}),
38 pull.drain(function (msg) {
39 if(msg.sync) return
40 var a = tests.reduce(function (found, test) {
41 return found.concat(exports.match(state, msg) || [])
42 }, [])
43
44 if(a.length)
45 a.forEach(notify)
46 })
47 )
48 })
49}
50
51
52

Built with git-ssb-web