Commit 79475b914bb4109c2c52e9c4fc8569b0e48e87df
tie it all together
Dominic Tarr committed on 7/20/2017, 10:14:12 AMParent: 821fa22a06ca562babbd363f8d195f4e504c0e92
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -1,9 +1,51 @@ | ||
1 | - | |
1 … | +var ssb = require('./ssb') | |
2 … | +var IRC = require('./irc') | |
2 | 3 … | //this should just wrap the stuff in util.js |
3 | 4 … | |
4 | 5 … | 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) | |
5 | 11 … | |
12 … | + function next (err, state) { | |
13 … | + if(--n) return | |
14 … | + //XXX: properly persist state with a flumeview? | |
6 | 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 … | + } | |
7 | 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 … | + }) | |
8 | 49 … | } |
9 | 50 … | |
51 … | + |
Built with git-ssb-web