git ssb

0+

Dominic / ssb-irc



Commit 79475b914bb4109c2c52e9c4fc8569b0e48e87df

tie it all together

Dominic Tarr committed on 7/20/2017, 10:14:12 AM
Parent: 821fa22a06ca562babbd363f8d195f4e504c0e92

Files changed

index.jschanged
index.jsView
@@ -1,9 +1,51 @@
1-
1 +var ssb = require('./ssb')
2 +var IRC = require('./irc')
23 //this should just wrap the stuff in util.js
34
45 exports.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)
511
12 + function next (err, state) {
13 + if(--n) return
14 + //XXX: properly persist state with a flumeview?
615
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 + }
721
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 + })
849 }
950
51 +

Built with git-ssb-web